[英]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.