现有PDF中的超链接
我试图添加一个超链接的基础上已知的位置坐标在PDF。我尝试过编辑物理pdf代码并添加了一个链接,但在此过程中删除了pdf上的其他内容现有PDF中的超链接,pdf,hyperlink,pdf-annotations,Pdf,Hyperlink,Pdf Annotations,我试图添加一个超链接的基础上已知的位置坐标在PDF。我尝试过编辑物理pdf代码并添加了一个链接,但在此过程中删除了pdf上的其他内容 [/Rect [ x x x x ] /Action <</Subtype /URI/URI (http://www.xxxxx.com/)>> /Subtype /Link
[/Rect [ x x x x ]
/Action
<</Subtype /URI/URI (http://www.xxxxx.com/)>>
/Subtype /Link
/ANN pdfmark
[/Rect[x]
/行动
/子类型/链接
/安·帕夫马克
有没有办法在不损坏现有pdf的情况下添加超链接?转换为不同的文件格式添加链接并转换回是更好的方法?可能的商业用途会阻止使用某些gnu许可产品。可以将超链接添加到现有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");
}
}
免责声明:我为该库的供应商工作。还提供了一个解决方案。我还建议不要编辑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");
Debenu的成员可以使用任何通用PDF库。GPL不阻止商业应用,但阻止大多数类型的专有应用。