WeasyprintCairo在转换为PDF时失去了SVG文本标签。

问题描述 投票:0回答:1

我有一张由Bokeh生成的SVG图像,请问该如何处理?(此处链接) 在图表的左侧和底部都有标签。

图片本身可以很好的显示图表中的文字,但是,当通过Weasyprint转换为PDF时,文字就丢失了。(See here for a screenshot of the PDF)

有人遇到过类似的问题吗?我不知道如何调试,因为转换时没有错误。

我的导出功能的一个片段。

html = HTML(string=html_string)

    result = html.write_pdf('./tmp/example.pdf', stylesheets=[css],
    font_config=font_config)

在HTML模板中,我用css将图片嵌入到背景图中,如下图。

html body article#columns section#linechart{
  width: 100%;
  background: url(./tmp/linechart.svg) no-repeat center;
  background-size: contain;
  margin: 0;
  height: 500px;
  overflow: visible;
}

先谢谢你!

当前版本信息。

CairoSVG = 2.4.2
Weasyprint = 51
Python = 3.73
python django bokeh cairo weasyprint
1个回答
0
投票

我不确定这是否与Cairo或Weasyprint有关,但是,我发现问题的发生是由于SVG的字体风格化造成的。显然,Bokeh在实际的文本元素中使用了如下样式。

<text fill="#444444" stroke="none" font-family="helvetica" font-size="13px" font-style="normal" font-weight="normal" text-decoration="normal" x="472.67919921875" y="58" text-anchor="start" dominant-baseline="central">Opportunities</text>

大多数其他绘图库都是通过类或内联来使用正常的样式,如下图。

<text class="title plot_title" x="400.0" y="26">Opportunities entered YTD</text>

为了解决这个问题,我选择了使用Pygal(Kozea的另一个很棒的回帖),这解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.