现有PDF中的超链接



我正在尝试添加一个基于PDF中已知位置坐标的超链接。我尝试过编辑实体pdf代码,并添加了一个链接,但在这个过程中删除了pdf上的其他内容。

[/Rect [ x x x x ]                     
    /Action                                     
  <</Subtype /URI/URI (http://www.xxxxx.com/)>>
    /Subtype /Link                              
/ANN pdfmark

有没有办法在不损坏现有pdf的情况下添加超链接?转换为不同的文件格式添加链接并转换回是更好的方法吗?可能的商业用途阻止了某些gnu许可产品的使用。

Debenu Quick PDF库也提供了一个解决方案。我还建议不要编辑PDF文件的"物理代码"(使用记事本或其他工具),因为它不会提供任何解决方案,在其他情况下也不会。

下面是一个如何使用Debenu快速PDF库的示例代码:

/* Add a link to a webpage*/
// Set the origin for the co-ordinates to be the top left corner of the page.
DPL.SetOrigin(1);
// Adding a link to an external web page using the AddLinkToWeb function.
DPL.AddLinkToWeb(200, 100, 60, 20, "www.debenu.com", 0);
// Hyperlinks and text are two separate elements in a PDF, 
//so we'll draw some text now so that you know 
//where the hyperlink is located on the page.
DPL.DrawText(205, 114, "Click me!");
// When the Debenu Quick PDF Library object is initiated a blank document
// is created and selected in memory by default. So
// all we need to do now is save the document to
// the local hard disk to see the changes that we've made.
DPL.SaveToFile("link_to_web.pdf");

Debenu 的成员

Docotic.Pdf库可以向现有Pdf添加超链接。该库是*GPL许可的,购买许可证后可用于商业解决方案。

下面是一个代码,它将超链接添加到PDF的第一页。

using System;
using System.Drawing;
public static void AddHyperlink()
{
    // NOTE: 
    // When used in trial mode, the library imposes some restrictions.
    // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
    // for more information.
    using (PdfDocument pdf = new PdfDocument("input.pdf"))
    {
        PdfPage page = pdf.Pages[0];
        RectangleF rectWithLink = new RectangleF(10, 70, 200, 100);
        page.AddHyperlink(rectWithLink, new Uri("http://google.com"));
        pdf.Save("output.pdf");
    }
}

免责声明:我为图书馆的供应商工作。

最新更新