سؤال

I am trying to generate reports (can be in any format as long as printable pdf,doc..etc) using templates from Python.

Normally, I would use reportlab to generate PDF report. But this time, I need the user to create their own template(More like a placeholder).

So, when user generate report, the data stored in the database will take up the place of placeholder that user created earlier and form a report.

For example, if user set a tag or something <name> in the template, the actual name from the database will replace that tag in the exact position.(this is just some silly example to demostrate my concept - i don't know if that's possible or not)

I do not need any other complicated functionalities.

Initially, I was thinking of using xhtml2pdf to convert create template in html and convert it back to pdf. But I can't seems to find a way to substitute the values from database into the html.

I have also look into Mako but I am lost in it's documentations.

Are there any other way to achieve functionality that I mentioned above?

FYI: I only needs the solution for Windows platform. I am using windows 8.1 64bits with python 2.7.3

هل كانت مفيدة؟

المحلول

The approach I've used in the past is to create the PDF templates as fillable PDF Form, generate an XFDF (XML Forms Data Format), and use a tool that can merge XFDF into the PDF Template Form, and flatten the filled data into PDF (flattening a PDF form replaces the form fields with the filled data).

You can use Acrobat to create the template form.

XFDF is just XML, so it's fairly easy to generate with any tools that can generate XML.

One of the tools I've used for merging and flattening the form is pdftk.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top