Last active
August 3, 2023 23:44
-
-
Save aspose-com-gists/c6fe5ccefe38a5ec03d983307eb0e850 to your computer and use it in GitHub Desktop.
HTML to PDF Conversion in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where to add library in android ?