Python trml2pdf生成空白PDF

2024-09-30 01:27:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Python中使用trml2pdf库,但是即使使用示例,也会得到一个空白的PDF文件。 我运行如下: trml2型py.pdf文件示例5.rml>;输出.pdf在

Acrobat在文件中打开时为空。 但是当我分析文本编辑器中的内容时,我看到了以下内容。在

生成的PDF:

%PDF-1.4

%“Œ‹ž ReportLab Generated PDF document http://www.reportlab.com

% 'BasicFonts': class PDFDictionary 

1 0 obj

% The standard fonts dictionary

<< /F1 2 0 R

 /F2 3 0 R

 /F3 4 0 R >>

PDF示例:

^{pr2}$

我做错什么了?为什么输出中有空行?在

谢谢!在

以下是基本的RML,也返回空白PDF:

<!DOCTYPE document SYSTEM "rml_1_0.dtd">
<document filename="example_1.pdf">
<stylesheet>
</stylesheet>
<pageDrawing>
     <drawCentredString x="4.1in" y="5.8in">
       Hello World.
 </drawCentredString>
</pageDrawing>
</document>

Tags: 文件inpygt示例pdfdocument空白
2条回答

在过去的6-8个月里,我在许多web应用程序中使用了^{},从未遇到过任何重大问题。^来自这个包的{}命令能够为您共享的rml生成PDF。在

你应该试试看。在

#Install z3c.rml
[sudo] pip install z3c.rml

# create a new rml document
vim example.rml

# rum rml2pdf command to convert this rml to pdf
rml2pdf example.rml

# You should have desired PDF file now

我正在使用trml2pdf,它是成功的工作,这里我张贴我的代码,以便你可以看一看

from django.template.loader import get_template
from django.template.context import Context
import trml2pdf
def invoicepdf(request):
    template = get_template('invoice.rml')
    context = Context({
        'name': "XXXXXXXXXX", 
        'date':_date, 
        'subtotal':1909201,
        'total': 345789

     })
    xmlstring = template.render(context)
    pdfstr = trml2pdf.parseString(xmlstring)
    response = HttpResponse(mimetype='application/pdf')
    response.write(pdfstr)
    response['Content-Disposition'] = 'attachment; filename=invoice.pdf'
    return response

RML代码

发票.rml在

^{pr2}$

相关问题 更多 >

    热门问题