Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active September 4, 2020 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/b2199f957c72708d4d2b0de93bca3098 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/b2199f957c72708d4d2b0de93bca3098 to your computer and use it in GitHub Desktop.
This Gist contains examples for Aspose.HTML for Java.
Aspose.HTML for Java
// 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();
}
}
// 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();
}
}
// 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();
}
}
// 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();
}
}
// 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();
}
}
// 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();
}
}
}
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();
}
}
}
// 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();
}
}
}
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();
}
}
// 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
);
}
// 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
);
}
// 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);
}
// 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);
// 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);
// 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);
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();
}
}
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();
}
}
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();
}
}
// 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);
// 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);
// 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);
// 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);
// 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);
// Convert markdown to HTML
com.aspose.html.converters.Converter.convertMarkdown(
"input.md",
"Markdown-to-HTML.out.html"
);
// 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
);
}
// 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
);
}
// 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);
}
// 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);
// 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);
// 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);
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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);
}
}
}
}
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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);
}
}
}
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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);
}
}
}
// 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"
);
}
// 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"
);
}
// 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();
}
}
// 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();
}
}
// 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();
}
}
// 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();
}
}
// 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();
}
}
// 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();
}
}
}
// 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"
);
// 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"
);
// 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"
);
// 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>
// 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"
);
// 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"
);
// 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();
}
}
// 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"
);
// 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"
);
// 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();
}
}
// 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();
}
}
}
// 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"
);
// 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"
);
// 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();
}
}
// 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();
}
}
}
// 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"
);
// 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"
);
// 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();
}
}
// 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"
);
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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"
);
}
// 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);
}
}
}
}
// 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),
com.aspose.html.drawing.Length.fromPixels(1000)
)
);
pageSetup.setAnyPage(anyPage);
options.setPageSetup(pageSetup);
options.setBackgroundColor(com.aspose.html.drawing.Color.getGreen());
// Call the ConvertMHTML method to convert the MHTML file to JPG.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
options,
"output.jpg"
);
}
// Open an existing MHTML file for reading.
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) {
// Call the ConvertMHTML method to convert the MHTML file to image.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
new com.aspose.html.saving.ImageSaveOptions(
com.aspose.html.rendering.image.ImageFormat.Jpeg),
"output.jpg"
);
}
// Open an existing MHTML file for reading.
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) {
// Create an instance of PdfSaveOptions.
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions();
// Call the ConvertMHTML method to convert the MHTML to PDF.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
options,
"output.pdf"
);
}
// 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 PDF by using the MemoryStreamProvider
com.aspose.html.converters.Converter.convertMHTML(
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);
}
}
}
// Open an existing MHTML file for reading.
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) {
// 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 ConvertMHTML method to convert the MHTML to PDF.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
options,
"output.pdf"
);
}
// Open an existing MHTML file for reading.
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) {
// Call the ConvertMHTML method to convert the MHTML to PDF.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
new com.aspose.html.saving.PdfSaveOptions(),
"output.pdf"
);
}
// Open an existing MHTML file for reading.
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) {
// Create an instance of XpsSaveOptions.
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions();
// Call the ConvertMHTML method to convert the MHTML to XPS.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
options,
"output.xps"
);
}
// 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 XPS by using the MemoryStreamProvider
com.aspose.html.converters.Converter.convertMHTML(
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);
}
}
}
// Open an existing MHTML file for reading.
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) {
// 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 ConvertMHTML method to convert the MHTML to XPS.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
options,
"output.xps"
);
}
// Open an existing MHTML file for reading.
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("sample.mht")) {
// Call the ConvertMHTML method to convert the MHTML to XPS.
com.aspose.html.converters.Converter.convertMHTML(
fileInputStream,
new com.aspose.html.saving.XpsSaveOptions(),
"output.xps"
);
}
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Initialize an SVG document from the svg file.
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("document.svg");
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.convertSVG(
document,
options,
"output.bmp"
);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Initialize an SVG document from the svg file.
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("document.svg");
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.convertSVG(
document,
options,
"output.gif"
);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Initialize an SVG document from the svg file.
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("document.svg");
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.convertSVG(
document,
options,
"output.jpg"
);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Initialize an SVG document from the svg file.
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("document.svg");
try {
// Initialize ImageSaveOptions
com.aspose.html.saving.ImageSaveOptions options = new com.aspose.html.saving.ImageSaveOptions(
com.aspose.html.rendering.image.ImageFormat.Png
);
// Convert SVG to PNG
com.aspose.html.converters.Converter.convertSVG(
document,
options,
"output.png"
);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Initialize an SVG document from the svg file.
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("document.svg");
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.convertSVG(
document,
options,
"output.tiff"
);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an SVG code and save it to the file
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
// Create an instance of MemoryStreamProvider
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) {
// Initialize the SVG document
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument(code, ".");
try {
// Convert SVG to Image by using the MemoryStreamProvider
com.aspose.html.converters.Converter.convertSVG(
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();
}
}
}
// Prepare an SVG code and save it to the file
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Set up the page-size to 3000x1000 pixels and change the 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),
com.aspose.html.drawing.Length.fromPixels(1000)
)
);
pageSetup.setAnyPage(anyPage);
options.setPageSetup(pageSetup);
options.setBackgroundColor(com.aspose.html.drawing.Color.getAliceBlue());
// Call the ConvertSVG to convert 'document.html' into jpeg image
com.aspose.html.converters.Converter.convertSVG(
"document.svg",
options,
"output.jpg"
);
// Prepare an SVG code.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
// Invoke the ConvertSVG method to convert the SVG code to image.
com.aspose.html.converters.Converter.convertSVG(
code,
".",
new com.aspose.html.saving.ImageSaveOptions(
com.aspose.html.rendering.image.ImageFormat.Jpeg
),
"output.jpg"
);
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Initialize an SVG document from the svg file.
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("document.svg");
try {
// Initialize PdfSaveOptions.
com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions();
// Convert SVG to PDF
com.aspose.html.converters.Converter.convertSVG(
document,
options,
"output.pdf"
);
} finally {
if (document != null) {
document.dispose();
}
}
// Create an instance of MemoryStreamProvider
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) {
// Prepare an SVG code
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
// Initialize an SVG document
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument(code, ".");
try {
// Convert SVG to PDF by using the MemoryStreamProvider
com.aspose.html.converters.Converter.convertSVG(
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();
}
}
}
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
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 SVG document to PDF
com.aspose.html.converters.Converter.convertSVG(
"document.svg",
options,
"output.pdf"
);
// Prepare an SVG code.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
// Call the ConvertSVG method to convert the SVG code to PDF.
com.aspose.html.converters.Converter.convertSVG(
code,
".",
new com.aspose.html.saving.PdfSaveOptions(),
"output.pdf"
);
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
fileWriter.write(code);
}
// Initialize an SVG document from the svg file.
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("document.svg");
try {
// Initialize XpsSaveOptions.
com.aspose.html.saving.XpsSaveOptions options = new com.aspose.html.saving.XpsSaveOptions();
// Convert SVG to XPS
com.aspose.html.converters.Converter.convertSVG(
document,
options,
"output.xps"
);
} finally {
if (document != null) {
document.dispose();
}
}
// Create an instance of MemoryStreamProvider
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) {
// Prepare an SVG code
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
// Initialize an SVG document
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument(code, ".");
try {
// Convert SVG to XPS by using the MemoryStreamProvider
com.aspose.html.converters.Converter.convertSVG(
document,
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);
}
} finally {
if (document != null) {
document.dispose();
}
}
}
// Prepare an SVG code and save it to the file.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.svg")) {
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 SVG document to XPS
com.aspose.html.converters.Converter.convertSVG(
"document.svg",
options,
"output.xps"
);
// Prepare an SVG code.
String code = "<svg xmlns='http://www.w3.org/2000/svg'>\n" +
"<circle cx='50' cy='50' r='40' stroke='black' stroke-width='3' fill='red' />\n" +
"</svg>\n";
// Invoke the ConvertSVG method to convert the SVG code to image.
com.aspose.html.converters.Converter.convertSVG(
code,
".",
new com.aspose.html.saving.XpsSaveOptions(),
"output.xps"
);
// Prepare an HTML code
String code = " <style>\n" +
" div {\n" +
" page - break -after:always;\n" +
" }\n" +
" </style >\n" +
" <div style = 'border: 1px solid red; width: 400px' > First Page</div >\n" +
" <div style = 'border: 1px solid red; width: 600px' > Second Page</div >\n";
// Initialize the HTML document from the HTML code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create the instance of Rendering Options and set a custom page-size
com.aspose.html.rendering.pdf.PdfRenderingOptions options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
options.getPageSetup().setAnyPage(new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(500, 200)));
// Enable auto-adjusting for the page size
options.getPageSetup().setAdjustToWidestPage(true);
// Create the PDF Device and specify options and output file
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(options, "output.pdf");
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code1 = "<br><span style='color: green'>Hello World!!</span>";
String code2 = "<br><span style='color: blue'>Hello World!!</span>";
String code3 = "<br><span style='color: red'>Hello World!!</span>";
// Create three HTML documents to merge later
com.aspose.html.HTMLDocument document1 = new com.aspose.html.HTMLDocument(code1, ".");
com.aspose.html.HTMLDocument document2 = new com.aspose.html.HTMLDocument(code2, ".");
com.aspose.html.HTMLDocument document3 = new com.aspose.html.HTMLDocument(code3, ".");
try {
// Create an instance of HTML Renderer
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
try {
// Create an instance of PDF device
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice("output.pdf");
try {
// Merge all HTML documents into PDF
renderer.render(device, new com.aspose.html.HTMLDocument[]{document1, document2, document3});
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document1 != null) {
document1.dispose();
}
if (document2 != null) {
document2.dispose();
}
if (document3 != null) {
document3.dispose();
}
}
// Prepare an HTML code
String code = "< script >\n" +
" var count = 0;\n" +
" setInterval(function()\n" +
" {\n" +
" var element = document.createElement('div');\n" +
" var message = (++count) + '. ' + 'Hello World!!';\n" +
" var text = document.createTextNode(message);\n" +
" element.appendChild(text);\n" +
" document.body.appendChild(element);\n" +
" },1000);\n" +
"</script >\n";
// Initialize an HTML document based on prepared HTML code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create an instance of HTML Renderer
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
try {
// Create an instance of PDF device
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice("output.pdf");
try {
// Render HTML to PDF
renderer.render(device, 5, document);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code and save it to the file.
String code = "<p>Hello World!!</p>";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
fileWriter.write(code);
}
// Create an instance of HTML document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html");
try {
// Initialize options with 'cyan' as a background-color
com.aspose.html.rendering.pdf.PdfRenderingOptions options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
options.setBackgroundColor(com.aspose.html.drawing.Color.getCyan());
// Create an instance of PDF device
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(options, "output.pdf");
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "<div>Hello World!!</div>";
// Initialize an instance of HTML document based on prepared code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create an instance of Rendering Options
com.aspose.html.rendering.image.ImageRenderingOptions options = new com.aspose.html.rendering.image.ImageRenderingOptions();
options.setFormat(com.aspose.html.rendering.image.ImageFormat.Jpeg);
// Disable smoothing mode
options.setSmoothingMode(com.aspose.html.drawing.SmoothingMode.None);
// Set the image resolution as 75 dpi
options.setVerticalResolution(com.aspose.html.drawing.Resolution.fromDotsPerInch(75));
options.setHorizontalResolution(com.aspose.html.drawing.Resolution.fromDotsPerInch(75));
// Create an instance of Image Device
com.aspose.html.rendering.image.ImageDevice device = new com.aspose.html.rendering.image.ImageDevice(options, "output.jpg");
try {
// Render HTML to Image
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "<style>\n" +
" div { page-break-after: always; }\n" +
"</style>\n" +
"< div > First Page</div >\n" +
"<div > Second Page</div >\n" +
"<div > Third Page</div >\n" +
"<div > Fourth Page</div >\n";
// Initialize the HTML document from the HTML code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create the instance of Rendering Options and set a custom page-size
com.aspose.html.rendering.pdf.PdfRenderingOptions options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
options.getPageSetup().setLeftRightPage(
new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(400, 200)),
new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(400, 100))
);
// Create the PDF Device and specify options and output file
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(options, "output.pdf");
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "<span>Hello World!!</span>";
// Initialize the HTML document from the HTML code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create the PDF Device and specify the output file to render
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice("output.pdf");
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "<div>Hello World!!</div>";
// Initialize the HTML document from the HTML code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create the instance of Rendering Options
com.aspose.html.rendering.pdf.PdfRenderingOptions options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
// Set the permissions to the file
options.setEncryption(
new com.aspose.html.rendering.pdf.encryption.PdfEncryptionInfo(
"user_pwd",
"owner_pwd",
com.aspose.html.rendering.pdf.encryption.PdfPermissions.PrintDocument,
com.aspose.html.rendering.pdf.encryption.PdfEncryptionAlgorithm.RC4_128
)
);
// Create the PDF Device and specify options and output file
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(options, "output.pdf");
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "<span>Hello World!!</span>";
// Initialize the HTML document from the HTML code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create the instance of PdfRenderingOptions and set a custom page-size
com.aspose.html.rendering.pdf.PdfRenderingOptions options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
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(5),
com.aspose.html.drawing.Length.fromInches(2)
)
);
pageSetup.setAnyPage(anyPage);
options.setPageSetup(pageSetup);
// Create the PDF Device and specify options and output file
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(options, "output.pdf");
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code and save it to the file.
String code = "< style >\n" +
" p\n" +
" {\n" +
" background:\n" +
" blue;\n" +
" }\n" +
" @media(min - resolution:300dpi)\n" +
" {\n" +
" p\n" +
" {\n" +
" /* high resolution screen color */\n" +
" background:\n" +
" green\n" +
" }\n" +
" }\n" +
" </style >\n" +
" <p > Hello World !! </p >\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
fileWriter.write(code);
}
// Create an instance of HTML document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html");
try {
// Create options for low-resolution screens
com.aspose.html.rendering.pdf.PdfRenderingOptions options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
options.setHorizontalResolution(com.aspose.html.drawing.Resolution.to_Resolution(50d));
options.setVerticalResolution(com.aspose.html.drawing.Resolution.to_Resolution(50d));
// Create an instance of PDF device
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(
options,
"output_resolution_50.pdf"
);
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
// Create options for high-resolution screens
options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
options.setHorizontalResolution(com.aspose.html.drawing.Resolution.to_Resolution(300d));
options.setVerticalResolution(com.aspose.html.drawing.Resolution.to_Resolution(300d));
// Create an instance of PDF device
device = new com.aspose.html.rendering.pdf.PdfDevice(
options,
"output_resolution_300.pdf"
);
try {
// Render HTML to PDF
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "<span>Hello World!!</span>";
// Initialize the HTML document from the HTML code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Create the instance of XpsRenderingOptions and set a custom page-size
com.aspose.html.rendering.xps.XpsRenderingOptions options = new com.aspose.html.rendering.xps.XpsRenderingOptions();
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(5),
com.aspose.html.drawing.Length.fromInches(2)
)
);
options.getPageSetup().setAnyPage(anyPage);
// Create the XPS Device and specify options and output file
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice(options, "output.xps");
try {
// Render HTML to XPS
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare a JSON data-source and save it to the file.
String data = " {\n" +
" 'FirstName': 'John',\n" +
" 'LastName': 'Smith',\n" +
" 'Address': {\n" +
" 'City': 'Dallas',\n" +
" 'Street': 'Austin rd.',\n" +
" 'Number': '200'\n" +
" }\n" +
" }\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("data-source.json")) {
fileWriter.write(data);
}
// Prepare an HTML Template and save it to the file.
String template = "<table border=1>\n" +
" <tr>\n" +
" <th>Person</th>\n" +
" <th>Address</th>\n" +
" </tr>\n" +
" <tr>\n" +
" <td>{{FirstName}} {{LastName}}</td>\n" +
" <td>{{Address.Street}} {{Address.Number}}, {{Address.City}}</td>\n" +
" </tr>\n" +
"</table>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("template.html")) {
fileWriter.write(template);
}
// Invoke Converter.ConvertTemplate in order to populate 'template.html' with the data-source from 'data-source.json' file
com.aspose.html.converters.Converter.convertTemplate(
"template.html",
new com.aspose.html.converters.TemplateData("data-source.json"),
new com.aspose.html.loading.TemplateLoadOptions(), "document.html"
);
com.aspose.html.dom.svg.SVGDocument document =
new com.aspose.html.dom.svg.SVGDocument(
"<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>",
"about:blank"
);
try {
// do some actions over the document here...
} finally {
document.dispose();
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<p>my first paragraph</p>", ".");
try {
// do some actions over the document here...
} finally {
document.dispose();
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("input.html");
try {
// do some actions over the document here...
} finally {
document.dispose();
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("https://www.facebook.com/");
try {
// do some actions over the document here...
} finally {
document.dispose();
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(new com.aspose.html.Url("https://www.facebook.com/"));
try {
// do some actions over the document here...
} finally {
document.dispose();
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// do some actions over the document here...
} finally {
document.dispose();
}
java.io.ByteArrayInputStream inputStream = new java.io.ByteArrayInputStream(
"<p>my first paragraph</p>".getBytes(java.nio.charset.StandardCharsets.UTF_8)
);
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(inputStream, "about:blank");
try {
// do some actions over the document here...
} finally {
if (document != null) {
document.dispose();
}
}
String outputHtml = "SimpleDocument.html";
// Create an instance of HTMLDocument
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
// Add image
com.aspose.html.dom.Element elm = document.createElement("img");
if (elm instanceof com.aspose.html.HTMLImageElement) {
com.aspose.html.HTMLImageElement img = (com.aspose.html.HTMLImageElement) elm;
img.setSrc("http://via.placeholder.com/400x200");
img.setAlt("Placeholder 400x200");
img.setTitle("Placeholder image");
document.getBody().appendChild(img);
}
// Add ordered list
com.aspose.html.HTMLOListElement orderedListElement = (com.aspose.html.HTMLOListElement) document.createElement("ol");
for (int i = 0; i < 10; i++) {
com.aspose.html.HTMLLIElement listItem = (com.aspose.html.HTMLLIElement) document.createElement("li");
listItem.setTextContent(" List Item {" + (i + 1) + "}");
orderedListElement.appendChild(listItem);
}
document.getBody().appendChild(orderedListElement);
// Add table 3x3
com.aspose.html.HTMLTableElement table = (com.aspose.html.HTMLTableElement) document.createElement("table");
com.aspose.html.HTMLTableSectionElement tBody = (com.aspose.html.HTMLTableSectionElement) document.createElement("tbody");
for (int i = 0; i < 3; i++) {
com.aspose.html.HTMLTableRowElement row = (com.aspose.html.HTMLTableRowElement) document.createElement("tr");
row.setId("trow_" + i);
for (int j = 0; j < 3; j++) {
com.aspose.html.HTMLTableCellElement cell = (com.aspose.html.HTMLTableCellElement) document.createElement("td");
cell.setId("cell{" + i + "}_{" + j + "}");
cell.setTextContent("Cell " + j);
row.appendChild(cell);
}
tBody.appendChild(row);
}
table.appendChild(tBody);
document.getBody().appendChild(table);
//Save the document to disk
document.save(outputHtml);
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
com.aspose.html.HTMLElement body = document.getBody();
// Create paragraph element
com.aspose.html.HTMLParagraphElement p = (com.aspose.html.HTMLParagraphElement) document.createElement("p");
// Set custom attribute
p.setAttribute("id", "my-paragraph");
// Create text node
com.aspose.html.dom.Text text = document.createTextNode("my first paragraph");
// Attach text to the paragraph
p.appendChild(text);
// Attach paragraph to the document body
body.appendChild(p);
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<p>paragraph</p><div>some element to remove</div>", "about:blank");
try {
com.aspose.html.HTMLElement body = document.getBody();
// Get "div" element
com.aspose.html.HTMLDivElement div = (com.aspose.html.HTMLDivElement) body.getElementsByTagName("div").get_Item(0);
// Remove found element
body.removeChild(div);
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<p>paragraph</p><div>some element to remove</div>", "about:blank");
try {
com.aspose.html.HTMLElement body = document.getBody();
// Get "div" element
com.aspose.html.HTMLDivElement div = (com.aspose.html.HTMLDivElement) body.getElementsByTagName("div").get_Item(0);
// Remove found element
body.removeChild(div);
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<style>p { color: red; }</style><p>my first paragraph</p>", "about:blank");
try {
// Get the element to inspect
com.aspose.html.dom.Element element = document.getElementsByTagName("p").get_Item(0);
// Get the CSS view object
com.aspose.html.dom.css.IViewCSS view = (com.aspose.html.dom.css.IViewCSS) document.getContext().getWindow();
// Get the computed style of the element
com.aspose.html.dom.css.ICSSStyleDeclaration declaration = view.getComputedStyle(element);
// Get "color" property value
System.out.println(declaration.getPropertyCSSValue("color")); // rgb(255, 0, 0)
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<style>p { color: red; }</style><p>my first paragraph</p>", "about:blank");
try {
// Get the element to edit
com.aspose.html.HTMLElement element = (com.aspose.html.HTMLElement) document.getElementsByTagName("p").get_Item(0);
// Get the CSS view object
com.aspose.html.dom.css.IViewCSS view = (com.aspose.html.dom.css.IViewCSS) document.getContext().getWindow();
// Get the computed style of the element
com.aspose.html.dom.css.ICSSStyleDeclaration declaration = view.getComputedStyle(element);
// Set green color
element.getStyle().setProperty("Color", "green");
// Get "color" property value
System.out.println(declaration.getPropertyCSSValue("color")); // rgb(0, 128, 0)
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Get body element
com.aspose.html.HTMLElement body = document.getBody();
// Set content of the body element
body.setInnerHTML("<p>paragraph</p>");
// Move to the first child
com.aspose.html.dom.Node node = body.getFirstChild();
System.out.println(node.getLocalName());
} finally {
if (document != null) {
document.dispose();
}
}
String InputHtml = "input.html";
try (java.io.FileWriter fileWriter = new java.io.FileWriter(InputHtml)) {
// Write sample HTML tags to HTML file
fileWriter.write("<p>this is a simple text");
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
// you can subscribe to the event 'OnLoad'
document.OnLoad.add(new com.aspose.html.dom.events.DOMEventHandler() {
@Override
public void invoke(Object sender, com.aspose.html.dom.events.Event e) {
// manipulate with document here
}
});
document.navigate("input.html");
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
// subscribe to the event 'OnReadyStateChange' that will be fired once document is completely loaded
document.OnReadyStateChange.add(new com.aspose.html.dom.events.DOMEventHandler() {
@Override
public void invoke(Object sender, com.aspose.html.dom.events.Event e) {
if (document.getReadyState().equals("complete")) {
// manipulate with document here
}
}
});
document.navigate("output.html");
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(
new com.aspose.html.Url("https://www.facebook.com/")
);
try {
// Read children nodes and get length information
if (document.getBody().getChildNodes().getLength() == 0)
System.out.println("No ChildNodes found...");
// Print Document URI to console. As per information above, it has to be https://www.w3.org/TR/html5/
System.out.println("Print Document URI = " + document.getDocumentURI());
// Print domain name for remote HTML
System.out.println("Domain Name = " + document.getDomain());
} finally {
if (document != null) {
document.dispose();
}
}
String InputHtml = "http://aspose.com/";
// Load HTML file using Url instance
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(new com.aspose.html.Url(InputHtml));
// Print inner HTML of file to console
System.out.println(document.getBody().getInnerHTML());
// Create an empty document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Create a Canvas element
com.aspose.html.HTMLCanvasElement canvas = (com.aspose.html.HTMLCanvasElement) document.createElement("canvas");
// Set the canvas size
canvas.setWidth(300);
canvas.setHeight(150);
// Append created element to the document
document.getBody().appendChild(canvas);
// Initialize a canvas 2D context
com.aspose.html.dom.canvas.ICanvasRenderingContext2D context = (com.aspose.html.dom.canvas.ICanvasRenderingContext2D) canvas.getContext("2d");
// Prepare a 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");
// Set the previously prepared brush to the fill and stroke properties
context.setFillStyle(gradient);
context.setStrokeStyle(gradient);
// Fill a rectange
context.fillRect(0, 95, 300, 20);
// Write a text
context.fillText("Hello World!", 10, 90, 500d);
// Create an instance of HTML renderer and XPS output device
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice("canvas.xps");
try {
// Render the document to the specified device
renderer.render(device, document);
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
String InputHtml = "input.html";
// Create HtmlDocument instance to load existing HTML file
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(InputHtml);
// Print inner HTML of file to console
System.out.println(document.getBody().getInnerHTML());
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<h1>heading text</h1>", "about:blank");
try {
// Create corresponding save options
com.aspose.html.saving.MarkdownSaveOptions saveOptions = com.aspose.html.saving.MarkdownSaveOptions.getGit();
// Save to .md file
document.save("HTMLToMarkDown_out.md", saveOptions);
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(
"<link href=\"\"c:\\work\\style.css\"\" rel=\"\"stylesheet\"\">\n" +
"<p>my first paragraph</p>\n", "about:blank");
try {
// Create corresponding save options
com.aspose.html.saving.MHTMLSaveOptions saveOptions = new com.aspose.html.saving.MHTMLSaveOptions();
// Set default resource handling behaviour to "embed"
saveOptions.getResourceHandlingOptions().setDefault(com.aspose.html.saving.ResourceHandling.Embed);
// Remove URL restrictions because referenced resource is in another domain
saveOptions.getResourceHandlingOptions().setUrlRestriction(com.aspose.html.saving.UrlRestriction.None);
// Save to .mht file
document.save("HtmlToMhtml_out.mht", saveOptions);
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<p>my first paragraph</p>", "about:blank");
try {
document.save("SaveToFile_out.html");
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<p>my first paragraph</p>", "about:blank");
try {
// Create options object
com.aspose.html.saving.HTMLSaveOptions options = new com.aspose.html.saving.HTMLSaveOptions();
// Set the maximum depth of resource which will be handled.
// Depth of 1 means that only resources directly referenced from the saved document will be handled.
// Setting this property to -1 will lead to handling of all resources.
// Default value is 3
options.getResourceHandlingOptions().setMaxHandlingDepth(1);
// This property is used to set restriction applied to handlers of external resources.
// SameHost means that only resources located at the same host will be saved.
options.getResourceHandlingOptions().setUrlRestriction(com.aspose.html.saving.UrlRestriction.SameHost);
// This property is used to setup processing behaviour of any type of resource.
// ResourceHandling.Save means all resources will be saved to the output folder
options.getResourceHandlingOptions().setDefault(com.aspose.html.saving.ResourceHandling.Save);
// This property is used to set up processing behaviour of particular 'application/javascript' mime type.
// In our case all scripts will be skipped during saving
options.getResourceHandlingOptions().setJavaScript(com.aspose.html.saving.ResourceHandling.Discard);
// Save the document
document.save("SaveUsingHTMLSaveOptions_out.html", options);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "< div class='happy' >\n" +
" <div >\n" +
" <span > Hello </span >\n" +
" </div >\n" +
" </div >\n" +
" <p class='happy' >\n" +
" <span > World ! </span >\n" +
" </p >\n";
// Initialize a document based on the prepared code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Here we create a CSS Selector that extract all elements whose 'class' attribute equals to 'happy' and their child SPAN elements
com.aspose.html.collections.NodeList elements = document.querySelectorAll(".happy span");
// Iterate over the resulted list of elements
elements.forEach(element -> {
System.out.println(((com.aspose.html.HTMLElement) element).getInnerHTML());
// output: Hello
// output: World!
});
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String html_code = "<span>Hello</span> <span>World!</span>";
// Initialize a document from the prepared code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(html_code, ".");
try {
// Get the reference to the first child (first SPAN) of the BODY
com.aspose.html.dom.Element element = document.getBody().getFirstElementChild();
System.out.println(element.getTextContent()); // output: Hello
// Get the reference to the second SPAN element
element = element.getNextElementSibling();
System.out.println(element.getTextContent()); // output: World!
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = " < p > Hello </p >\n" +
" <img src = 'image1.png' >\n" +
" <img src = 'image2.png' >\n" +
" <p > World ! </p >\n";
// Initialize a document based on the prepared code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// To start HTML navigation we need to create an instance of TreeWalker.
// The specified parameters mean that it starts walking from the root of the document, iterating all nodes and use our custom implementation of the filter
com.aspose.html.dom.traversal.ITreeWalker iterator = document.createTreeWalker(document, com.aspose.html.dom.traversal.filters.NodeFilter.SHOW_ALL, new OnlyImageFilter());
// Use
while (iterator.nextNode() != null) {
// Since we are using our own filter, the current node will always be an instance of the HTMLImageElement.
// So, we don't need the additional validations here.
com.aspose.html.HTMLImageElement image = (com.aspose.html.HTMLImageElement) iterator.getCurrentNode();
System.out.println(image.getSrc());
// output: image1.png
// output: image2.png
}
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String code = "< div class='happy' >\n" +
" <div >\n" +
" <span > Hello ! </span >\n" +
" </div >\n" +
" </div >\n" +
" <p class='happy' >\n" +
" <span > World </span >\n" +
" </p >\n";
// Initialize a document based on the prepared code
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(code, ".");
try {
// Here we evaluate the XPath expression where we select all child SPAN elements from elements whose 'class' attribute equals to 'happy':
com.aspose.html.dom.xpath.IXPathResult result = document.evaluate("//*[@class='happy']//span",
document,
null,
com.aspose.html.dom.xpath.XPathResultType.Any,
null
);
// Iterate over the resulted nodes
for (com.aspose.html.dom.Node node; (node = result.iterateNext()) != null; ) {
System.out.println(node.getTextContent());
// output: Hello
// output: World!
}
} finally {
if (document != null) {
document.dispose();
}
}
// Initialize configuration object and set up the page-margins for the document
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
configuration.getService(com.aspose.html.services.IUserAgentService.class).setUserStyleSheet(
"@page\n" +
" {\n" +
" /* Page margins should be not empty in order to write content inside the margin-boxes */\n" +
" margin - top:1 cm;\n" +
" margin - left:2 cm;\n" +
" margin - right:2 cm;\n" +
" margin - bottom:2 cm;\n" +
"\n" +
" /* Page counter located at the bottom of the page */\n" +
" @bottom -right\n" +
" {\n" +
" -aspose - content:\"\" Page \"\" currentPageNumber() \"\" of \"\" totalPagesNumber();\n" +
" color:\n" +
" green;\n" +
" }\n" +
"\n" +
" /* Page title located at the top-center box */\n" +
" @top -center\n" +
" {\n" +
" -aspose - content:\"\" Document 's title\"\";\n" +
" vertical - align:bottom;\n" +
" }\n" +
" }\n"
);
// Initialize an empty document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(configuration);
try {
// Initialize an output device
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice("output_out.xps");
try {
// Send the document to the output device
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", "c:\\work\\");
try {
com.aspose.html.rendering.pdf.PdfRenderingOptions options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
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(500, 500)
);
anyPage.setMargin(new com.aspose.html.drawing.Margin(50, 50, 50, 50));
pageSetup.setAnyPage(anyPage);
options.setPageSetup(pageSetup);
options.setEncryption(
new com.aspose.html.rendering.pdf.encryption.PdfEncryptionInfo(
"user",
"p@wd",
com.aspose.html.rendering.pdf.encryption.PdfPermissions.PrintDocument,
com.aspose.html.rendering.pdf.encryption.PdfEncryptionAlgorithm.RC4_128
)
);
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(options, "document_out.pdf");
try {
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", "c:\\work\\");
try {
// Initialize rendering optionss and set jpeg as output format
com.aspose.html.rendering.image.ImageRenderingOptions options = new com.aspose.html.rendering.image.ImageRenderingOptions(com.aspose.html.rendering.image.ImageFormat.Jpeg);
// Set the size and margin property for all pages.
options.getPageSetup().setAnyPage(
new com.aspose.html.drawing.Page(
new com.aspose.html.drawing.Size(500, 500),
new com.aspose.html.drawing.Margin(50, 50, 50, 50)
)
);
// If the document has an element which size is bigger than predefined by user page size output pages will be will be adjusted.
options.getPageSetup().setAdjustToWidestPage(true);
com.aspose.html.rendering.image.ImageDevice device = new com.aspose.html.rendering.image.ImageDevice(options, "document_out.jpg");
try {
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", "c:\\work\\");
try {
com.aspose.html.rendering.image.ImageDevice device = new com.aspose.html.rendering.image.ImageDevice("document_out.png");
try {
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<style>p { color: green; }</style><p>my first paragraph</p>", "c:/work/");
try {
com.aspose.html.rendering.xps.XpsRenderingOptions xpsRenderingOptions = new com.aspose.html.rendering.xps.XpsRenderingOptions();
com.aspose.html.rendering.PageSetup pageSetup = new com.aspose.html.rendering.PageSetup();
com.aspose.html.drawing.Page anyPage = new com.aspose.html.drawing.Page(
new com.aspose.html.drawing.Size(500, 500),
new com.aspose.html.drawing.Margin(50, 50, 50, 50)
);
pageSetup.setAnyPage(anyPage);
xpsRenderingOptions.setPageSetup(pageSetup);
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice(
xpsRenderingOptions,
"document_out.xps"
);
try {
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Create the instance of HTML Document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
// Subscribe to the 'OnLoad' event.
// This event will be fired once the document is fully loaded.
document.OnLoad.add(new com.aspose.html.dom.events.DOMEventHandler() {
@Override
public void invoke(Object sender, com.aspose.html.dom.events.Event e) {
msg = document.getDocumentElement().getOuterHTML();
System.out.println(msg);
}
});
// Navigate asynchronously at the specified Uri
document.navigate("https://html.spec.whatwg.org/multipage/introduction.html");
}
public String getMsg() {
return msg;
// Create the instance of HTML Document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
// Subscribe to the 'ReadyStateChange' event.
// This event will be fired during the document loading process.
document.OnReadyStateChange.add(new com.aspose.html.dom.events.DOMEventHandler() {
@Override
public void invoke(Object sender, com.aspose.html.dom.events.Event e) {
// Check the value of 'ReadyState' property.
// This property is representing the status of the document. For detail information please visit https://www.w3schools.com/jsref/prop_doc_readystate.asp
if (document.getReadyState().equals("complete")) {
System.out.println(document.getDocumentElement().getOuterHTML());
notifyAll();
}
}
});
// Navigate asynchronously at the specified Uri
document.navigate("https://html.spec.whatwg.org/multipage/introduction.html");
synchronized (this) {
wait(10000);
}
// Prepare a 'document.html' file.
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
fileWriter.write("Hello World!");
}
// Load from a 'document.html' file.
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html");
// Write the document content to the output stream.
System.out.println(document.getDocumentElement().getOuterHTML());
// Create a memory stream object
java.io.InputStream inputStream =
new java.io.ByteArrayInputStream(
"<p>Hello World!</p>".getBytes(java.nio.charset.StandardCharsets.UTF_8)
);
// Initialize document from the string variable
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(inputStream, ".");
try {
// Save the document to disk.
document.save("document.html");
} finally {
if (document != null) {
document.dispose();
}
}
// Initialize an empty HTML Document.
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Create a text element and add it to the document
com.aspose.html.dom.Text text = document.createTextNode("Hello World!");
document.getBody().appendChild(text);
// Save the document to disk.
document.save("document.html");
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String html_code = "<p>Hello World!</p>";
// Initialize document from the string variable
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(html_code, ".");
try {
// Save the document to disk.
document.save("document.html");
} finally {
if (document != null) {
document.dispose();
}
}
// Load a document from 'https://html.spec.whatwg.org/multipage/introduction.html' web page
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("https://www.facebook.com/");
try {
// Write the document content to the output stream.
System.out.println(document.getDocumentElement().getOuterHTML());
} finally {
if (document != null) {
document.dispose();
}
}
// Initialize the SVG Document from the string object
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", ".");
try {
// Write the document content to the output stream.
System.out.println(document.getDocumentElement().getOuterHTML());
} finally {
if (document != null) {
document.dispose();
}
}
// Create an instance of HTML Document with specified content
String content = "<style>p { color: red; }</style><p>Hello World!</p>";
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(content, ".");
try {
// Find the paragraph element to inspect the styles
com.aspose.html.HTMLElement paragraph = (com.aspose.html.HTMLElement) document.getElementsByTagName("p").get_Item(0);
// Get the reference to the IViewCSS interface.
com.aspose.html.dom.css.IViewCSS view = (com.aspose.html.dom.css.IViewCSS) document.getContext().getWindow();
// Get the calculated style value for the paragraph node
com.aspose.html.dom.css.ICSSStyleDeclaration declaration = view.getComputedStyle(paragraph);
// Read the "color" property value out of the style declaration object
System.out.println(declaration.getPropertyCSSValue("color"));
// Set the green color to the paragraph
paragraph.getStyle().setProperty("color", "navy");
// Create the instance of the PDF output device and render the document into this device
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice("output.pdf");
try {
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Create the instance of HTML Document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Create the style element and assign the green color for all elements with class-name equals 'gr'.
com.aspose.html.dom.Element style = document.createElement("style");
style.setTextContent(".gr { color: green }");
// Find the document header element and append style element to the header
com.aspose.html.dom.Element head = document.getElementsByTagName("head").get_Item(0);
head.appendChild(style);
// Create the paragraph element with class-name 'gr'.
com.aspose.html.HTMLParagraphElement p = (com.aspose.html.HTMLParagraphElement) document.createElement("p");
p.setClassName("gr");
// Create the text node
com.aspose.html.dom.Text text = document.createTextNode("Hello World!!");
// Append the text node to the paragraph
p.appendChild(text);
// Append the paragraph to the document body element
document.getBody().appendChild(p);
// Create the instance of the PDF output device and render the document into this device
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice("output.pdf");
try {
document.renderTo(device);
} finally {
if (device != null) {
device.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Create an instance of HTML Document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Write the content of the HTML document into the console output
System.out.println(document.getDocumentElement().getOuterHTML()); // output: <html><head></head><body></body></html>
// Set content of the body element
document.getBody().setInnerHTML("<p>Hello World!!</p>");
// Write the content of the HTML document into the console output
System.out.println(document.getDocumentElement().getOuterHTML()); // output: <html><head></head><body><p>Hello World!!</p></body></html>
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code with missing image file
String code = "<img src='missing.jpg'>";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
fileWriter.write(code);
}
// Create an instance of Configuration
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
try {
// Add ErrorMessageHandler to the chain of existing message handlers
com.aspose.html.services.INetworkService network = configuration.getService(com.aspose.html.services.INetworkService.class);
network.getMessageHandlers().addItem(new LogMessageHandler());
// Initialize an HTML document with specified configuration
// During the document loading, the application will try to load the image and we will see the result of this operation in the console.
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html", configuration);
try {
// Convert HTML to PNG
com.aspose.html.converters.Converter.convertHTML(
document,
new com.aspose.html.saving.ImageSaveOptions(),
"output.png"
);
} finally {
if (document != null) {
document.dispose();
}
}
} finally {
if (configuration != null) {
configuration.dispose();
}
}
// Prepare an HTML code and save it to the file.
String code = "<span>Hello World!!</span>\n" +
"<script>document.write('Have a nice day!');</script>\n";
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
fileWriter.write(code);
}
// Create an instance of Configuration
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
try {
// Mark 'scripts' as an untrusted resource
configuration.setSecurity(com.aspose.html.Sandbox.Scripts);
// Initialize an HTML document with specified configuration
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html", configuration);
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();
}
}
} finally {
if (configuration != null) {
configuration.dispose();
}
}
// Create an instance of Configuration
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
// Get the IUserAgentService
com.aspose.html.services.IUserAgentService userAgent = configuration.getService(com.aspose.html.services.IUserAgentService.class);
// Set ISO-8859-1 encoding to parse the document
userAgent.setCharSet("ISO-8859-1");
// 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);
}
// Create an instance of Configuration
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
try {
// Get the IUserAgentService
com.aspose.html.services.IUserAgentService userAgent = configuration.getService(com.aspose.html.services.IUserAgentService.class);
// Set the custom color to the SPAN element
userAgent.setUserStyleSheet("span { color: green; }");
// Initialize an HTML document with specified configuration
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html", configuration);
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();
}
}
} finally {
if (configuration != null) {
configuration.dispose();
}
}
// Initialize an empty HTML Document.
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Create a text element and add it to the document
com.aspose.html.dom.Text text = document.createTextNode("Hello World!");
document.getBody().appendChild(text);
// Save the HTML to the file on disk.
document.save("document.html");
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an HTML code
String html_code = "<H2>Hello World!</H2>";
// Initialize document from the string variable
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(html_code, ".");
try {
// Save the document as a Markdown file.
document.save("document.md", com.aspose.html.saving.HTMLSaveFormat.Markdown);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare a simple HTML file with a linked document.
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
fileWriter.write("<p>Hello World!</p>" + "<a href='linked.html'>linked file</a>");
}
// Prepare a simple linked HTML file
try (java.io.FileWriter fileWriter = new java.io.FileWriter("linked.html")) {
fileWriter.write("<p>Hello linked file!</p>");
}
// Load 'document.html' into memory
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html");
try {
// Save the document
document.save("document.mht", com.aspose.html.saving.HTMLSaveFormat.MHTML);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare a simple HTML file with a linked document.
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
fileWriter.write("<p>Hello World!</p>\n" +
"<a href='linked.html'>linked file</a>\n"
);
}
// Prepare a simple linked HTML file
try (java.io.FileWriter fileWriter = new java.io.FileWriter("linked.html")) {
fileWriter.write("<p>Hello linked file!</p>");
}
// Load 'document.html' into memory
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html");
try {
// Create Save Options instance
com.aspose.html.saving.HTMLSaveOptions options = new com.aspose.html.saving.HTMLSaveOptions();
// The following line with value '0' cut off all other linked HTML-files while saving this instance.
// If you remove this line or change value to the '1', the 'linked.html' file will be saved as well to the output folder.
options.getResourceHandlingOptions().setMaxHandlingDepth(1);
// Save the document
document.save("document.html", options);
} finally {
if (document != null) {
document.dispose();
}
}
// Prepare an SVG code
String code = "<svg xmlns='http://www.w3.org/2000/svg' height='80' width='300'>\n" +
" <g fill='none'>\n" +
" <path stroke='red' d='M5 20 l215 0' />\n" +
" <path stroke='black' d='M5 40 l215 0' />\n" +
" <path stroke='blue' d='M5 60 l215 0' />\n" +
" </g>\n" +
" </svg>\n";
// Initialize a SVG instance from the content string
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument(code, ".");
try {
// Save the SVG file to the disk
document.save("document.svg");
} finally {
if (document != null) {
document.dispose();
}
}
// Create a custom StreamProvider based on ICreateStreamProvider interface
try (MemoryStreamProvider streamProvider = new MemoryStreamProvider()) {
// Create a simple HTML document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Add your first 'hello world' to the document.
document.getBody().appendChild(document.createTextNode("Hello world!!!"));
// Convert HTML document to XPS by using the custom StreamProvider
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();
}
}
}
// The MutationObserver interface provides the ability to watch for changes being made to the DOM tree.
// Create an empty document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Create an 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
) {
synchronized (this) {
com.aspose.html.dom.mutations.MutationRecord mutationRecord =
((java.util.List<com.aspose.html.dom.mutations.MutationRecord>) mutations)
.get(0);
System.out.println(mutationRecord.getAddedNodes().get_Item(0));
notifyAll();
}
}
});
// Options for the observer (which mutations to observe)
com.aspose.html.dom.mutations.MutationObserverInit config = new com.aspose.html.dom.mutations.MutationObserverInit();
config.setChildList(true);
config.setSubtree(true);
// Start observing the target node
observer.observe(document.getDocumentElement(), config);
// An example of user modifications
com.aspose.html.dom.Element p = document.createElement("p");
document.getDocumentElement().appendChild(p);
// 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();
}
}
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("document.epub")) {
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice("document_out.xps");
com.aspose.html.rendering.EpubRenderer renderer = new com.aspose.html.rendering.EpubRenderer();
try {
renderer.render(device, fileInputStream, new com.aspose.html.Configuration());
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(
"<style>p { color: green; }</style><p>my first paragraph</p>",
Resources.outputDirectory()
);
try {
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
com.aspose.html.rendering.image.ImageDevice device = new com.aspose.html.rendering.image.ImageDevice("document_out.png");
try {
renderer.render(device, document);
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Create an instance of the HTML document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Async loading of the external html file
document.navigate("input.html");
// Create a renderer and output device
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
com.aspose.html.rendering.image.ImageDevice device = new com.aspose.html.rendering.image.ImageDevice("document.png");
try {
// Delay the rendering indefinitely until there are no scripts or any other internal tasks to execute
renderer.render(device, -1l, document);
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// Create an instance of the HTML document
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument();
try {
// Async loading of the external html file
document.navigate("input.html");
// Create a renderer and output device
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
com.aspose.html.rendering.image.ImageDevice device = new com.aspose.html.rendering.image.ImageDevice("document.png");
try {
// Delay rendering for 5 seconds
// Note: document will be rendered into device if there are no scripts or any internal tasks to execute
renderer.render(device, com.aspose.time.TimeSpan.fromSeconds(5), document);
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream("document.mht")) {
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice("document_out.xps");
com.aspose.html.rendering.MhtmlRenderer renderer = new com.aspose.html.rendering.MhtmlRenderer();
try {
renderer.render(device, fileInputStream, new com.aspose.html.Configuration());
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
}
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(
"<style>p { color: green; }</style><p>my first paragraph0</p>",
Resources.outputDirectory()
);
com.aspose.html.HTMLDocument document2 = new com.aspose.html.HTMLDocument(
"<style>p { color: blue; }</style><p>my first paragraph1</p>",
Resources.outputDirectory()
);
try {
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice("document_out.xps");
try {
renderer.render(device, new com.aspose.html.HTMLDocument[]{document, document2});
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
if (document2 != null) {
document2.dispose();
}
}
com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("<svg xmlns='http://www.w3.org/2000/svg'><circle cx='50' cy='50' r='40'/></svg>", "c:\\work\\");
try {
com.aspose.html.rendering.SvgRenderer renderer = new com.aspose.html.rendering.SvgRenderer();
com.aspose.html.rendering.image.ImageDevice device = new com.aspose.html.rendering.image.ImageDevice("document_out.png");
try {
renderer.render(device, document);
} finally {
if (device != null) {
device.dispose();
}
if (renderer != null) {
renderer.dispose();
}
}
} finally {
if (document != null) {
document.dispose();
}
}
// HTML template document
com.aspose.html.HTMLDocument templateHtml = new com.aspose.html.HTMLDocument("HTMLTemplateforXML.html");
//XML data for merging
com.aspose.html.converters.TemplateData data = new com.aspose.html.converters.TemplateData("XMLTemplate.xml");
//Output file path
String templateOutput = "HTMLTemplate_Output.html";
//Merge HTML tempate with XML data
com.aspose.html.converters.Converter.convertTemplate(
templateHtml,
data,
new com.aspose.html.loading.TemplateLoadOptions(),
templateOutput
);
package com.aspose.html.examples.java;
public class HTMLDocumentWaiter implements Runnable {
private Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html;
public HTMLDocumentWaiter(Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html) {
this.html = html;
try {
this.html.execute();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void run() {
System.out.println("Current Thread: " + Thread.currentThread().getName() + "; " + Thread.currentThread().getId());
try {
while (!Thread.currentThread().isInterrupted() && html.getMsg() == null) {
Thread.currentThread().sleep(60000);
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}
}
package com.aspose.html.examples.java;
public class HttpStatus {
public static final int SC_OK = 200;
}
package com.aspose.html.examples.java;
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-Java
/// <summary>
/// This message handler logs all failed requests to the console.
/// </summary>
public class LogMessageHandler extends com.aspose.html.net.MessageHandler {
public void invoke(com.aspose.html.net.INetworkOperationContext context) {
// Check whether response is OK
if (context.getResponse().getStatusCode() != HttpStatus.SC_OK) {
// Log information to console
System.out.println("File Not Found: " + context.getRequest().getRequestUri());
}
// Invoke the next message handler in the chain.
//Next(context);
}
}
package com.aspose.html.examples.java;
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-Java
public class MemoryStreamProvider implements java.io.Closeable {
// List of InputStream objects created during the document rendering
public java.util.List<java.io.InputStream> lStream = new java.util.ArrayList<>();
@Override
public void close() throws java.io.IOException {
for (java.io.InputStream stream : lStream) {
stream.close();
}
}
}
package com.aspose.html.examples.java;
// For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-Java
public class OnlyImageFilter extends com.aspose.html.dom.traversal.filters.NodeFilter {
@Override
public short acceptNode(com.aspose.html.dom.Node n) {
// The current filter skips all elements, except IMG elements.
return "img".equals(n.getLocalName()) ? FILTER_ACCEPT : FILTER_SKIP;
}
}
package com.aspose.html.examples.java;
import java.nio.file.Path;
import java.nio.file.Paths;
public class RunExamples {
public static void main(String... args) {
System.out.println("Open com.aspose.html.examples.java.RunExamples.java. \nIn main(String... args) method uncomment the example that you want to run.");
System.out.println("=====================================================");
// Uncomment the one you want to try out
// =====================================================
// =====================================================
// Aspose.HTML
// =====================================================
// =====================================================
/**
* EnvironmentConfiguration
*/
//EnvironmentConfiguration.DisableScriptsExecution();
//EnvironmentConfiguration.SpecifyUserStyleSheet();
//EnvironmentConfiguration.JavaScriptExecutionTimeout();
//EnvironmentConfiguration.CustomMessageHandler();
/**
* CreatingADocument
*/
//CreatingADocument.HTMLDocumentFromScratch();
//CreatingADocument.HTMLDocumentFromFile();
//CreatingADocument.HTMLDocumentFromURL();
//CreatingADocument.HTMLDocumentFromString();
//CreatingADocument.HTMLDocumentFromMemoryStream();
//CreatingADocument.SVGDocumentFromString();
//CreatingADocument.HTMLDocumentAsynchronouslyOnReadyStateChange();
//CreatingADocument.HTMLDocumentAsynchronouslyOnLoad();
/**
* EditingADocument
*/
//EditingADocument.UsingDOM();
//EditingADocument.UsingInnerOuterHTML();
//EditingADocument.EditCSS();
/**
* SavingADocument
*/
//SavingADocument.HTMLToFile();
//SavingADocument.HTMLWithoutLinkedFile();
//SavingADocument.HTMLToMHTML();
//SavingADocument.HTMLToMarkdown();
//SavingADocument.SVGToFile();
/**
* ConvertHTMLToImage
*/
//ConvertHTMLToImage.WithASingleLine();
//ConvertHTMLToImage.ConvertHTMLToJPG();
//ConvertHTMLToImage.ConvertHTMLToPNG();
//ConvertHTMLToImage.ConvertHTMLToBMP();
//ConvertHTMLToImage.ConvertHTMLToGIF();
//ConvertHTMLToImage.ConvertHTMLToTIFF();
//ConvertHTMLToImage.SpecifyImageSaveOptions();
//ConvertHTMLToImage.SpecifyCustomStreamProvider();
/**
* ConvertHTMLToPDF
*/
//ConvertHTMLToPDF.WithASingleLine();
//ConvertHTMLToPDF.ConvertHTMLDocumentToPDF();
//ConvertHTMLToPDF.SpecifyPdfSaveOptions();
//ConvertHTMLToPDF.SpecifyCustomStreamProvider();
/**
* ConvertHTMLToXPS
*/
//ConvertHTMLToXPS.WithASingleLine();
//ConvertHTMLToXPS.ConvertHTMLDocumentToXPS();
//ConvertHTMLToXPS.SpecifyXpsSaveOptions();
//ConvertHTMLToXPS.SpecifyCustomStreamProvider();
/**
* ConvertHTMLToMarkdown
*/
//ConvertHTMLToMarkdown.WithASingleLine();
//ConvertHTMLToMarkdown.SpecifyMarkdownSaveOptions();
//ConvertHTMLToMarkdown.ConvertUsingGitSyntax();
//ConvertHTMLToMarkdown.InlineHTML();
/**
* ConvertHTMLToMHTML
*/
//ConvertHTMLToMHTML.WithASingleLine();
//ConvertHTMLToMHTML.ConvertHTMLDocumentToMHTML();
//ConvertHTMLToMHTML.SpecifyMHTMLSaveOptions();
/**
* ConvertSVGToImage
*/
//ConvertSVGToImage.WithASingleLine();
//ConvertSVGToImage.ConvertSVGToJPG();
//ConvertSVGToImage.ConvertSVGToPNG();
//ConvertSVGToImage.ConvertSVGToBMP();
//ConvertSVGToImage.ConvertSVGToGIF();
//ConvertSVGToImage.ConvertSVGToTIFF();
//ConvertSVGToImage.SpecifyImageSaveOptions();
//ConvertSVGToImage.SpecifyCustomStreamProvider();
/**
* ConvertSVGToPDF
*/
//ConvertSVGToPDF.WithASingleLine();
//ConvertSVGToPDF.ConvertSVGDocumentToPDF();
//ConvertSVGToPDF.SpecifyPdfSaveOptions();
//ConvertSVGToPDF.SpecifyCustomStreamProvider();
/**
* ConvertSVGToXPS
*/
//ConvertSVGToXPS.WithASingleLine();
//ConvertSVGToXPS.ConvertSVGDocumentToXPS();
//ConvertSVGToXPS.SpecifyXpsSaveOptions();
//ConvertSVGToXPS.SpecifyCustomStreamProvider();
/**
* ConvertEPUBToImage
*/
//ConvertEPUBToImage.WithASingleLine();
//ConvertEPUBToImage.ConvertEPUBToJPG();
//ConvertEPUBToImage.ConvertEPUBToPNG();
//ConvertEPUBToImage.ConvertEPUBToBMP();
//ConvertEPUBToImage.ConvertEPUBToGIF();
//ConvertEPUBToImage.ConvertEPUBToTIFF();
//ConvertEPUBToImage.SpecifyImageSaveOptions();
//ConvertEPUBToImage.SpecifyCustomStreamProvider();
/**
* ConvertEPUBToPDF
*/
//ConvertEPUBToPDF.WithASingleLine();
//ConvertEPUBToPDF.ConvertEPUBFileToPDF();
//ConvertEPUBToPDF.SpecifyPdfSaveOptions();
//ConvertEPUBToPDF.SpecifyCustomStreamProvider();
/**
* ConvertEPUBToXPS
*/
//ConvertEPUBToXPS.WithASingleLine();
//ConvertEPUBToXPS.ConvertEPUBFileToXPS();
//ConvertEPUBToXPS.SpecifyXpsSaveOptions();
//ConvertEPUBToXPS.SpecifyCustomStreamProvider();
/**
* ConvertMHTMLToImage
*/
//ConvertMHTMLToImage.WithASingleLine();
//ConvertMHTMLToImage.ConvertMHTMLToJPG();
//ConvertMHTMLToImage.ConvertMHTMLToPNG();
//ConvertMHTMLToImage.ConvertMHTMLToBMP();
//ConvertMHTMLToImage.ConvertMHTMLToGIF();
//ConvertMHTMLToImage.ConvertMHTMLToTIFF();
//ConvertMHTMLToImage.SpecifyImageSaveOptions();
//ConvertMHTMLToImage.SpecifyCustomStreamProvider();
/**
* ConvertMHTMLToPDF
*/
//ConvertMHTMLToPDF.WithASingleLine();
//ConvertMHTMLToPDF.ConvertMHTMLFileToPDF();
//ConvertMHTMLToPDF.SpecifyPdfSaveOptions();
//ConvertMHTMLToPDF.SpecifyCustomStreamProvider();
/**
* ConvertMHTMLToXPS
*/
//ConvertMHTMLToXPS.WithASingleLine();
//ConvertMHTMLToXPS.ConvertMHTMLFileToXPS();
//ConvertMHTMLToXPS.SpecifyXpsSaveOptions();
//ConvertMHTMLToXPS.SpecifyCustomStreamProvider();
/**
* ConvertMarkdownToHTML
*/
//ConvertMarkdownToHTML.WithASingleLine();
//ConvertMarkdownToHTML.ConvertMarkdownToPNG();
/**
* HTMLTemplate
*/
//HTMLTemplate.CreateHTMLFromTemplate();
/**
* FineTuningConverters
*/
//FineTuningConverters.SpecifyOutputDevice();
//FineTuningConverters.SpecifyRenderingOptions();
//FineTuningConverters.SpecifyResolution();
//FineTuningConverters.SpecifyBackgroundColor();
//FineTuningConverters.SpecifyLeftRightPageSize();
//FineTuningConverters.AdjustPageSizeToContent();
//FineTuningConverters.SpecifyPDFPermissions();
//FineTuningConverters.SpecifyImageSpecificOptions();
//FineTuningConverters.SpecifyXpsRenderingOptions();
//FineTuningConverters.CombineMultipleHTMLToPDF();
//FineTuningConverters.RendererTimeoutExample();
/**
* WebScraping
*/
//WebScraping.WebScraping.NavigateThroughHTML();
//WebScraping.WebScraping.NodeFilterUsageExample();
//WebScraping.WebScraping.XPathQueryUsageExample();
//WebScraping.WebScraping.CSSSelectorUsageExample();
/**
* HTML5Canvas
*/
//HTML5Canvas.ManipulateUsingJavaScript();
//HTML5Canvas.ManipulateUsingCode();
/**
* OutputStreams
*/
//OutputStreams.StreamProviderUsageExample();
/**
* DOMMutationObserver
*/
//DOMMutationObserver.ObserveHowNodesAreAdded();
/**
* HTMLFormEditor
*/
//HTMLFormEditor.FillFormAndSubmitIt();
/**
* CSSExtensions
*/
//CSSExtensions.AddTitleAndPageNumber();
/**
* Document
*/
//// =====================================================
//CreateSimpleDocument.Run();
//LoadHtmlDoc.Run();
//LoadHTMLdocAsyn.EventNavigate();
//LoadHTMLdocAsyn.Run();
//LoadHtmlDocWithCredentials.Run();
//LoadHtmlUsingRemoteServer.Run();
//LoadHtmlUsingURL.Run();
//ManipulateCanvas.Run();
//ReadInnerHtml.Run();
/**
* Conversions
*/
//AdjustPdfPageSize.Run();
//AdjustXPSPageSize.Run();
//CanvasToPDF.Run();
//EPUBtoImage.Run();
//EPUBtoPDF.Run();
//EPUBtoXPS.Run();
//HTMLtoBMP.Run();
//HTMLtoGIF.Run();
//HTMLtoJPEG.Run();
//HTMLtoMarkdown.Run();
//HTMLtoMHTML.Run();
//HTMLtoPDF.Run();
//HTMLtoPNG.Run();
//HTMLtoTIFF.Run();
//HTMLtoXPS.Run();
//MarkdownToHTML.Run();
//MHTMLtoImage.Run();
//MHTMLtoPDF.Run();
//MHTMLtoXPS.Run();
//SVGtoImage.Run();
//SVGtoPDF.Run();
//SVGtoXPS.Run();
/**
* WorkingWithCSS
*/
//// =====================================================
// UseExtendedContentProperty.Run();
/**
* WorkingWithDevices
*/
//// =====================================================
//GenerateEncryptedPDFByPdfDevice.Run();
//GenerateJPGByImageDevice.Run();
//GeneratePNGByImageDevice.Run();
//GenerateXPSByXpsDevice.Run();
/**
* WorkingWithRenderers
*/
//// =====================================================
//RenderEPUBAsXPS.Run();
//RenderHTMLAsPNG.Run();
//RenderingTimeout.IndefiniteTimeout();
//RenderingTimeout.Run();
//RenderMHTMLAsXPS.Run();
//RenderMultipleDocuments.Run();
//RenderSVGDocAsPNG.Run();
/**
* QuickStart
*/
//// =====================================================
// ApplyMeteredLicense.Run();
/**
* MutationObserver
*/
//// =====================================================
// MutationObserverExample.Run();
/**
* Working with Template Merger
*/
//// =====================================================
// MergeHTMLWithXML.Run();
// MergeHTMLWithJson.Run();
/**
* Working with ICreateStream Provider
*/
//// =====================================================
// UseICreateStreamProvider.Run();
System.exit(0);
}
public static String GetDataDir_Data() {
Path resourceDirectory = Paths.get("src","test","resources");
return resourceDirectory.toFile().getAbsolutePath() + "/Data/";
}
}
package com.aspose.html.examples.java;
public class SimpleWait {
public static void main(String... args) {
var html =
new Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad();
var htmlDocumentWaiter = new HTMLDocumentWaiter(html);
new Thread(htmlDocumentWaiter, "html").start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment