首页 > 解决方案 > 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 文件可以在这里查看。如您所见,当悬停文本(并单击它)时,没有链接。

感谢您对此的任何帮助!

标签: javapdfsvgapache-fopbatik

解决方案


推荐阅读