如何使用 iTextSharp 在现有 PDF 中插入指向另一个页面的超链接? [英] How do I insert a hyperlink to another page with iTextSharp in an existing PDF?
问题描述
我想添加一个指向现有 pdf 的链接,该链接跳转到另一个页面上的坐标.
I would like to add a link to an existing pdf that jumps to a coordinate on another page.
我可以使用此代码添加一个矩形:
I am able to add a rectangle using this code:
PdfContentByte overContent = stamper.GetOverContent(1);
iTextSharp.text.Rectangle rectangle = new Rectangle(10,10,100,100,0);
rectangle.BackgroundColor = BaseColor.BLUE;
overContent.Rectangle(rectangle);
stamper.Close();
如何创建可点击的链接?谢谢.
How can I do similar to create a link that is clickable? Thanks.
推荐答案
这在 "iText 一书的第 7 章中有解释在行动 - 第二版".你可以在这里找到一个例子:http://itextpdf.com/examples/iia.php?id=150
This is explained in chapter 7 of the book "iText in Action - Second Edition". You can find an example here: http://itextpdf.com/examples/iia.php?id=150
如果你需要C#版本,请看这里:http://kuujinbo.info/iTextInAction2Ed/index.aspx
If you need the C# version, please take a look here: http://kuujinbo.info/iTextInAction2Ed/index.aspx
更具体地说:http://kuujinbo.info/iTextInAction2Ed/index.aspx?ch=Chapter07&ex=TimetableAnnotations2
PdfAnnotation annotation = PdfAnnotation.CreateLink(
stamper.Writer, rect, PdfAnnotation.HIGHLIGHT_INVERT,
new PdfAction("http://itextpdf.com/")
);
stamper.AddAnnotation(annotation, page);
在此代码示例中,page
是要添加链接的页面编号,rect
是定义链接的 Rectangle
对象该页面上的坐标.
In this code sample page
is the number of the page where you want to add the link and rect
is the Rectangle
object defining the coordinates on that page.
这篇关于如何使用 iTextSharp 在现有 PDF 中插入指向另一个页面的超链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!