如何使用 iTextSharp 在现有 PDF 中插入指向另一个页面的超链接? [英] How do I insert a hyperlink to another page with iTextSharp in an existing PDF?

查看:41
本文介绍了如何使用 iTextSharp 在现有 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆