【问题标题】:Hyperlink in existing PDF现有 PDF 中的超链接
【发布时间】:2014-10-04 17:28:22
【问题描述】:

我正在尝试根据 PDF 中的已知位置坐标添加超链接。我已尝试编辑物理 pdf 代码并添加了链接,但在此过程中删除了 pdf 上的其他内容。

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

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

【问题讨论】:

  • 任何通用 PDF 库都应该可以做到这一点。

标签: pdf hyperlink pdf-annotations


【解决方案1】:

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

以下是如何使用 Debenu Quick 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");

德贝努成员

【讨论】:

    【解决方案2】:

    Docotic.Pdf library 可以为现有 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");
        }
    }
    

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

    【讨论】:

    • GPL 不阻止商业应用程序,但大多数类型的专有应用程序。
    猜你喜欢
    • 2019-12-31
    • 2014-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-06
    • 2013-04-11
    • 1970-01-01
    相关资源
    最近更新 更多