How to do a link to a file in rst with sphinx?

38,778

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.

Share:
38,778

Related videos on Youtube

Ger
Author by

Ger

I am associate professor in numerical simulations and physical-chemistry at Pau (France) in Université de Pau et des Pays de l'Adour. I did my phd in Paris XI (Orsay) on the study, by numeric simulations, of the photophysics properties of Fluorescent Proteins.

Updated on December 03, 2020

Comments

  • Ger
    Ger over 3 years

    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 ?

  • Mad Physicist
    Mad Physicist almost 6 years
    Alternatively, you can put your file in the _static folder (or whatever you configured that to be), and reference it directly from there.
  • 1313e
    1313e over 5 years
    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).
  • Henrik
    Henrik over 5 years
    @1313e OP asked for a link. Have a try with .. figure:: doc/mypdf.pdf to show the PDF.
  • Mayou36
    Mayou36 almost 5 years
    Link is outdated unfortunately. I did not find the updated version.
  • Pierre H.
    Pierre H. over 4 years
    @Mayou36: link to the :download: role documention is now fixed.