繁体   English   中英

使用itext java和html将锚添加到pdf

[英]Add anchor to pdf using itext java and html

我尝试使用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>

但是最后当您单击链接时并不会定位

我究竟做错了什么?

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

<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属性添加到<p>标记。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM