You can find detailed information at: Convert HTML to JPG, PNG, TIFF, or BMP Image in Java
Last active
January 14, 2021 20:14
-
-
Save aspose-com-gists/5e71e1be8d062c0f8359bf90d5c71a04 to your computer and use it in GitHub Desktop.
Convert HTML File Webpage or String to Image like JPG, PNG, TIFF, BMP, GIF, etc.
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
// Initialize an HTML document from the html file | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); | |
try { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Bmp); | |
// Convert HTML to BMP | |
com.aspose.html.converters.Converter.convertHTML(document, options, "output.bmp"); | |
} finally { | |
if (document != null) { | |
document.dispose(); | |
} | |
} |
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
// Load input HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); | |
try { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
// Convert HTML to output JPG image | |
com.aspose.html.converters.Converter.convertHTML(document, options, "output.jpg"); | |
} finally { | |
if (document != null) { | |
document.dispose(); | |
} | |
} |
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
// Initialize an HTML document from the html file | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); | |
try { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Png); | |
// Convert HTML to PNG | |
com.aspose.html.converters.Converter.convertHTML(document, options, "output.png"); | |
} finally { | |
if (document != null) { | |
document.dispose(); | |
} | |
} |
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
// Initialize an HTML document from the html file | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(dataDir + "document.html"); | |
try { | |
// Set up the page-size 3000x1000 pixels and change the background color to green | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Tiff); | |
com.aspose.html.rendering.PageSetup pageSetup = new com.aspose.html.rendering.PageSetup(); | |
com.aspose.html.drawing.Page anyPage = new com.aspose.html.drawing.Page(); | |
anyPage.setSize( | |
new com.aspose.html.drawing.Size( | |
com.aspose.html.drawing.Length.fromPixels(3000), | |
com.aspose.html.drawing.Length.fromPixels(1000) | |
) | |
); | |
pageSetup.setAnyPage(anyPage); | |
options.setPageSetup(pageSetup); | |
// Set background color for output image | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getGreen()); | |
// Call the ConvertHTML to convert 'document.html' into tiff image | |
com.aspose.html.converters.Converter.convertHTML(dataDir + "document.html", options, dataDir + "output.tiff"); | |
} finally { | |
if (document != null) { | |
document.dispose(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment