我正在尝试使用Batik(v1.12)和PDFTranscoder(fop v2.4)将SVG文档转换为PDF。
问题是我的SVG包含某种方式未转换为PDF的链接。是否支持它,或者存在已知问题,或者我试图以错误的方式使用它?
下面是input document的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);
}
}
可以在here上查看输出PDf文档。如您所见,当悬停文本(并单击它)时,没有链接。
谢谢您的帮助!