Search code examples
pythonpdfpython-sphinxstatic-files

Custom role to link PDF file as static content


I am trying to write a custom role for Sphinx to allow linking to PDF files that are then displayed in the browser (rather than being downloaded when using the :download: role).

I have got as far as a role that creates a link to the PDF file:

:pdf:`Document Title <pdf/document.pdf>`

generates something like:

<a href="pdf/document.pdf>Document Title</a>

However, I don't know how to get Sphinx to copy the pdf directory to the output directory. Is this possible?


Solution

  • Use html_static_path in your conf.py.

    html_static_path = ['_static', 'pdf']