How do I create a simple pdf file in python?

14,197

Solution 1

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.

Solution 2

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.

Solution 3

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

Solution 4

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.

Share:
14,197

Related videos on Youtube

Keilan
Author by

Keilan

Updated on June 20, 2022

Comments

  • Keilan
    Keilan almost 2 years

    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.

    • Clayton Stanley
      Clayton Stanley over 11 years
      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.
    • jdi
      jdi over 11 years
      My coworker uses ReportLab for her PDF process in her app. Seems to work fine.
    • Mechanical snail
      Mechanical snail over 11 years
      possible duplicate of How to create PDF files in Python
    • phabtar
      phabtar over 10 years
      Not a duplicate, the question specifically says pypdf isn't the answer.
  • Keilan
    Keilan over 11 years
    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!
  • Serge
    Serge over 9 years
    Unfortunately doesn't support python 3 for now.