Using Sphinx Extension to convert svg to pdf

喜你入骨 提交于 2020-07-06 19:20:16

问题


My company is using Sphinx to create the manuals for our products. Our products are shipped with PDF and HTML documentations. We are using Windows as a sole developer environment.

A necessary requirement is to generate both kind of format from the same sources (*.rst files).

A legacy documentation uses extensive SVG-Images, but the sphinx build format latex does not support SVG-Files in \includegraphics{} environments.

Now I found the promising Sphinx-Extension sphinx.ext.imgconverter and included it into my conf.py.

extensions = [
    'sphinx.ext.imgmath',
    'sphinx.ext.ifconfig',
    'sphinx.ext.imgconverter'
]

Hopefully, converting all SVG-Files into PDF-files if I'm building LaTeX. Unfortunately, the documentation of the extension is very short and there is no working example.

http://www.sphinx-doc.org/en/master/ext/imgconverter.html#module-sphinx.ext.imgconverter

The contents of our rst files are basically:

.. image:: Image.*
   :width: 100px

Sphinx should figure out on its own, if the star should be replcaced by svg or pdf depending on the build html/pdf. This information I got from previous posts:

  1. Using Sphinx docs how can I specify png image formats for HTML builds and pdf image formats for Latex/PDF builds?

But somehow there I'm unable to generate my latex. Using Sphinx docs how can I specify png image formats for HTML builds and pdf image formats for Latex/PDF builds?

Instead the following warning is issued:

WARNING: no matching candidate for image URI u'Image.*'

But only if I wanted to build LaTeX in case of HTML there is no warning.

Do I have to install ImageMagick or is there is something wrong? How does Sphinx know, where to search ImageMagick?

Update

I just updated my Sphinx to version 1.7.2. It still doesn't work. As I was unable to install ImageMagick, I temporarily removed the extension sphinx.ext.imgconverter from my conf.py to test for a manual solution. I converted all the images manually to pdf/png using inkscape.

Now I got the following warnings, if I compile with make latex.

WARNING: a suitable image for latex builder not found: ['image/svg+xml']

But there are definitely manually converted images (pdf,png) in both the source directory and the build/latex directory, alike.

My LaTeX file is compiled to something like:

\noindent\sphinxincludegraphics[width=100\sphinxpxdimen]{{Image}.*}

And I'm unable to compile it with pdflatex.

LaTeX Error: Unknown graphics extension: .*.

Are there some settings for the LaTeX Builder in my conf.py to take my converted images?

If I include the following lines in my conf.py something unexpected happens:

from sphinx.builders.latex import LaTeXBuilder
LaTeXBuilder.supported_image_types = ['image/png', 'image/pdf','image/svg+xml' ]

The output of my LaTeX file now contains the line:

\noindent\sphinxincludegraphics[width=100\sphinxpxdimen]{{Image}.svg}

If I remove the type image/svg+xml from the supported_image_types I got the previous error again. My impression is, that sphinx-build looks for the converted images in the wrong places. But this is just an idea.


回答1:


  1. I suspect that the error is related to this issue. It was fixed in Sphinx 1.7, which indicates you have a release of Sphinx < 1.7 installeed. Upgrade to Sphinx 1.7 or greater. Tip: always search the source code repository for help.
  2. From the documentation for sphinx.ext.imgconverter:

    Internally, this extension uses Imagemagick to convert images.

    Which means it must be installed and be in your system path.



来源:https://stackoverflow.com/questions/49898798/using-sphinx-extension-to-convert-svg-to-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!