使用ITextSharp编辑PDF中的超链接和锚点 [英] Editing Hyperlink and Anchors in PDF using ITextSharp

查看:1225
本文介绍了使用ITextSharp编辑PDF中的超链接和锚点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iTextSharp库和C#.Net来分割我的PDF文件。

I am using iTextSharp library and C#.Net for splitting my PDF file.

考虑一个名为sample.pdf的PDF文件,其中包含72页。此sample.pdf包含具有导航到其他页面的超链接的页面。例如:在第4页中有三个超链接,点击时可导航到相应的第24,27,28页。与第4页一样,有近12页与它们有这个超链接。

Consider a PDF file named sample.pdf containing 72 pages. This sample.pdf contains pages that have hyperlink that navigate to other page. Eg: In the page 4 there are three hyperlinks which when clicked navigates to corresponding 24th,27th,28th page. As same as the 4th page there are nearly 12 pages that is having this hyperlinks with them.

现在使用iTextSharp库我将这个PDF页面分成72个单独的文件,并保存为名称为.pdf,2.pdf .... 72.pdf。所以在4.pdf中点击超链接我需要让PDF导航到24.pdf,27.pdf,28.pdf。

Now using iTextSharp library I had split this PDF pages into 72 separate file and saved with the name as 1.pdf,2.pdf....72.pdf. So in the 4.pdf when clicking that hyperlinks I need to make the PDF navigate to 24.pdf,27.pdf,28.pdf.

请帮帮我。如何编辑和设置4.pdf中的超链接,以便导航到相应的pdf文件。

Please help me out here. How can I edit and set the hyperlinks in the 4.pdf so that it navigates to corresponding pdf files.

谢谢你,
Ashok

Thank you, Ashok

推荐答案

你是什么想要很有可能。您想要的是需要使用低级PDF对象(PdfDictionary,PdfArray等)。

What you want is quite possible. What you want will require you to work with the low-level PDF objects (PdfDictionary, PdfArray, etc).

每当有人需要处理这些对象时,我总是请参阅 PDF参考。在您的情况下,您将要检查第7章(特别是第3节)和第12章,第3节(文档级导航)和第5章(注释)。

And whenever someone needs to work with those objects, I always refer them to the PDF Reference. In your case, you'll want to examine chapter 7 (particularly section 3) and chapter 12, sections 3 (doc-level navigation) and 5 (annotations).

假设你已经读过,这就是你需要做的事情:

Assuming you've read that, here's what you need to do:


  1. 逐步浏览每个页面的注释数组(在原始文档中,在分解之前)。

  1. Step through the annotation array of each page (in the original doc, before breaking it up).

  1. 查找所有链接注释&他们的目的地。

  2. 为与新文件对应的链接建立新目的地。

  3. 将新目的地写入链接注释。


  • 使用PdfCopy将此页面写入新PDF(它将复制注释以及页面内容)。

  • 步骤1.1并不简单。有几种不同的本地goto注释格式。您需要确定给定链接指向的页面。某些链接可能表示PDF等效于下一页或上一页,而其他链接则包含对特定页面的引用。这将是间接对象引用,而不是页码。

    Step 1.1 isn't simple. There are several different kinds of "local goto" annotation formats. You need to determine which page a given link points to. Some links might say the PDF equivalent of "next page" or "previous page", while others will include a reference to a particular page. This will be an "indirect object reference", not a page number.

    要确定页面引用的页码,您需要... ouch。好的。最有效的方法是为原始文档中的每个页面调用PdfReader.GetPageRef(int pageNum)并将其缓存在地图中(reference-> pageNum)。

    To determine the page number from a page reference, you need to... ouch. Okay. The most efficient way would be to call PdfReader.GetPageRef(int pageNum) for each page in the original document and cache it in a map (reference->pageNum).

    然后,您可以通过创建远程goto PdfAction并将其写入链接注释的A(操作)条目来构建远程goto链接,删除之前存在的任何内容(可能是Dest)。

    You can then build "remote goto" links by creating a remote goto PdfAction, and writing that into the link annotation's "A" (action) entry, removing anything that was there before (probably a "Dest").

    我不太会说C#,所以我会把实际的实现留给你。

    I don't speak C# very well, so I'll leave the actual implementation to you.

    这篇关于使用ITextSharp编辑PDF中的超链接和锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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