0

I am trying to add a hyperlink based off of known position coordinates in the PDF. I have tried editing the physical pdf code and have added a link, but in the process deleted other content on the pdf.

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

Is there any way of adding the hyperlink without corrupting the existing pdf? Would converting to a different file format adding the link and converting back be a better approach? Possible commercial use prevents use of some gnu licensed products.

4

2 回答 2

1

Debenu Quick PDF Libarary也提供了一个解决方案。我还建议不要编辑 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");

德贝努成员

于 2014-11-03T14:41:10.443 回答
0

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");
    }
}

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

于 2014-10-04T19:39:57.167 回答