【问题标题】:Add anchor to pdf using itext java and html使用 itext java 和 html 将锚点添加到 pdf
【发布时间】:2015-01-29 17:57:20
【问题描述】:

我尝试使用 IText java 从 html 生成 pdf。我需要创建链接锚。下面是示例代码。

Java 代码:

String k = pdfService.all(request);
OutputStream os = response.getOutputStream();
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, os);
document.open();
InputStream is = new ByteArrayInputStream(k.getBytes());
XMLWorkerHelper.getInstance().parseXHtml(writer, document, is);
document.close();

HTML代码:

    <?xml version="1.0" encoding="utf-8"?>
   <html>
     <head>
       <meta charset="utf-8"/>
       <title>title</title>
     </head>
     <body bgcolor="#ffffff">
      <p><a href="#anccc" >GoTo</a></p>
      ... some code ...
      <p id="anccc">anchor</p>
     </body>
  </html>

但是最后点击链接的时候并没有去锚

我做错了什么?

【问题讨论】:

    标签: java html pdf itext anchor


    【解决方案1】:

    据我所知,内部锚点是这样创建的:

    <a href="#myanchor">Click here to go to my anchor</a>
    ...
    <a name="myanchor">This is the destination of a link</a>
    

    XML Worker 支持。

    不支持将id 属性添加到&lt;p&gt; 标记。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-31
      • 2022-07-31
      • 2015-06-04
      • 1970-01-01
      • 2017-12-19
      • 2023-03-12
      • 2014-02-17
      • 1970-01-01
      相关资源
      最近更新 更多