Skip to content Skip to sidebar Skip to footer

Python - Trml2pdf Generating A Blank Pdf

I use trml2pdf library in Python, but even when I use the examples, I get a blank PDF file. I run it as follows: trml2pdf.py ex5.rml > out.pdf When I open the file in Acrobat i

Solution 1:

I've been using z3c.rml in many web apps for last 6-8 months and never faced any major issue. rml2pdf command from this package was able to generate the PDF for the rml you have shared.

You should give it a try.

#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

Solution 2:

I am using trml2pdf and it is successfully working , here i am posting my code so that you can take a look

from django.template.loader import get_template
from django.template.context import Context
import trml2pdf
definvoicepdf(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 Code

invoice.rml

<!-- This is very Invoice RML template for illustrative purposes.  --><!-- A basic RML template has three sections.  The 'template'     --><!-- section is where you define fixed position elements, along   --><!-- with 'frames' containing  flowing text.  The 'stylesheet'    --><!-- section contains re-useable text style definitions.  The     --><!-- 'story' section contains the text and graphics which fill    --><!-- up the frames defined in the template section.               --><!-- For more information, please read the documentation at       --><!-- http://www.reportlab.com/software/documentation/             --><!DOCTYPE documentSYSTEM"rml.dtd"><documentfilename="invoice.pdf"><!-- left margin --><templatetitle="Invoices"author="Atul jain"allowSplitting="20"><pageTemplateid="first"><frameid="first"x1="34.0"y1="28.0"width="530"height="786"/><pageGraphics><lines>0.3cm 27.0cm 20cm 27.0cm</lines></pageGraphics></pageTemplate></template><story><para><fontcolor="white"></font></para><para><b>Name:- {{name}} </b></para><para><b>Date:- {{date}} </b></para><blockTablecolWidths="385.0,60.0,85.0"><tr><td><para><fontcolor="white"></font></para></td><td><para>Net Total:</para></td><td><para>{{subtotal}} INR;</para></td></tr><tr><td><para><fontcolor="white"></font></para></td><td><para><b>Total:</b></para></td><td><para><b>{{total}} INR;</b></para></td></tr></blockTable></story></document>

Post a Comment for "Python - Trml2pdf Generating A Blank Pdf"