Pergunta

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() 
Foi útil?

Solução

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

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

http://www.reportlab.org

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top