rst2pdf

0.105 · active · verified Thu Apr 16

rst2pdf is a Python library and command-line tool for converting reStructuredText documents to PDF format, leveraging the ReportLab library for PDF generation. It supports various reStructuredText features, including styles, images, and syntax highlighting. The current version is 0.105, and it maintains an active release cadence with frequent minor updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the rst2pdf Python API to convert a reStructuredText string into a PDF file. The `rst2pdf` function from `rst2pdf.createpdf` is the primary programmatic interface.

import os
from rst2pdf.createpdf import rst2pdf

rst_content = '''
My PDF Document
===============

This is a sample reStructuredText document converted to PDF.

* Item A
* Item B

.. code-block:: python

   print("Hello, rst2pdf!")

.. note::
   This is a generated PDF using rst2pdf.
'''

output_filename = "sample_document.pdf"

try:
    # The rst2pdf function can take a string for 'text' and a filename for 'output'
    rst2pdf(text=rst_content, output=output_filename)
    print(f"PDF successfully created: {output_filename}")
except Exception as e:
    print(f"Error creating PDF: {e}")
    print("Please ensure all core dependencies like docutils and reportlab are correctly installed.")

view raw JSON →