Skip to content

Instantly share code, notes, and snippets.

@alfredodeza
Last active December 20, 2024 19:57
Show Gist options
  • Save alfredodeza/7fb5c667addb1c6963b9 to your computer and use it in GitHub Desktop.
Save alfredodeza/7fb5c667addb1c6963b9 to your computer and use it in GitHub Desktop.
pdf output from sphinx with rst2pdf
1. Install rst2pdf
- use your package manager (or)
- pip install rst2pdf (or)
- easy_install rst2pdf
2. Add rst2pdf to the list of extensions in conf.py
extensions = ['rst2pdf.pdfbuilder']
This list will be empty if you accepted the defaults when the project was setup. If not, just append 'rst2pdf.pdfbuilder' to the list.
3. Add a pdf_documents variable to conf.py
pdf_documents = [('index', u'rst2pdf', u'Sample rst2pdf doc', u'Your Name'),]
# index - master document
# rst2pdf - name of the generated pdf
# Sample rst2pdf doc - title of the pdf
# Your Name - author name in the pdf
4. Generate pdf
sphinx-build -b pdf source build/pdf
The generated pdf will be in the build/pdf directory.
@syedjafer
Copy link

Tanq u saved me .

@aaxc
Copy link

aaxc commented May 15, 2019

Does this work for Windows?
I'm getting such error:

Exception occurred: File "c:\python37\lib\site-packages\sphinx\registry.py", line 315, in load_extension mod = __import__(extname, None, None, ['setup']) File "c:\python37\lib\site-packages\rst2pdf\pdfbuilder.py", line 129 except Exception, e: ^ SyntaxError: invalid syntax

@ayleph
Copy link

ayleph commented May 23, 2019

Does this work for Windows?
I'm getting such error:

Exception occurred: File "c:\python37\lib\site-packages\sphinx\registry.py", line 315, in load_extension mod = __import__(extname, None, None, ['setup']) File "c:\python37\lib\site-packages\rst2pdf\pdfbuilder.py", line 129 except Exception, e: ^ SyntaxError: invalid syntax

This is a Python 2/3 issue, not a Windows issue. You must be running Python 3, and it looks like rst2pdf (at least the version available through PyPI) isn't compatible with Python 3.

@Emma-sap
Copy link

I have one error:
Sphinx error:
Builder name pdf not registered or available through entry point
so how should I fix it?

@johnthagen
Copy link

To track a Python 3-compatible release for rst2pdf, see this issue.

@the-vampiire
Copy link

brilliant man. thank you for the guide.

@saileshkush95
Copy link

how can i add button or link to generate pdf, in sphinx generated document instead of using terminal

@alfredodeza
Copy link
Author

how can i add button or link to generate pdf, in sphinx generated document instead of using terminal

You can't

@aitesam961
Copy link

Great work listing it out.
I'm using sphinx_rtd_theme that works well with html build but the PDF build returns no theme and just the headings stuff.
Is there a way to produce ReadtheDocs theme in PDF?

Much appreciated.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment