23

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.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Keilan
  • 331
  • 1
  • 2
  • 10
  • I don't know of any tools, but you could approach your problem differently. Output what you want formatted to a text file, and then use a bash txt->pdf tool on that. – Clayton Stanley Aug 05 '12 at 02:46
  • My coworker uses ReportLab for her PDF process in her app. Seems to work fine. – jdi Aug 05 '12 at 02:53
  • 1
    possible duplicate of [How to create PDF files in Python](http://stackoverflow.com/questions/2252726/how-to-create-pdf-files-in-python) – Mechanical snail Aug 06 '12 at 05:16
  • Not a duplicate, the question specifically says pypdf isn't the answer. – phabtar Aug 17 '13 at 05:41

6 Answers6

10

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.

Mohammad Alhashash
  • 1,543
  • 1
  • 14
  • 30
  • This works. I tried some of the other solutions and most of them had trouble with the utf-8 characters (although I'm sure there is some easy fix I don't know how to do that would solve it) but this one had no trouble. Thanks for your help! – Keilan Aug 05 '12 at 23:31
5

rst2pdf does exactly what you want; with restructured text input

Styles can be applied inline with native RST styling, and document-level properties (including fonts) are controlled with a style sheet.

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
1

Try pod (python open document) is a library that allows to easily generate documents whose content is dynamic.

pod generates another ODF text document (ODT) that contains the desired result.pod can call OpenOffice in server mode to generate the result in PDF, DOC, RTF or TXT format.

NIlesh Sharma
  • 5,445
  • 6
  • 36
  • 53
1

A recipe to convert a text file to a PDF. A little long but pure Python and with no external dependencies.

Noufal Ibrahim
  • 71,383
  • 13
  • 135
  • 169
0

you could also use weasyprint it supports specific css paged media features

yvess
  • 1,992
  • 19
  • 17
0

A simpler approach would be to use the csv package to write the two columns to a .csv file, then read it into a spreadsheet & print to pdf. Not 100% python but maybe 90% less work ...

simonltwick
  • 310
  • 2
  • 6