how to insert a string to pdf using pypdf?

Egy Mohammad Erdin picture Egy Mohammad Erdin · May 25, 2011 · Viewed 9.2k times · Source

sorry,.. i'am a noob in python..

I need to create a pdf file, without using an existing pdf files.. (pure create a new one)
i have googling, and lot of them is merge 2 pdf or create a new file copies from a particular page in another file... what i want to achieve is make a report page (in chart), but for first step or the simple one "how to insert a string into my pdf file ? (hello world mybe)"..

this is my code to make a new pdf file with a single blankpage

from pyPdf import PdfFileReader, PdfFileWriter
op = PdfFileWriter()  

# here to add blank page
op.addBlankPage(200,200)  

#how to add string here, and insert it to my blank page ?

ops = file("document-output.pdf", "wb")  
op.write(ops)  
ops.close() 

Answer

Andreas Jung picture Andreas Jung · May 25, 2011

You want "pisa" or "reportlab" for generating arbitrary PDF documents, not "pypdf".

http://www.xhtml2pdf.com/doc/pisa-en.html

http://www.reportlab.org