Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to insert a string to pdf using pypdf?

Tags:

python

pypdf

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() 
like image 354
Egy Mohammad Erdin Avatar asked May 25 '11 04:05

Egy Mohammad Erdin


2 Answers

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

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

http://www.reportlab.org

like image 169
Andreas Jung Avatar answered Nov 04 '22 03:11

Andreas Jung


Also check out the pyfpdf library. I've used the php port of this library for a few years and it's quite flexible, allowing you to work with flowable text, lines, rectangles, and images.

http://code.google.com/p/pyfpdf

like image 29
Vineet Bansal Avatar answered Nov 04 '22 04:11

Vineet Bansal