We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Hyperlinks do not work when exporting from HTML and PDF is encrypted

Hi,
I am trying to export from HTML to PDF and want to encrypt the document. Hyperlinks work fine in the exported PDF if the encryption is NOT used. However, they cannot be clicked if PDF is encrypted.

I need the links to stay intact in encrypted PDF. Can you please tell me how to do that?

@pvalencia,

Please ZIP and upload the following resources here for testing.

  • Input HTML file
  • Aspose generated PDF files (encrypted and non encrypted)
  • Piece of source code to reproduce the same problem on our end

We will then investigate the issue on our end and provide you more information.

Here is the code to reproduce this problem.

public static void test() {
	InputStream is = new ByteArrayInputStream("<html><body><a href='http://aspose.com'>Click here</a></body></html>".getBytes());
	Document doc = new Document(is, new HtmlLoadOptions(""));
	doc.encrypt("password", "password", 0, CryptoAlgorithm.AESx256);
	doc.save("output.pdf");
}

Note that if you comment out the doc.encrypt() line, the output works.

@petarian,

As your query is related to Aspose.PDF for Java API, we are moving this thread in Aspose.PDF forum where you will be guided appropriately.

@petarian

Thank you for sharing details.

We have worked with the data shared by you and have been able to reproduce the issue in our environment. A ticket with ID PDFJAVA-38044 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Can I get an ETA on its fix? This feature is very important to us. In fact, we are only using this library to convert HTML to PDF and you can imagine how important links are in an HTML document.

@petarian

The issue has just been logged in our issue management system and will be scheduled on its due turn which can take some months. We understand your concerns, so we have devised a workaround for you. Please try using it in your environment until logged ticket is investigated and resolved.

InputStream is = new ByteArrayInputStream("<html><body><a href='http://aspose.com'>Click here</a></body></html>".getBytes());
Document doc = new Document(is, new HtmlLoadOptions(""));
doc.save( dataDir + "HTMLencrypted.pdf");

    Document document = new Document ( dataDir + "HTMLencrypted.pdf");
    //Set privileges for the document
    DocumentPrivilege privilege = DocumentPrivilege.getAllowAll();
    document.encrypt("password", "password", privilege, CryptoAlgorithm.AESx256 , false);
document.save( dataDir + "HTMLencrypted.pdf");

Farhan,

Thanks for the workaround code snippet. That worked. Although this will reduce the scalability of the application, it works and I can live with it for the time being.

Having said that, I found another posting with a similar problem in 2016. The ticket ID for that is PDFNET-41153. This tells me the problem has been logged on your end for about two years. Is there an ETA on that?

@petarian

We are glad to know that suggested workaround is working in your environment.

About PDFNET-41153, it has not been scheduled owing to some previously logged and critical tickets. We have raised its priority to next level and will schedule it soon. We appreciate your patience and comprehension in this regard.