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);”><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);”>However, if you uncomment the lines that password protect the PDF, the hyperlinks are screwed up<pre class=“lang-cs prettyprint prettyprinted” style=“margin-top: 0px; margin-bottom: 1em; padding: 5px; border: 0px; font-size: 13px; width: auto; max-height: 600px; overflow: auto; font-family: Consolas, Menlo, Monaco, “Lucida Console”, “Liberation Mono”, “DejaVu Sans Mono”, “Bitstream Vera Sans Mono”, “Courier New”, monospace, sans-serif; color: rgb(57, 51, 24); word-wrap: normal; background-color: rgb(239, 240, 241);”><code style=“margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, “Lucida Console”, “Liberation Mono”, “DejaVu Sans Mono”, “Bitstream Vera Sans Mono”, “Courier New”, monospace, sans-serif; white-space: inherit;”>// create new PDF doc with hyperlink in// 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);”>