How to create a PDF-out-of-Sphinx-documentation-tool

niceseb picture niceseb · Sep 16, 2016 · Viewed 32.7k times · Source

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

Answer

Alan Zhiliang Feng picture Alan Zhiliang Feng · Dec 8, 2017

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