Last active
September 4, 2020 08:33
-
-
Save aspose-com-gists/b2199f957c72708d4d2b0de93bca3098 to your computer and use it in GitHub Desktop.
This Gist contains examples for Aspose.HTML for 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
Aspose.HTML for 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
// Initialize configuration object and set up the page-margins for the document | |
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration(); | |
try { | |
// Get the User Agent service | |
com.aspose.html.services.IUserAgentService userAgent = configuration.getService(com.aspose.html.services.IUserAgentService.class); | |
// Set the style of custom margins and create marks on it | |
userAgent.setUserStyleSheet("@page\n" + | |
"{\n" + | |
" /* Page margins should be not empty in order to write content inside the margin-boxes */\n" + | |
" margin-top: 1cm;\n" + | |
" margin-left: 2cm;\n" + | |
" margin-right: 2cm;\n" + | |
" margin-bottom: 2cm;\n" + | |
" /* Page counter located at the bottom of the page */\n" + | |
" @bottom-right\n" + | |
" {\n" + | |
" -aspose-content: \"\"Page \"\" currentPageNumber() \"\" of \"\" totalPagesNumber();\n" + | |
" color: green;\n" + | |
" }\n" + | |
"\n" + | |
" /* Page title located at the top-center box */\n" + | |
" @top-center\n" + | |
" {\n" + | |
" -aspose-content: \"\"Hello World Document Title!!!\"\";\n" + | |
" vertical-align: bottom;\n" + | |
" color: blue;\n" + | |
" }\n" + | |
"}\n"); | |
// Initialize an HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<div>Hello World!!!</div>", ".", configuration); | |
try { | |
// Initialize an output device | |
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice("output.xps"); | |
try { | |
// Send the document to the output device | |
document.renderTo(device); | |
} finally { | |
if (device != null) { | |
device.dispose(); | |
} | |
} | |
} finally { | |
if (document != null) { | |
document.dispose(); | |
} | |
} | |
} finally { | |
if (configuration != null) { | |
configuration.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
// Create an empty HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); | |
try { | |
// Create a mutation observer instance | |
com.aspose.html.dom.mutations.MutationObserver observer = new com.aspose.html.dom.mutations.MutationObserver( | |
new com.aspose.html.dom.mutations.MutationCallback() { | |
@Override | |
public void invoke( | |
Iterable<com.aspose.html.dom.mutations.MutationRecord> mutations, | |
com.aspose.html.dom.mutations.MutationObserver mutationObserver | |
) { | |
mutations.forEach(mutationRecord -> { | |
mutationRecord.getAddedNodes().forEach(node -> { | |
synchronized (this) { | |
System.out.println("The '" + node + "' node was added to the document."); | |
notifyAll(); | |
} | |
}); | |
}); | |
} | |
}); | |
// configuration of the observer | |
com.aspose.html.dom.mutations.MutationObserverInit config = new com.aspose.html.dom.mutations.MutationObserverInit(); | |
config.setChildList(true); | |
config.setSubtree(true); | |
config.setCharacterData(true); | |
// pass in the target node to observe with the specified configuration | |
observer.observe(document.getBody(), config); | |
// Now, we are going to modify DOM tree to check | |
// Create an paragraph element and append it to the document body | |
com.aspose.html.dom.Element p = document.createElement("p"); | |
document.getBody().appendChild(p); | |
// Create a text and append it to the paragraph | |
com.aspose.html.dom.Text text = document.createTextNode("Hello World"); | |
p.appendChild(text); | |
// Since, mutations are working in the async mode you should wait a bit. | |
// We use synchronized(object) and wait(milliseconds) for this purpose as example. | |
synchronized (this) { | |
wait(5000); | |
} | |
// Later, you can stop observing | |
observer.disconnect(); | |
} 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
// Create an empty HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); | |
try { | |
// Create the Canvas element | |
com.aspose.html.HTMLCanvasElement canvas = (com.aspose.html.HTMLCanvasElement) document.createElement("canvas"); | |
// with a specified size | |
canvas.setWidth(300); | |
canvas.setHeight(150); | |
// and append it to the document body | |
document.getBody().appendChild(canvas); | |
// Get the canvas rendering context to draw | |
com.aspose.html.dom.canvas.ICanvasRenderingContext2D context = (com.aspose.html.dom.canvas.ICanvasRenderingContext2D) canvas.getContext("2d"); | |
// Prepare the gradient brush | |
com.aspose.html.dom.canvas.ICanvasGradient gradient = context.createLinearGradient(0, 0, canvas.getWidth(), 0); | |
gradient.addColorStop(0, "magenta"); | |
gradient.addColorStop(0.5, "blue"); | |
gradient.addColorStop(1.0, "red"); | |
// Assign brush to the content | |
context.setFillStyle(gradient); | |
context.setStrokeStyle(gradient); | |
// Write the Text | |
context.fillText("Hello World!", 10, 90, 500d); | |
// Fill the Rectangle | |
context.fillRect(0, 95, 300, 20); | |
// Create the PDF output device | |
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice("canvas.output.2.pdf"); | |
try { | |
// Render HTML5 Canvas to PDF | |
document.renderTo(device); | |
} finally { | |
if (device != null) { | |
device.dispose(); | |
} | |
} | |
} 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
// Prepare a document with HTML5 Canvas inside and save it to the file 'document.html' | |
String code = "< canvas id = myCanvas width = '200' height = '100' style = 'border:1px solid #d3d3d3;' ></canvas >\n" + | |
"<script >\n" + | |
" var c = document.getElementById('myCanvas');\n" + | |
" var context = c.getContext('2d');\n" + | |
" context.font = '20px Arial';\n" + | |
" context.fillStyle = 'red';\n" + | |
" context.fillText('Hello World', 40, 50);\n" + | |
"</script >\n"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Initialize an HTML document from the html file | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); | |
try { | |
// Convert HTML to PDF | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
new com.aspose.html.saving.PdfSaveOptions(), | |
"output.pdf" | |
); | |
} 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 instance of HTML document from 'https://httpbin.org/forms/post' url | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("https://httpbin.org/forms/post"); | |
try { | |
// Create an instance of Form Editor | |
com.aspose.html.forms.FormEditor editor = com.aspose.html.forms.FormEditor.create(document, 0); | |
try { | |
// You can fill the data up using direct access to the input elements, like this: | |
editor.get_Item("custname").setValue("John Doe"); | |
document.save("out.html"); | |
// or this: | |
com.aspose.html.forms.TextAreaElement comments = editor.getElement(com.aspose.html.forms.TextAreaElement.class, "comments"); | |
comments.setValue("MORE CHEESE PLEASE!"); | |
// or even by performing a bulk operation, like this one: | |
java.util.Map<String, String> map = new java.util.HashMap<>(); | |
map.put("custemail", "john.doe@gmail.com"); | |
map.put("custtel", "+1202-555-0290"); | |
editor.fill(map); | |
// Create an instance of form submitter | |
com.aspose.html.forms.FormSubmitter submitter = new com.aspose.html.forms.FormSubmitter(editor); | |
try { | |
// Submit the form data to the remote server. | |
// If you need you can specify user-credentials and timeout for the request, etc. | |
com.aspose.html.forms.SubmissionResult result = submitter.submit(); | |
// Check the status of the result object | |
if (result.isSuccess()) { | |
// Check whether the result is in json format | |
if (result.getResponseMessage().getHeaders().getContentType().getMediaType().equals("application/json")) { | |
// Dump result data to the console | |
System.out.println(result.getContent().readAsString()); | |
} else { | |
// Load the result data as an HTML document | |
com.aspose.html.dom.Document resultDocument = result.loadDocument(); | |
try { | |
// Inspect HTML document here. | |
System.out.println(resultDocument.getDocumentElement().getTextContent()); | |
} finally { | |
if (resultDocument != null) { | |
resultDocument.dispose(); | |
} | |
} | |
} | |
} | |
} finally { | |
if (submitter != null) { | |
submitter.dispose(); | |
} | |
} | |
} finally { | |
if (editor != null) { | |
editor.dispose(); | |
} | |
} | |
} 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
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Initialize an HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<span>Hello World!!</span>", "."); | |
try { | |
// Convert HTML to Image by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg), | |
streamProvider.lStream | |
); | |
// Get access to the memory stream that contains the result data | |
java.io.InputStream inputStream = streamProvider.lStream.stream().findFirst().orElse(null); | |
// Flush the result data to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("output.jpg")) { | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} 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
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("FirstFile.html")) { | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("FirstFileOut.html")) { | |
byte[] bytes = new byte[fileInputStream.available()]; | |
fileInputStream.read(bytes); | |
fileOutputStream.write(bytes); | |
String style = "<style>\n" + | |
".st\n" + | |
"{\n" + | |
"color:\n" + | |
"green;\n" + | |
"}\n" + | |
"</style >\n" + | |
"<div id = id1 > Aspose.Html rendering Text in Black Color</div >\n" + | |
"<div id = id2 class='' st '' > Aspose.Html rendering Text in Green Color</div >\n" + | |
"<div id = id3 class='' st '' style = 'color: blue;' > Aspose.Html rendering Text in Blue Color</div >\n" + | |
"<div id = id3 class='' st '' style = 'color: red;' ><font face = 'Arial' > Aspose.Html rendering Text in Red\n" + | |
"Color</font ></div >\n"; | |
fileOutputStream.write(style.getBytes(java.nio.charset.StandardCharsets.UTF_8)); | |
} | |
String pdf_output; | |
// Create HtmlRenderer object | |
com.aspose.html.rendering.HtmlRenderer pdf_renderer = new com.aspose.html.rendering.HtmlRenderer(); | |
try { | |
// Create HtmlDocument instnace while passing path of already created HTML file | |
com.aspose.html.HTMLDocument html_document = new com.aspose.html.HTMLDocument("FirstFileOut.html"); | |
try { | |
// Set the page size less than document min-width. The content in the resulting file will be cropped becuase of element with width: 200px | |
com.aspose.html.rendering.pdf.PdfRenderingOptions pdf_options = | |
new com.aspose.html.rendering.pdf.PdfRenderingOptions(); | |
com.aspose.html.rendering.PageSetup pageSetup = new com.aspose.html.rendering.PageSetup(); | |
pageSetup.setAnyPage(new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100))); | |
pageSetup.setAdjustToWidestPage(false); | |
pdf_options.setPageSetup(pageSetup); | |
pdf_output = "not-adjusted-to-widest-page_out.pdf"; | |
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(pdf_options, pdf_output); | |
try { | |
// Render the output | |
pdf_renderer.render(device, html_document); | |
} finally { | |
if (device != null) { | |
device.dispose(); | |
} | |
} | |
// Set the page size less than document min-width and enable AdjustToWidestPage option. The page size of the resulting file will be changed according to content width | |
pdf_options = new com.aspose.html.rendering.pdf.PdfRenderingOptions(); | |
pageSetup = new com.aspose.html.rendering.PageSetup(); | |
pageSetup.setAnyPage(new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100))); | |
pageSetup.setAdjustToWidestPage(true); | |
pdf_options.setPageSetup(pageSetup); | |
pdf_output = "adjusted-to-widest-page_out.pdf"; | |
device = new com.aspose.html.rendering.pdf.PdfDevice(pdf_options, pdf_output); | |
try { | |
// Render the output | |
pdf_renderer.render(device, html_document); | |
} finally { | |
if (device != null) { | |
device.dispose(); | |
} | |
} | |
} finally { | |
if (html_document != null) { | |
html_document.dispose(); | |
} | |
} | |
} finally { | |
if (pdf_renderer != null) { | |
pdf_renderer.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
// Set input file name. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("FirstFile.html")) { | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("FirstFileOut.html")) { | |
byte[] bytes = new byte[fileInputStream.available()]; | |
fileInputStream.read(bytes); | |
fileOutputStream.write(bytes); | |
String style = "<style>\n" + | |
".st\n" + | |
"{\n" + | |
"color: green;\n" + | |
"}\n" + | |
"</style>\n" + | |
"<div id=id1>Aspose.Html rendering Text in Black Color</div>\n" + | |
"<div id=id2 class=''st''>Aspose.Html rendering Text in Green Color</div>\n" + | |
"<div id=id3 class=''st'' style='color: blue;'>Aspose.Html rendering Text in Blue Color</div>\n" + | |
"<div id=id3 class=''st'' style='color: red;'>Aspose.Html rendering Text in Red Color</div>\n"; | |
fileOutputStream.write(style.getBytes(java.nio.charset.StandardCharsets.UTF_8)); | |
} | |
// Create HtmlRenderer object | |
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer(); | |
try { | |
// Create HtmlDocument instnace while passing path of already created HTML file | |
com.aspose.html.HTMLDocument html_document = new com.aspose.html.HTMLDocument("FirstFileOut.html"); | |
try { | |
// Set the page size less than document min-width. The content in the resulting file will be cropped becuase of element with width: 200px | |
com.aspose.html.rendering.xps.XpsRenderingOptions xps_options = new com.aspose.html.rendering.xps.XpsRenderingOptions(); | |
com.aspose.html.drawing.Page page = new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100)); | |
com.aspose.html.rendering.PageSetup pageSetup = new com.aspose.html.rendering.PageSetup(); | |
pageSetup.setAnyPage(page); | |
pageSetup.setAdjustToWidestPage(false); | |
xps_options.setPageSetup(pageSetup); | |
String output = "not-adjusted-to-widest-page_out.1.xps"; | |
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice(xps_options, output); | |
try { | |
// Render the output | |
renderer.render(device, html_document); | |
} finally { | |
if (device != null) { | |
device.dispose(); | |
} | |
} | |
// Set the page size less than document min-width and enable AdjustToWidestPage option | |
// The page size of the resulting file will be changed according to content width | |
xps_options = new com.aspose.html.rendering.xps.XpsRenderingOptions(); | |
page = new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100)); | |
pageSetup = new com.aspose.html.rendering.PageSetup(); | |
pageSetup.setAnyPage(page); | |
pageSetup.setAdjustToWidestPage(true); | |
xps_options.setPageSetup(pageSetup); | |
output = "not-adjusted-to-widest-page_out.2.xps"; | |
device = new com.aspose.html.rendering.xps.XpsDevice(xps_options, output); | |
try { | |
// Render the output | |
renderer.render(device, html_document); | |
} finally { | |
if (device != null) { | |
device.dispose(); | |
} | |
} | |
} finally { | |
if (html_document != null) { | |
html_document.dispose(); | |
} | |
} | |
} finally { | |
if (renderer != null) { | |
renderer.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
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("canvas.html"); | |
try { | |
// Create an instance of HTML renderer and XPS output device | |
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer(); | |
try { | |
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice("canvas.output.pdf"); | |
try { | |
// Render the document to the specified device | |
renderer.render(device, document); | |
} finally { | |
if (device != null) { | |
device.dispose(); | |
} | |
} | |
} finally { | |
if (renderer != null) { | |
renderer.dispose(); | |
} | |
} | |
} 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
// Source EPUB document | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
// Output file path | |
String outputFile = "EPUBtoImageOutput.jpeg"; | |
// Convert SVG to Image | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
outputFile | |
); | |
} |
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
// Source EPUB document | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize pdfSaveOptions | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
options.setJpegQuality(100); | |
// Output file path | |
String outputFile = "EPUBtoPDF_Output.pdf"; | |
// Convert EPUB to PDF | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
outputFile | |
); | |
} |
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
// Source EPUB document | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize XpsSaveOptions | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getCyan()); | |
// Output file path | |
String outputFile = "EPUBtoXPS_Output.xps"; | |
// Convert EPUB to XPS | |
com.aspose.html.converters.Converter.convertEPUB(fileInputStream, options, outputFile); | |
} |
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
// Source HTML document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Bmp); | |
// Output file path | |
String outputFile = "HTMLtoBMP_Output.bmp"; | |
// Convert HTML to BMP | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); |
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
// Source HTML document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Gif); | |
// Output file path | |
String outputFile = "HTMLtoGIF_Output.gif"; | |
// Convert HTML to GIF | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); |
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
// Source HTML document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
// Output file path | |
String outputFile = "HTMLtoJPEG_Output.jpeg"; | |
// Convert HTML to JPEG | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); |
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
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<p>my first paragraph</p>", Resources.outputDirectory()); | |
try { | |
// Create MarkdownSaveOptions object | |
com.aspose.html.saving.MarkdownSaveOptions options = new com.aspose.html.saving.MarkdownSaveOptions(); | |
// Set the rules: only <a>, <img> and <p> elements will be converted to markdown. | |
options.setFeatures(com.aspose.html.saving.MarkdownFeatures.Link | com.aspose.html.saving.MarkdownFeatures.Image | com.aspose.html.saving.MarkdownFeatures.AutomaticParagraph); | |
document.save("output.rules.html.to.md", options); | |
} 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
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument( | |
"<p>my first paragraph</p>" + | |
"<p>my second paragraph</p>", | |
Resources.outputDirectory() | |
); | |
try { | |
document.save("Markdown-to-html.out.md", com.aspose.html.saving.HTMLSaveFormat.Markdown); | |
} 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
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<p>my first paragraph</p>", Resources.outputDirectory()); | |
try { | |
// Save to markdown by using default for the GIT formatting model | |
document.save("Markdown-with-options.out.md", com.aspose.html.saving.MarkdownSaveOptions.getGit()); | |
} 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
// Source HTML Document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize MHTMLSaveOptions | |
com.aspose.html.saving.MHTMLSaveOptions options = new com.aspose.html.saving.MHTMLSaveOptions(); | |
// Set the resource handling rules | |
options.getResourceHandlingOptions().setMaxHandlingDepth(1); | |
// Output file path | |
String outputPDF = "HTMLtoMHTML_Output.mht"; | |
// Convert HTML to MHTML | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputPDF); |
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
// Source HTML document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize PdfSaveOptions | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
options.setJpegQuality(100); | |
// Output file path | |
String outputPDF = "HTMLtoPDF_Output.pdf"; | |
// Convert HTML to PDF | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputPDF); |
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
// Source HTML document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Png); | |
// Output file path | |
String outputFile = "HTMLtoPNG_Output.png"; | |
// Convert HTML to PNG | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); |
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
// Source HTML document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Tiff); | |
// Output file path | |
String outputFile = "HTMLtoPNG_Output.tif"; | |
// Convert HTML to TIFF | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); |
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
// Source HTML document | |
com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument("input.html"); | |
// Initialize XpsSaveOptions | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getCyan()); | |
// Output file path | |
String outputFile = "output.html.to.xps"; | |
// Convert HTML to XPS | |
com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); |
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
// Convert markdown to HTML | |
com.aspose.html.converters.Converter.convertMarkdown( | |
"input.md", | |
"Markdown-to-HTML.out.html" | |
); |
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
// Source MHTML document | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
// Output file path | |
String outputFile = "MHTMLtoImage.jpeg"; | |
// Convert SVG to Image | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
options, | |
outputFile | |
); | |
} |
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
// Source MHTML document | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize pdfSaveOptions | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
options.setJpegQuality(100); | |
// Output file path | |
String outputFile = "MHTMLtoPDF_Output.pdf"; | |
// Convert MHTML to PDF | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
options, | |
outputFile | |
); | |
} |
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
// Source EPUUB document | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize XpsSaveOptions | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getCyan()); | |
// Output file path | |
String outputFile = "MHTMLtoXPS_Output.xps"; | |
// Convert MHTML to XPS | |
com.aspose.html.converters.Converter.convertMHTML(fileInputStream, options, outputFile); | |
} |
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
// Source SVG document | |
com.aspose.html.dom.svg.SVGDocument svgDocument = new com.aspose.html.dom.svg.SVGDocument("input.svg"); | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
// Output file path | |
String outputFile = "SVGtoImage_Output.jpeg"; | |
// Convert SVG to Image | |
com.aspose.html.converters.Converter.convertSVG(svgDocument, options, outputFile); |
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
// Source SVG document | |
com.aspose.html.dom.svg.SVGDocument svgDocument = new com.aspose.html.dom.svg.SVGDocument("input.svg"); | |
// Initialize pdfSaveOptions | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
options.setJpegQuality(100); | |
// Output file path | |
String outputFile = "SVGtoPDF_Output.pdf"; | |
// Convert SVG to PDF | |
com.aspose.html.converters.Converter.convertSVG(svgDocument, options, outputFile); |
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
// Source SVG document | |
com.aspose.html.dom.svg.SVGDocument svgDocument = new com.aspose.html.dom.svg.SVGDocument("input.svg"); | |
// Initialize XpsSaveOptions | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getCyan()); | |
// Output file path | |
String outputFile = "SVGtoXPS_Output.xps"; | |
// Convert SVG to XPS | |
com.aspose.html.converters.Converter.convertSVG(svgDocument, options, outputFile); |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Bmp); | |
// Call the ConvertEPUB method to convert the EPUB file to BMP. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.bmp" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Gif); | |
// Call the ConvertEPUB method to convert the EPUB file to GIF. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.gif" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions( | |
com.aspose.html.rendering.image.ImageFormat.Jpeg | |
); | |
// Call the ConvertEPUB method to convert the EPUB file to JPG. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.jpg" | |
); | |
} |
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
// Opens an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Png); | |
// Call the ConvertEPUB method to convert the EPUB file to PNG. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.png" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Tiff); | |
// Call the ConvertEPUB method to convert the EPUB file to TIFF. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.tiff" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Convert EPUB to Image by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg), | |
streamProvider.lStream | |
); | |
// Get access to the memory streams that contain the resulted data | |
int size = streamProvider.lStream.size(); | |
for (int i = 0; i < size; i++) { | |
java.io.InputStream inputStream = streamProvider.lStream.get(i); | |
// Flush the page to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("page_{" + (i + 1) + "}.jpg")) { | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} | |
} | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Initailize the ImageSaveOptions with a custom page-size and a background-color. | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
com.aspose.html.rendering.PageSetup pageSetup = new com.aspose.html.rendering.PageSetup(); | |
com.aspose.html.drawing.Page anyPage = new com.aspose.html.drawing.Page(); | |
com.aspose.html.drawing.Size size = new com.aspose.html.drawing.Size( | |
com.aspose.html.drawing.Length.fromPixels(3000), | |
com.aspose.html.drawing.Length.fromPixels(1000) | |
); | |
anyPage.setSize(size); | |
pageSetup.setAnyPage(anyPage); | |
options.setPageSetup(pageSetup); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getAliceBlue()); | |
// Call the ConvertEPUB method to convert the EPUB file to JPG. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.jpg" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Call the ConvertEPUB method to convert the EPUB file to image. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg), | |
"output.jpg" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Create an instance of PdfSaveOptions. | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Convert EPUB to PDF by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
new com.aspose.html.saving.PdfSaveOptions(), | |
streamProvider.lStream | |
); | |
// Get access to the memory stream that contains the resulted data | |
java.io.InputStream inputStream = streamProvider.lStream.stream().findFirst().get(); | |
// Flush the result data to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("output.pdf")) { | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Create an instance of the PdfSaveOptions with a custom page-size and a background-color. | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
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); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getAliceBlue()); | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Call the ConvertEPUB method to convert the EPUB to PDF. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
new com.aspose.html.saving.PdfSaveOptions(), | |
"output.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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Create an instance of XpsSaveOptions. | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
// Call the ConvertEPUB method to convert the EPUB to XPS. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.xps" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Convert EPUB to XPS by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
new com.aspose.html.saving.XpsSaveOptions(), | |
streamProvider.lStream | |
); | |
// Get access to the memory stream that contains the resulted data | |
java.io.InputStream inputStream = streamProvider.lStream.stream().findFirst().get(); | |
// Flush the result data to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("output.xps")) { | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Create an instance of the XpsSaveOptions with a custom page-size and a background-color. | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
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); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getAliceBlue()); | |
// Call the ConvertEPUB method to convert the EPUB to XPS. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
options, | |
"output.xps" | |
); | |
} |
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
// Open an existing EPUB file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("input.epub")) { | |
// Call the ConvertEPUB method to convert the EPUB to XPS. | |
com.aspose.html.converters.Converter.convertEPUB( | |
fileInputStream, | |
new com.aspose.html.saving.XpsSaveOptions(), | |
"output.xps" | |
); | |
} |
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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// 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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// 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.Gif); | |
// Convert HTML to GIF | |
com.aspose.html.converters.Converter.convertHTML(document, options, "output.gif"); | |
} 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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// 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.Jpeg); | |
// Convert HTML to JPG | |
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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// 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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// 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.Tiff); | |
// Convert HTML to TIFF | |
com.aspose.html.converters.Converter.convertHTML(document, options, "output.tiff"); | |
} 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
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Initialize an HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<span>Hello</span> <span>World!!</span>", "."); | |
try { | |
// Convert HTML to Image by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg), | |
streamProvider.lStream | |
); | |
// Get access to the memory stream that contains the result data | |
java.io.InputStream inputStream = streamProvider.lStream.stream().findFirst().get(); | |
// Flush the result data to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("output.jpg")) { | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} 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
// Prepare an HTML code and save it to the file | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// 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.Jpeg); | |
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); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getGreen()); | |
// Call the ConvertHTML to convert 'document.html' into jpeg image | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
options, | |
"output.jpg" | |
); |
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
// Invoke the ConvertHTML method to convert the HTML code to image. | |
com.aspose.html.converters.Converter.convertHTML( | |
"<span>Hello</span> <span>World!!</span>", | |
".", | |
new com.aspose.html.saving.ImageSaveOptions( | |
com.aspose.html.rendering.image.ImageFormat.Jpeg | |
), | |
"output.jpg" | |
); |
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
// Prepare an HTML code and save it to the file. | |
String code = "<h1>Header 1</h1>\n" + | |
"<h2>Header 2</h2>\n" + | |
"<p>Hello World!!</p>\n"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Call ConvertHTML method to convert HTML to Markdown. | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
com.aspose.html.saving.MarkdownSaveOptions.getGit(), | |
"output.md" | |
); |
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
// Prepare an HTML code and save it to the file. | |
String code = "text<div markdown='inline'><code>text</code></div>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Call ConvertHTML method to convert HTML to Markdown. | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
new com.aspose.html.saving.MarkdownSaveOptions(), | |
"output.md" | |
); | |
// Output file will contain: text\r\n<div markdown="inline"><code>text</code></div> |
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
// Prepare an HTML code and save it to the file. | |
String code = "<h1>Header 1</h1>\n" + | |
"<h2>Header 2</h2>\n" + | |
"<p>Hello World!!</p>\n" + | |
"<a href='aspose.com'>aspose</a>\n"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Create an instance of SaveOptions and set up the rule: | |
// - only <a> and <p> elements will be converted to markdown. | |
com.aspose.html.saving.MarkdownSaveOptions options = new com.aspose.html.saving.MarkdownSaveOptions(); | |
options.setFeatures( | |
com.aspose.html.saving.MarkdownFeatures.Link | |
| | |
com.aspose.html.saving.MarkdownFeatures.AutomaticParagraph | |
); | |
// Call the ConvertHTML method to convert the HTML to Markdown. | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
options, | |
"output.md" | |
); |
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
// Prepare an HTML code and save it to the file. | |
String code = "<h1>Header 1</h1>\n" + | |
"<h2>Header 2</h2>\n" + | |
"<p>Hello World!!</p>\n"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Call ConvertHTML method to convert HTML to Markdown. | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
new com.aspose.html.saving.MarkdownSaveOptions(), | |
"output.md" | |
); |
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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Initialize an HTML document from the file | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); | |
try { | |
// Initialize MHTMLSaveOptions | |
com.aspose.html.saving.MHTMLSaveOptions options = new com.aspose.html.saving.MHTMLSaveOptions(); | |
// Convert HTML to MHT | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
options, | |
"output.mht" | |
); | |
} 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
// Prepare an HTML code with a link to another file and save it to the file as 'document.html' | |
String code = "<span>Hello World!!</span>\n" + | |
"<a href='document2.html'>click</a>\n"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Prepare an HTML code and save it to the file as 'document2.html' | |
code = "<span>Hello World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document2.html")) { | |
fileWriter.write(code); | |
} | |
// Change the value of the resource linking depth to 1 in order to convert document with directly linked resources. | |
com.aspose.html.saving.MHTMLSaveOptions options = new com.aspose.html.saving.MHTMLSaveOptions(); | |
options.getResourceHandlingOptions().setMaxHandlingDepth(1); | |
// Convert HTML to MHT | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
options, | |
"output.mht" | |
); |
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
// Invoke the ConvertHTML method to convert the HTML to MHT. | |
com.aspose.html.converters.Converter.convertHTML( | |
"<span>Hello World!!</span>", | |
".", | |
new com.aspose.html.saving.MHTMLSaveOptions(), | |
"output.mht" | |
); |
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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Initialize an HTML document from the file | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); | |
try { | |
// Initialize PdfSaveOptions | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
// Convert HTML to PDF | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
options, | |
"output.pdf" | |
); | |
} 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
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Initialize an HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<span>Hello World!!</span>", "."); | |
try { | |
// Convert HTML to PDF by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
new com.aspose.html.saving.PdfSaveOptions(), | |
streamProvider.lStream | |
); | |
// Get access to the memory stream that contains the result data | |
java.io.InputStream inputStream = streamProvider.lStream.stream().findFirst().get(); | |
// Flush the result data to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("output.pdf")) { | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} 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
// Prepare an HTML code and save it to the file | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Set A5 as a page-size and change the background color to green | |
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); | |
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.fromInches(8.3f), | |
com.aspose.html.drawing.Length.fromInches(5.8f) | |
) | |
); | |
pageSetup.setAnyPage(anyPage); | |
options.setPageSetup(pageSetup); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getGreen()); | |
// Convert HTML document to PDF | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
options, | |
"output.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
// Invoke the ConvertHTML method to convert the HTML to PDF. | |
com.aspose.html.converters.Converter.convertHTML( | |
"<span>Hello World!!</span>", | |
".", | |
new com.aspose.html.saving.PdfSaveOptions(), | |
"output.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
// Prepare an HTML code and save it to the file. | |
String code = "<span>Hello World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Initialize an HTML document from the file | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); | |
try { | |
// Initialize XpsSaveOptions | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
// Convert HTML to XPS | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
options, | |
"output.xps" | |
); | |
} 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
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Initialize an HTML document | |
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<span>Hello World!!</span>", "."); | |
try { | |
// Convert HTML to XPS by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
new com.aspose.html.saving.XpsSaveOptions(), | |
streamProvider.lStream | |
); | |
// Get access to the memory stream that contains the result data | |
java.io.InputStream inputStream = streamProvider.lStream.stream().findFirst().get(); | |
// Flush the result data to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("output.xps")) { | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} 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
// Prepare an HTML code and save it to the file | |
String code = "<span>Hello</span> <span>World!!</span>"; | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { | |
fileWriter.write(code); | |
} | |
// Set A5 as a page-size and change the background color to green | |
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions(); | |
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.fromInches(8.3f), | |
com.aspose.html.drawing.Length.fromInches(5.8f) | |
) | |
); | |
pageSetup.setAnyPage(anyPage); | |
options.setPageSetup(pageSetup); | |
options.setBackgroundColor(com.aspose.html.drawing.Color.getGreen()); | |
// Convert HTML document to XPS | |
com.aspose.html.converters.Converter.convertHTML( | |
"document.html", | |
options, | |
"output.xps" | |
); |
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
// Invoke the ConvertHTML method to convert the HTML to XPS. | |
com.aspose.html.converters.Converter.convertHTML( | |
"<span>Hello World!!</span>", | |
".", | |
new com.aspose.html.saving.XpsSaveOptions(), | |
"output.xps" | |
); |
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
// Prepare a simple Markdown example | |
String code = "### Hello World\n" + | |
"\r\n\n" + | |
"\n" + | |
"[visit applications](https://products.aspose.app/html/family)\n"; | |
// Create a Markdown file | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.md")) { | |
fileWriter.write(code); | |
} | |
// Convert Markdown to HTML document | |
com.aspose.html.HTMLDocument document = com.aspose.html.converters.Converter.convertMarkdown("document.md"); | |
try { | |
// Convert HTML document to PNG image file format | |
com.aspose.html.converters.Converter.convertHTML( | |
document, | |
new com.aspose.html.saving.ImageSaveOptions( | |
com.aspose.html.rendering.image.ImageFormat.Png | |
), | |
"output_md.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
// Prepare a simple Markdown example | |
String code = "### Hello World\n" + | |
"\r\n\n" + | |
"\n" + | |
"[visit applications](https://products.aspose.app/html/family)\n"; | |
// Create a Markdown file | |
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.md")) { | |
fileWriter.write(code); | |
} | |
// Convert Markdown to HTML document | |
com.aspose.html.converters.Converter.convertMarkdown( | |
"document.md", | |
"document.html" | |
); |
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
// Open an existing MHTML file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Bmp); | |
// Call the ConvertMHTML method to convert the MHTML file to BMP. | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
options, | |
"output.bmp" | |
); | |
} |
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
// Open an existing MHTML file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Gif); | |
// Call the ConvertMHTML method to convert the MHTML file to GIF. | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
options, | |
"output.gif" | |
); | |
} |
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
// Open an existing MHTML file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
// Call the ConvertMHTML method to convert the MHTML file to JPG. | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
options, | |
"output.jpg" | |
); | |
} |
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
// Open an existing MHTML file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Png); | |
// Call the ConvertMHTML method to convert the MHTML file to PNG. | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
options, | |
"output.png" | |
); | |
} |
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
// Open an existing MHTML file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initialize ImageSaveOptions | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Tiff); | |
// Call the ConvertMHTML method to convert the MHTML file to TIFF. | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
options, | |
"output.tiff" | |
); | |
} |
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
// Open an existing MHTML file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Create an instance of MemoryStreamProvider | |
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) { | |
// Convert MHTML to Image by using the MemoryStreamProvider | |
com.aspose.html.converters.Converter.convertMHTML( | |
fileInputStream, | |
new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg), | |
streamProvider.lStream | |
); | |
// Get access to the memory streams that contain the resulted data | |
int bound = streamProvider.lStream.size(); | |
for (int value = 0; value < bound; value++) { | |
// Flush the page to the output file | |
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream("page_{" + (value + 1) + "}.jpg")) { | |
java.io.InputStream inputStream = streamProvider.lStream.get(value); | |
byte[] buffer = new byte[inputStream.available()]; | |
inputStream.read(buffer); | |
fileOutputStream.write(buffer); | |
} | |
} | |
} | |
} |
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
// Open an existing MHTML file for reading. | |
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) { | |
// Initailize the ImageSaveOptions with a custom page-size and a background-color. | |
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg); | |
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), | |