蜡染:Linux 上的 svg 到 pdf(无 X 服务器)
类似于将 SVG 转换为 PDF 中的方法 svg2pdf 转换在 Windows 下成功运行,并且可以在生成的 pdf 中搜索文本项。它也在 Linux (Ubuntu) 下生成 pdf(使用 -Djava.awt.headless=true 以避免由于缺少 X11 窗口服务器而出现异常),但文本项不可搜索,有时甚至被编码为图像。
是否也可以在 Linux 下保留 pdf 中的文本,我是否缺少一些运行时选项?
UPD:如果找不到某种字体,我可以以某种方式强制蜡染(SVGGraphics2D 或 SVGConverter)回退到默认字体吗?
Similar to approach in Convert SVG to PDF
the svg2pdf conversion runs successfully under windows and text items are searchable in the resulting pdf. It produces pdfs (with -Djava.awt.headless=true to avoid exceptions due missing X11 window server) under linux (Ubuntu) as well, but the text items are not searchable and sometimes are even coded as images.
Is it possible to preserve text in pdf under linux as well, am I missing some runtime options?
UPD: Can I somehow force batik (SVGGraphics2D or SVGConverter) to fall back to a default font, if certain font wasn't found?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
按照此处的食谱解决:
http://batik.2283329.n4.nabble.com/Placing-SVG-Text-into-PDF-td3778127.html
主要步骤:
Solved by following the recipe here:
http://batik.2283329.n4.nabble.com/Placing-SVG-Text-into-PDF-td3778127.html
major steps:
如果要将字体从 Windows 复制到 Linux,只需将
.ttf
文件复制到正确的位置即可(注意:某些字体受版权保护,需要许可才能安装)。无需将它们放入某种注册表中。要使它们在 Java 中可用,您有两个选择:
您可以在运行 batik 之前设置环境变量
JAVA_FONTS
打开
jre/lib
目录中的font.properties
文件,取消注释并设置为适当的字体目录:If you want to copy a font from Windows to Linux, you only need to copy the
.ttf
file to the right place (note: Some fonts are copyrighted and you need permission to install them). There is no need to put them into some kind of registry.To make them available in Java, you have two options:
You can set the environment variable
JAVA_FONTS
before running batikOpen
font.properties
file in thejre/lib
directory, uncommnent and set to the appropriate font directory:尝试为您想要使用的字体添加定义(带有网址):
我也遇到了同样的问题。我在 svg 中忘记的一件事是 type="text/css"。
Try to add definitions (with url) for those fonts you want to use:
I had the same problem. One thing that i forgot in svg was type="text/css".
安装 imagemagick。然后调用convert:
将转换为PDF。
install imagemagick. Then call convert:
which will convert into a PDF.