40

Followed this link to try and generate pdf from Sphinx:

https://www.quora.com/How-to-create-a-PDF-out-of-Sphinx-documentation-tool

$ sphinx-build -b pdf source build/pdf

Error: Cannot find source directory  `/Users/seb/mydocs/source'.


$ make all-pdf
make: *** No rule to make target `all-pdf'.  Stop.
$ make pdf
make: *** No rule to make target `pdf'.  Stop.

Since tried in OSX:

$ conda install -c dfroger rst2pdf=0.93
Fetching package metadata .........
Solving package specifications: .
Error: Package missing in current osx-64 channels: 
  - rst2pdf 0.93*

You can search for packages on anaconda.org with

anaconda search -t conda rst2pdf

EDIT:

After pip install rst2pdf

install rst2pdf
register rst2pdf in your conf.py Sphinx config
extensions = ['sphinx.ext.autodoc','rst2pdf.pdfbuilder']

But adding 'rst2pdf.pdfbuilder' causes

Extension error:
Config value 'math_number_all' already present
make: *** [html] Error 1


$ sphinx-build -bpdf sourcedir outdir

But what do I specify as sourcedir and outdir? Example please.

EDIT:

Now after make html

and then:

 $ rst2pdf index.rst output.pdf
 index.rst:14: (ERROR/3) Unknown directive type "toctree".

 .. toctree::

 :maxdepth: 2

introduction tutorial multiple_jobs deployment project

index.rst:26: (ERROR/3) Unknown interpreted text role "ref".
index.rst:27: (ERROR/3) Unknown interpreted text role "ref".
index.rst:28: (ERROR/3) Unknown interpreted text role "ref".

Also:

$rst2pdf.py index.rst -o mydocument.pdf

Does produce a mydocument.pdf but completely different from html and toc to all the pages are not even there?

Image of pdf verse HTML same page

niceseb
  • 493
  • 1
  • 4
  • 11
  • Why do you use anconda/conda? If you don't have a specific reason for this, install pip and run "pip install rst2pdf". If you want to have more control over the style of your output, it's better to build the PDF via LaTeX. – Timotheus.Kampik Sep 17 '16 at 16:28

9 Answers9

35

This is from the official Sphinx documentation. If you have pdfTex tool installed in your machine, all you need is:

$ make latexpdf

Then, the generated pdf file(s) will be under _build/latex/<PROJECT-NAME>.pdf

So, the complete process from scratch would be as follows:

$ pip install -U sphinx # install the package
$ sphinx-quickstart # create a new project (answer the questions)
$ make latexpdf # compile and generate pdf file

Note that you may also "optionally" install whatever extensions needed by editing the file config.py

NOTE: This answer assumes LaTeX engine is installed on your machine.

Aziz Alto
  • 19,057
  • 5
  • 77
  • 60
  • 2
    Yeah this is a much better answer than using 'rst2pdf'. Also, just a quick note 'latexmk' needs to be installed, so a 'sudo apt install latexmk' may be necessary (which was the case for me). – ptolemy0 Dec 29 '20 at 16:49
  • Note that this answer requires Latex tools to be installed on your system, which may not be trivial depending on your OS: https://latextools.readthedocs.io/en/latest/install/ – phoenix Jan 21 '21 at 14:24
  • True, thanks. My bad I thought "If you have pdftext tool .." implied that. But I guess I should be more explicit. – Aziz Alto Jan 22 '21 at 04:41
25

I have succeeded in generating a PDF file for the DevStack document by following the configuration changes in this link:

Here are the steps:

  1. Edit your conf.py (edit or append values)

    extensions = ['rst2pdf.pdfbuilder']
    pdf_documents = [('index', u'rst2pdf', u'Sample rst2pdf doc', u'Your Name'),]
    
  2. Install the "rst2pdf" if necessary

    pip install rst2pdf
    
  3. Build the PDF file like this:

    sphinx-build -b pdf doc/source doc/build
    
phoenix
  • 7,988
  • 6
  • 39
  • 45
Alan Zhiliang Feng
  • 1,774
  • 18
  • 20
  • 1
    Sadly the quora link is no longer valid. – David Bridgeland Mar 22 '19 at 20:31
  • 8
    The source code of the package `rst2pdf` contains multiple `SyntaxErrors` in python 3.7. – JDG Sep 09 '19 at 13:02
  • 5
    As of September 2019, the latest release `rst2pdf` does not support Python 3, but the master branch does. Follow [this issue](https://github.com/rst2pdf/rst2pdf/issues/796) to track a Python 3-compatible release. – phoenix Sep 18 '19 at 19:36
  • 1
    `rst2pdf` is resurrected and is available at https://github.com/rst2pdf/rst2pdf. It supports Python 3. See this for more information https://gist.github.com/alfredodeza/7fb5c667addb1c6963b9 – yoonghm Mar 28 '20 at 15:47
  • How can I use the sphinx-build command to generate PDF with rst2pdf custom styles. Currently the command: rst2pdf index.rst -s paamrstyles.txt creates only single PDF. – Sushivam Aug 04 '22 at 04:13
  • Sadly rst2pdf does not properly support **equations**: https://github.com/rst2pdf/rst2pdf/issues/1028#issuecomment-1593322989 – Stefan Aug 01 '23 at 09:25
9

Succeeded in Pdf Generation via Latex (for windows 10)... No need to change existing conf.py file in Sphinx... the best solution is install MiKTeX....install Perl (ActiveState).... after when running sphinx type 'make HTML' type 'make latex' and then make latexPdf... this solved my issue.

  • 2
    Thank you my brother. Your explain is clair. It work as well for me after many breakdown compilation with readthedoc.org. Thank very much. – Mbambadev Sep 14 '20 at 10:09
4

You could avoid rst2pdf and use make pdflatex to build pdf output via a latex file.

cf more info:

https://docs.typo3.org/typo3cms/extensions/sphinx/AdvancedUsersManual/RenderingPdf/

tfv
  • 6,016
  • 4
  • 36
  • 67
  • Fior `make pdflatex` to work for Unicode characters, the TeX environment in the platform should be set appropriately. Also, perhaps the language statment like `language = 'XXX'` is needed in `conf.py` – Masa Sakano Mar 05 '20 at 21:36
2

Make sure to have a look at http://rst2pdf.ralsina.me/handbook.html#sphinx.

Following applies to Ubuntu 16.

But it is probably less painful to install a full LaTex suite than to try to get this tool running; it is very sensitive to errors, and is difficult to use.

I took a look there (https://tex.stackexchange.com/a/95373) and it looks daunting...

this is more encouraging: https://milq.github.io/install-latex-ubuntu-debian/

And I did it:

sudo apt-get install texlive-full
make clean latexpdf

is worthwhile your patience (and disk space) to install. I got rid of rst2pdf.

axd
  • 626
  • 5
  • 13
  • 1
    as an aside, you should NOT use ubuntu texlive install, rather install texlive directly from https://www.tug.org/texlive/ – Ahmed Masud Jul 23 '20 at 05:19
  • thank you. it is sometimes painful to find out where the truth lies in Stackoverflow... – axd Jul 29 '20 at 13:01
  • I just went through this entire exercise I'm going to create a video and a detailed answer here, on how to properly create PDFs nice-looking PDFs from restructuredtext – Ahmed Masud Jul 29 '20 at 13:15
1

Found this related post which discovers that rst2pdf breaks math rendering in Sphinx 1.4.1 because it imports a dummy math module.

In rst2pdf.pdfbuilder:setup(), it calls mathbase.setup() internally to install dummy math module. It causes conflicts and raise errors.

I had this same error when running sphinx-build -b pdf

Extension error:
Config value 'math_number_all' already present

Now looking at latex option, and exporting to pdf as @tfv posted. pdflatex is a larger universe of TeX distribution.

Community
  • 1
  • 1
SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
0

As an alternative to latexpdf: rinohtype

Once rinohtype is installed, sphinx-build -b rinoh . _build

Brian Wright
  • 93
  • 1
  • 9
0

Create a file documentation.md, and open it in Typora software. Navigate to the Sphynx documentation that you need, mark with mouse and copy inside Typora. Then inside typora export as PDF. Done.

71GA
  • 1,132
  • 6
  • 36
  • 69
0

cd into the folder where the makefile is and make latex worked out ok

Renan
  • 1
  • 1