54

I am writing a documentation and I would like to include links to pdf files or zip archives. How can I achieve that using rst language and sphinx ?

If I do that

here is a pdf file : `pdf <doc/mypdf.pdf>`_

It does not work because, during the compilation sphinx do not copy the contains of the doc directory (I use the makefile generated by sphinx-quickstart).

On the contrary, using the image directive :

.. image:: img/plop.png

sphinx does copy the plop.png image in build directory. How can I obtain the same behavior for pdf or zip archive ?

Ger
  • 9,076
  • 10
  • 37
  • 48
  • try the `:download:` role -- see http://stackoverflow.com/questions/2921724/include-a-text-file-as-is-in-python-sphinx-docs/ – Bonlenfum Jan 15 '13 at 20:31

2 Answers2

78

A solution is to use the :download: “role” (detailed in the sphinx documentation on roles).

Here is a short example assuming you have a file mypdf.pdf in a directory doc. The directory doc and your rst file must be in the same directory:

here is a pdf file :download:`pdf <doc/mypdf.pdf>`

Note that you mustn't put a blank space between :download: and the path to the file.

Pierre H.
  • 388
  • 1
  • 11
Ger
  • 9,076
  • 10
  • 37
  • 48
-1

The image directive also works for PDF files.

.. image:: doc/mypdf.pdf
Henrik
  • 2,771
  • 1
  • 23
  • 33
  • This will only show a link to the PDF-file, not display the file itself (which is something I am struggling with at the moment). – 1313e Dec 06 '18 at 00:45
  • @1313e OP asked for a link. Have a try with `.. figure:: doc/mypdf.pdf` to show the PDF. – Henrik Dec 10 '18 at 12:42