Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a simple pdf file in python?

Tags:

I'm looking for a way to output a VERY simple pdf file from Python. Basically it will consist of two columns of words, one in Russian (so utf-8 characters) and the other in English.

I've been googling for about an hour, and the packages I've found are either massive overkill (and still don't provide useful examples) such as ReportLab, or seem to assume that the only thing anyone would ever do with pdfs is concatenate several of them together (PyPdf, pdfrw).

Maybe I'm just missing something obvious, but all the ones I've seen seem to launch into some massive discussion about taking 17 pdf files and converting them into a 60 foot wide poster with 23 panes (slight exaggeration maybe), and leave me wondering how to get the "Hello World" program working. Any help would be appreciated.

like image 930
Keilan Avatar asked Aug 05 '12 02:08

Keilan


People also ask

Can Python produce a PDF?

Fortunately, the Python ecosystem has some great packages for reading, manipulating, and creating PDF files. In this tutorial, you'll learn how to: Read text from a PDF.

How do I make a simple PDF?

Open Acrobat and choose “Tools” > “Create PDF”. Select the file type you want to create a PDF from: single file, multiple files, scan, or other option. Click “Create” or “Next” depending on the file type. Follow the prompts to convert to PDF and save to your desired location.


1 Answers

You may use wkhtmltopdf. It is a command line utility that uses Webkit to convert html to pdf.

You can generate your data as html and style it with css if you want, then, use wkhtmltopdf to generate the pdf file.

like image 192
Mohammad Alhashash Avatar answered Oct 01 '22 02:10

Mohammad Alhashash