• wkhtmltopdf 转换后 表格不显示 python解决方案


    wkhtmltopdf 转换后 表格不显示

       def post(self, request, *args, **kwargs):
    		
            # 获取的直接是富文本中的html字符串
            content = request.DATA.get('content')
    
            file_name = request.DATA.get('file_name')
    
            file_type = request.DATA.get('file_type')
    
            direction = request.DATA.get('direction')
    
            options = constants.PDFKIT_OPTIONS
    		
            # 横向 或 纵向
            if direction:
                options['orientation'] = 'Landscape'
    		
            # 判断如果有table 加上样式,就可以显示表格了
            if '<table' in content:
                content = '<style>table {max- 100%;} td {border: 1px solid #ccc;}</style>' + content
    
            file_path = '{}_{}.pdf'.format(file_name, uuid.uuid4())
            ExportPdfHelper(content, file_path, options).export_pdf()
    	'''
    	这里实际调用pdfkit.from_string方法,
            pdfkit.from_string(self.content, self.file_path, configuration=self.config, options=self.options)
            
            参数:
    	content:h5字符串 
    	file_path:生成的pdf存放位置,
            configuration: pdfkit.configuration(wkhtmltopdf=settings.WKHTMLTOPDF_PATH) 工具位置
            options:
            PDFKIT_OPTIONS = {
                'page-size': 'Letter',
                'margin-top': '0.75in',
                'margin-right': '0.75in',
                'margin-bottom': '0.75in',
                'margin-left': '0.75in',
                'encoding': "UTF-8",
                'no-outline': None,
                'quiet': '',
                'enable-forms': '',
            }
            options 明细 https://www.jianshu.com/p/4d65857ffe5e 
    		'''
    
    
            ret, info = upload_file_to_qiniu(file_path, file_path)
    
            qiniu_url = settings.QINIU_CDN_DOMAIN + "/" + ret['key']
    
            return Response({'status': 1, 'file_url': qiniu_url})
    
    
    # 如果不想表格被分页打断, border防止表格线变双行
    '<style>' 
             'table {max- 100%;  ' border-collapse: collapse;} ' 
             ' td {border: 1px solid #ccc;}' 
              'table {page-break-inside: avoid !important;}' 
             '</style>'
    
    
  • 相关阅读:
    scp上传服务器文件
    svn一次添加所有未添加的文件
    vue 去掉#和拼接参数
    vuex状态管理
    获取页面iframe里的元素
    angular 中ng-bind-html 、$scope服务
    心态崩了
    day 8
    day 7
    day6 angularjs学习
  • 原文地址:https://www.cnblogs.com/robert-zhou/p/13896652.html
Copyright © 2020-2023  润新知