使用itext java将锚点添加到pdf
我正在尝试使用itext java
api将anchor(命名为destinations)添加到pdf。但是它不起作用。当我单击文本时,什么也没有发生。这就是我在做什么。
Anchor anchor = new Anchor("Jump down to next paragraph");
anchor.setReference("#linkTarget");
Paragraph paragraph = new Paragraph();
paragraph.add(anchor);
document.add(paragraph);
Anchor anchorTarget =
new Anchor("This is the target of the link above");
anchor.setName("linkTarget");
Paragraph targetParagraph = new Paragraph();
targetParagraph.setSpacingBefore(50);
targetParagraph.add(anchorTarget);
document.add(targetParagraph);
我究竟做错了什么?。任何帮助
回答:
试试这个。它为我工作。setLocalGoto()
并setLocalDestination()
会做魔术。
Chunk chunk = new Chunk("Contact information"); chunk.setLocalGoto("contact");
document.add(new Paragraph(chunk));
document.newPage();
chunk chunk1 = new Chunk("Contact information");
chunk1.setLocalDestination("contact");
Chapter chapter = new Chapter(new Paragraph(chunk1),1);
chapter.setNumberDepth(0);
document.add(chapter);
以上是 使用itext java将锚点添加到pdf 的全部内容, 来源链接: utcz.com/qa/399066.html