使用Sphinx Extension将svg转换为pdf [英] Using Sphinx Extension to convert svg to pdf

查看:318
本文介绍了使用Sphinx Extension将svg转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司正在使用Sphinx来为我们的产品创建手册.我们的产品随附PDF和HTML文档.我们将Windows用作唯一的开发人员环境.

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.

一个必要的要求是从相同的源(* .rst文件)生成两种格式.

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

旧版文档使用了大量的SVG图像,但sphinx构建格式latex\includegraphics{}环境中不支持SVG文件.

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

现在,我找到了很有希望的Sphinx-Extension sphinx.ext.imgconverter,并将其包含在我的conf.py中.

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'
]

希望,如果我要构建LaTeX,请将所有SVG文件转换为PDF文件.不幸的是,该扩展的文档非常简短,并且没有有效的示例.

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

如果应根据html/pdf版本,用svg或pdf代替星星,则狮身人面像应该自己弄清楚.我从以前的帖子中获得的信息:

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. 使用Sphinx文档如何为HTML版本指定png图像格式,为Latex/PDF版本指定pdf图像格式?

但是以某种方式,我无法生成我的乳胶. 使用Sphinx文档如何为HTML版本指定png图像格式,为Latex/PDF版本指定pdf图像格式?

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?

相反会发出以下警告:

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

但是只有当我想在HTML的情况下构建LaTeX时,才没有警告.

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

我必须安装ImageMagick还是出现问题? Sphinx怎么知道,在哪里搜索ImageMagick?

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

更新

我刚刚将Sphinx更新为1.7.2版.它仍然不起作用.由于无法安装ImageMagick,因此暂时从我的conf.py中删除了扩展名sphinx.ext.imgconverter来测试手动解决方案.我使用inkscape将所有图像手动转换为pdf/png.

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.

现在,如果我使用make latex进行编译,则会收到以下警告.

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

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

但是source目录和build/latex目录中肯定都有手动转换的图像(pdf,png).

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

我的LaTeX文件被编译成类似以下内容的文件:

My LaTeX file is compiled to something like:

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

而且我无法使用pdflatex进行编译.

And I'm unable to compile it with pdflatex.

LaTeX Error: Unknown graphics extension: .*.

conf.py中的LaTeX Builder是否有一些设置可以拍摄转换后的图像?

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

如果我在conf.py中包含以下几行,则会发生意外情况:

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' ]

我的LaTeX文件的输出现在包含以下行:

The output of my LaTeX file now contains the line:

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

如果我从supported_image_types中删除类型image/svg+xml,我将再次遇到上一个错误.我的印象是,sphinx-build在错误的位置查找转换后的图像.但这只是一个主意.

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. 我怀疑该错误与该问题有关.它已在Sphinx 1.7中修复,这表明您已经发布了Sphinx< 1.7安装.升级到Sphinx 1.7或更高版本. 提示:始终在源代码存储库中搜索帮助.
  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:

在内部,此扩展程序使用 Imagemagick 来转换图像.

这意味着它必须已安装并且在您的系统路径中.

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

这篇关于使用Sphinx Extension将svg转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆