Skip to content

Instantly share code, notes, and snippets.

@farhan-raza
Last active June 10, 2022 13:03
Show Gist options
  • Save farhan-raza/81e031e7252bb15fe4b33fbeb86310af to your computer and use it in GitHub Desktop.
Save farhan-raza/81e031e7252bb15fe4b33fbeb86310af to your computer and use it in GitHub Desktop.
Save webpage as PDF in Java | Print web page to PDF
// Load input HTML file from URL
HTMLDocument document = new HTMLDocument("https://www.aspose.com/");
// Initialize PdfSaveOptions class object and set the encryption properties
PdfSaveOptions options = new PdfSaveOptions();
options.setEncryption(new PdfEncryptionInfo("user", "owner", PdfPermissions.PrintDocument, PdfEncryptionAlgorithm.RC4_128));
// Save output PDF file with encryption
Converter.convertHTML(document, options, "URLtoPDF_encrypted.pdf");
// Load input HTML file from URL
HTMLDocument document = new HTMLDocument("https://www.aspose.com");
// Initialize PdfSaveOptions class object
PdfSaveOptions options = new PdfSaveOptions();
// Save webpage as PDF in Java
Converter.convertHTML(document, options, "URLtoPDF.pdf");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment