Welcome folks today in this blog post we will be generating pdf files from raw text
or files in python using rst2pdf library
.
pip install rst2pdf
The usual way of creating PDF from reStructuredText is by going through LaTeX. This tool provides an alternative by producing PDF directly using the ReportLab library.
More information is available at the main website.
Features
- User-defined page layout. Multiple frames per page, multiple layouts per document.
- Page transitions
- Cascading stylesheet mechanism, define only what you want changed.
- Supports TTF and Type1 font embedding.
- Any number of paragraph styles using the class directive.
- Any number of character styles using text roles.
- Custom page sizes and margins.
- Syntax highlighter for many languages, using Pygments.
- Supports embedding almost any kind of raster or vector images.
- Supports hyphenation.
- Sphinx integration
- Full user’s manual
Usage
To convert a reStructuredText document to a PDF, simply run:
1 |
$ rst2pdf <document name> output.pdf |
For information on available options, use -h
:
1 |
$ rst2pdf -h |
To enable basic integration with Sphinx, modify your conf.py
file to enable the rst2pdf.pdfbuilder
extension and configure the pdf_documents
option. For example:
1 2 3 4 5 6 7 8 9 10 |
extensions = [ # ... 'rst2pdf.pdfbuilder', ] # Grouping the document tree into PDF files. List of tuples # (source start file, target name, title, author, options). pdf_documents = [ ('index', 'MyProject', 'My Project', 'Author Name'), ] |