I’m hoping someone can help me with a problem I’m having with generating a password protected PDF with hyperlinks with the Aspose.Pdf library. The problem is that the password protection seems to screw the hyperlink up …
The following code works fine (without any password protection):
<p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; line-height: 19.5px; background-color: rgb(255, 255, 255);”>The PDF that is generated is fine with the hyperlink successfully opening a browser and navigating to google<p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; line-height: 19.5px; background-color: rgb(255, 255, 255);”>// 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”);

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”);<p style=“margin: 0px 0px 1em; padding: 0px; border: 0px; font-size: 15px; clear: both; color: rgb(36, 39, 41); font-family: Arial, “Helvetica Neue”, Helvetica, sans-serif; line-height: 19.5px; background-color: rgb(255, 255, 255);”>
