java - PDFTranscoder (org.apache.fop) 是否支持超链接?
问题描述
我正在尝试使用 Batik (v1.12) 和 PDFTranscoder (fop v2.4) 将 SVG 文档转换为 PDF。
问题是我的 SVG 包含未以某种方式转码为 PDF 的链接。它是否受支持,或者它是否存在已知问题,或者我是否试图以错误的方式使用它?
下面是输入文档的 SVG 标记(我可以重现该问题的最简单的) :
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="500"
height="500" x="0" y="0">
<g>
<a target="_blank" xlink:href="https://www.google.com">
<text x="50%" y="50%" style="font: 13px sans-serif"
text-anchor="middle" fill="rgb(0, 0, 0)">TEST
</text>
</a>
</g>
</svg>
还简化了 Java 中的代码片段,我用于转码:
public void convert(InputStream svgIn, OutputStream pdfOut) throws SvgExportException {
String parserName = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(parserName);
try {
Document document = factory.createDocument("svg", svgIn);
PDFTranscoder t = new PDFTranscoder();
TranscoderInput input = new TranscoderInput(document);
TranscoderOutput output = new TranscoderOutput(outputStream);
try {
transcoder.transcode(input, output);
} catch (TranscoderException e) {
throw new SvgExportException("Internal Error: Transcoding the SVG Document to PDF failed.", getReasonForTranscoderException(e));
}
} catch (IOException e) {
throw new CustomTechnicalException(e);
}
}
输出 PDf 文件可以在这里查看。如您所见,当悬停文本(并单击它)时,没有链接。
感谢您对此的任何帮助!
解决方案
推荐阅读
- mysql - MySQL中的相关子查询无法在主要的stmt中包含“列”
- usb - 如何从 menuconfig 启用 USB 小工具模式
- matlab - ROC曲线3类分类与Matlab
- r - 在 R 中从 github 下载某些包时遇到问题
- python - 如何在 plt.title() 中增加标题的字体大小?
- javascript - Tizen SDK 2.3.1 的 Tizen Wearable Web Widget App 数据路径中的文件管理
- jquery-ui - 即使我不再使用 jquery ui,为什么 Google lighthouse 会在我的网站上看到 jquery ui 漏洞
- windows - 如何在 WinDBG(实时)调试器会话中创建新线程?
- javascript - 在 csp 策略中设置随机数的正确程序是什么?
- javascript - 在 javascript 中使用 promise all() 进行昂贵的计算?