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

查看:485
本文介绍了我要如何插入超链接到另一个页面iTextSharp的在现有的PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个链接到现有的PDF跳转到其他网页上的坐标。

I would like to add a link to an existing pdf that jumps to a coordinate on another page.

我可以用这个code添加一个矩形:

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.

推荐答案

这是在书中的第7章解释的iText在行动 - 第二版。你可以找到一个例子在这里: 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);

在此code样品是要在其中添加链接,矩形矩形确定该网页上的坐标对象。

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天全站免登陆