【问题标题】:xhtml2pdf is creating URL with WinAnsiEncoding in Djangoxhtml2pdf 在 Django 中使用 WinAnsiEncoding 创建 URL
【发布时间】:2018-10-31 03:46:31
【问题描述】:

我正在单击一个按钮并调用 django 类并在 ajax 成功(函数(数据))中获得响应

ajax

$('.contract-download').click(function(){
        $.ajax({
            url:'{% url 'app:contract' %}',
            method:'GET',
            data:{
            'data-invoice':$(this).attr('data-invoice'),
            'data-order':$(this).attr('data-order')

            },
            success:function(data){
            console.log(data)
            window.open("data:application/pdf,charset=utf-8" + escape(data))

            }
        })
    })

它正在创建它的 url 的新窗口只是在 WinAnsiEncoding 中

%PDF-1.4
%���� ReportLab Generated PDF document http://www.reportlab.com
1 0 obj
<<
/F1 2 0 R /F2 4 0 R /F3 8 0 R /F4 10 0 R
>>
endobj
2 0 obj
<<
/BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font
>>
endobj
3 0 obj
<<
/BitsPerComponent 1 /ColorSpace /DeviceGray /Filter [ /ASCII85Decode ] /Height 23 /Length 223 /Subtype /Image 
  /Type /XObject /Width 24
>>
stream

            003B00 002700 002480 0E4940 114920 14B220 3CB650
            75FE88 17FF8C 175F14 1C07E2 3803C4 703182 F8EDFC
            B2BBC2 BB6F84 31BFC2 18EA3C 0E3E00 07FC00 03F800
            1E1800 1FF800>
            endstream
endobj
4 0 obj
<<
/BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding /Name /F2 /Subtype /Type1 /Type /Font
>>
endobj
5 0 obj
<<
/Contents 24 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 23 0 R /Resources <<
/Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /XObject <<
/FormXob.c7485dcc8d256a6f197ed7802687f252 3 0 R
>>
>> /Rotate 0 /Trans <<

>> 
  /…

我想在这里给出简单的人类可读的url名称,怎么做?

【问题讨论】:

  • “简单的人类可读的网址名称”是什么意思?您正在打开一个带有 data: URL 的窗口,您无法更改它。
  • @AKX 抱歉,我无法正确解释。实际上,上述所有数据都在 Url 中呈现,仅适用于 Firefox,但不适用于 Chrome

标签: django


【解决方案1】:

使用link_callback函数

在静态目录中添加字体文件(例如 .ttf)

并添加 encoding='utf-8' 创建 pdf

status = pisa.CreatePDF(
    html, dest=response,
    link_callback=link_callback,
    encoding="UTF-8"
)

我以前是指 using-xhtml2pdf-in-django

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 1970-01-01
    • 2019-06-29
    • 2017-09-20
    • 2017-10-20
    • 1970-01-01
    相关资源
    最近更新 更多