使用Aspose.Pdf库生成带有超链接的密码保护PDF

时间:2016-07-16 12:52:51

标签: c# .net aspose aspose.pdf

我希望有人可以帮我解决我在使用Aspose.Pdf库生成带有密码保护的PDF的超链接时遇到的问题。问题是密码保护似乎搞砸了超链接......

以下代码正常(没有任何密码保护):

// create new PDF doc with hyperlink in
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = doc.Pages.Add();
Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("hyperlink test");
textFragment.Hyperlink = new Aspose.Pdf.WebHyperlink("https://www.google.co.uk/");
page.Paragraphs.Add(textFragment);

// password protect the PDF
// Aspose.Pdf.Permissions permission = (Aspose.Pdf.Permissions.PrintingQuality | Aspose.Pdf.Permissions.PrintDocument | Aspose.Pdf.Permissions.ModifyTextAnnotations | Aspose.Pdf.Permissions.FillForm | Aspose.Pdf.Permissions.ModifyContent | Aspose.Pdf.Permissions.ExtractContent | Aspose.Pdf.Permissions.AssembleDocument);
// doc.Encrypt("pass1", "pass2", permission, Aspose.Pdf.CryptoAlgorithm.RC4x128);

// save the doc
doc.Save("C:\\temp\\PDFHyperlink\\test.pdf");

生成的PDF很好,超级链接成功打开浏览器并导航到谷歌

enter image description here

但是,如果取消注释密码保护PDF的行,则超链接

// create new PDF doc with hyperlink in
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
Aspose.Pdf.Page page = doc.Pages.Add();
Aspose.Pdf.Text.TextFragment textFragment = new Aspose.Pdf.Text.TextFragment("hyperlink test");
textFragment.Hyperlink = new Aspose.Pdf.WebHyperlink("https://www.google.co.uk/");
page.Paragraphs.Add(textFragment);

// password protect the PDF
Aspose.Pdf.Permissions permission = (Aspose.Pdf.Permissions.PrintingQuality | Aspose.Pdf.Permissions.PrintDocument | Aspose.Pdf.Permissions.ModifyTextAnnotations | Aspose.Pdf.Permissions.FillForm | Aspose.Pdf.Permissions.ModifyContent | Aspose.Pdf.Permissions.ExtractContent | Aspose.Pdf.Permissions.AssembleDocument);
doc.Encrypt("pass1", "pass2", permission, Aspose.Pdf.CryptoAlgorithm.RC4x128);

// save the doc
doc.Save("C:\\temp\\PDFHyperlink\\test.pdf");

enter image description here

...单击超链接时收到以下消息:

enter image description here

...如果您点击允许,则不会发生任何事情!

我的密码保护PDF的方式有问题吗?任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

我测试过这个场景,并设法重现上述问题。为了更正,我在问题跟踪系统中将其记录为 PDFNET-41159 。我们将进一步研究这个问题的细节,并让您及时了解更正的状态。请耐心等待解决方案。

我的名字是Nayyer,我是Aspose的开发人员传播者。