簡體   English   中英

使用Aspose.Pdf庫生成帶有超鏈接的受密碼保護的PDF

[英]Generating a password protected PDF with hyperlinks with the Aspose.Pdf library

我希望有人可以通過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很好,超鏈接成功打開了瀏覽器並導航到google

在此處輸入圖片說明

但是,如果取消注釋密碼保護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的方式是否存在問題? 任何幫助,將不勝感激。

我已經測試了方案,並設法重現了上述問題。 為了更正,我在問題跟蹤系統中將其記錄為PDFNET-41159 我們將進一步調查該問題的詳細信息,並讓您及時了解更正的狀態。 請耐心等待解決。

我叫Nayyer,我是Aspose的開發人員。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM