将 svg 转换为 pdf:为什么我会丢失文本?

发布于 2024-12-15 21:09:56 字数 596 浏览 4 评论 0原文

我正在使用 Batik 将 svg 转换为 pdf。 Batik 输出的 pdf 没有文本。 svg 确实有文本。如果我使用 Batik 光栅化为 png,我确实会得到文本。

我使用的字体是Arial。我在 debian 盒子上。 Arial 已安装。这是我正在使用的命令:

/usr/bin/java -jar /usr/local/share/java/batik-1.7/batik-rasterizer.jar \
    -m application/pdf -bg 255.255.255.255 -d /tmp/olV0zQ_wYQ/chart.pdf \ 
    /tmp/tAi25KAE2z/tmp.svg

然后我得到以下输出:

About to transcode 1 SVG file(s)

Converting tmp.svg to /tmp/olV0zQ_wYQ/chart.pdf ... ... success

这是我的 svg 文件

I'm using Batik to convert an svg to a pdf. The pdf that Batik outputs has no text. The svg does have text. If I use Batik to rasterize to png, I do get text.

The font I am using is Arial. I am on a debian box. Arial is installed. Here is the command I am using:

/usr/bin/java -jar /usr/local/share/java/batik-1.7/batik-rasterizer.jar \
    -m application/pdf -bg 255.255.255.255 -d /tmp/olV0zQ_wYQ/chart.pdf \ 
    /tmp/tAi25KAE2z/tmp.svg

And then I get the following output:

About to transcode 1 SVG file(s)

Converting tmp.svg to /tmp/olV0zQ_wYQ/chart.pdf ... ... success

Here is my svg file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柏拉图鍀咏恒 2024-12-22 21:09:56

我刚刚遇到了同样的问题。
它在本地计算机上运行良好,但在远程服务器(debian)上运行不佳。
我通过重新定位文本解决了这个问题(字体在那里,但看不见)

请尝试以下操作:

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="330" viewBox="0 0 500 300">

<style type="text/css"><![CDATA[
.xAxisLabels
{
color: #000000;
font-family: Arial
}
]]></style>
<title>title</title>
<desc>stuff</desc>
<defs>
    <font-face font-family="Arial">
        <font-face-src>
        <font-face-uri xlink:href="/usr/share/hholdings/fonts/Arial.ttf"/>
        </font-face-src>
    </font-face>
</defs>

<text transform="translate(112.5 300)" class="xAxisLabels">jan</text>
<text transform="translate(204.17 300)" class="xAxisLabels">feb</text>
<text transform="translate(295.84 300)" class="xAxisLabels">mar</text>
<text transform="translate(387.51 300)"  class="xAxisLabels">apr</text>
</svg>

I just had the same problem.
It worked fine on the local machine but not on a distant server (debian).
I solved it by repositionning the text (the font was there but was out of view)

Please try this :

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="330" viewBox="0 0 500 300">

<style type="text/css"><![CDATA[
.xAxisLabels
{
color: #000000;
font-family: Arial
}
]]></style>
<title>title</title>
<desc>stuff</desc>
<defs>
    <font-face font-family="Arial">
        <font-face-src>
        <font-face-uri xlink:href="/usr/share/hholdings/fonts/Arial.ttf"/>
        </font-face-src>
    </font-face>
</defs>

<text transform="translate(112.5 300)" class="xAxisLabels">jan</text>
<text transform="translate(204.17 300)" class="xAxisLabels">feb</text>
<text transform="translate(295.84 300)" class="xAxisLabels">mar</text>
<text transform="translate(387.51 300)"  class="xAxisLabels">apr</text>
</svg>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文