Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aspose-com-gists/c6fe5ccefe38a5ec03d983307eb0e850 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/c6fe5ccefe38a5ec03d983307eb0e850 to your computer and use it in GitHub Desktop.
HTML to PDF Conversion in Java
// Create HTML load options
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// Load HTML file
Document doc = new Document("HTML-Document.html", htmloptions);
// Set passwords and encryption PDF document
doc.encrypt("userpassword", "ownerPassword", Permissions.ModifyContent , CryptoAlgorithm.AESx256);
// Save HTML file as PDF
doc.save("HTML-to-PDF.pdf");
// Create and initialize URL
URL oracleURL = new URL("https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html");
// Get web page as input stream
InputStream is = oracleURL.openStream();
// Initialize HTML load options
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// Load stream into Document object
Document pdfDocument = new Document(is, htmloptions);
// Save output as PDF format
pdfDocument.save("HTML-to-PDF.pdf");
// Create HTML load options
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// Load HTML file
Document doc = new Document("HTML-Document.html", htmloptions);
// Convert HTML file to PDF
doc.save("HTML-to-PDF.pdf");
// Create HTML load options
HtmlLoadOptions htmloptions = new HtmlLoadOptions();
// Set conversion to single page PDF
htmloptions.setRenderToSinglePage(true);
// Load HTML file
Document doc = new Document("HTML-Document.html", htmloptions);
// Save HTML file as PDF
doc.save("HTML-to-PDF.pdf");
@BusyInfotech
Copy link

Where to add library in android ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment