Hello World! I love HTML!
"; + java.io.InputStream is = new java.io.ByteArrayInputStream(code.getBytes()); + + // Initialize a document from the stream variable + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(is, "."); + + // Save the document to a disk + document.save("load-from-stream.html"); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromString.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromString.java new file mode 100644 index 0000000..d3d6545 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromString.java @@ -0,0 +1,16 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_LoadFromString { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_LoadFromString + // Prepare HTML code + String html_code = "Hello World!
"; + + // Initialize a document from the string variable + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(html_code, "."); + + // Save the document to a disk + document.save("create-from-string.html"); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromURL.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromURL.java new file mode 100644 index 0000000..769c01f --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromURL.java @@ -0,0 +1,12 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_LoadFromURL { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_LoadFromURL + // Load a document from 'https://docs.aspose.com/html/net/creating-a-document/document.html' web page + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("https://docs.aspose.com/html/net/creating-a-document/document.html"); + + System.out.println(document.getDocumentElement().getOuterHTML()); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_NewHTML.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_NewHTML.java new file mode 100644 index 0000000..5130cb0 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_NewHTML.java @@ -0,0 +1,26 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_NewHTML { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_NewHTML + // Initialize an empty HTML Document. + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + // Prepare an output path for a document saving + String documentPath = "create-new-document.html"; + + 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 a disk + document.save(documentPath); + } finally { + if (document != null) { + document.dispose(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_OnLoad.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_OnLoad.java new file mode 100644 index 0000000..f394f8e --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_OnLoad.java @@ -0,0 +1,32 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_OnLoad { + public static void main(String [] args) throws java.io.IOException, InterruptedException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_SVG + + // Initialize an HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + java.util.concurrent.atomic.AtomicBoolean isLoading = new java.util.concurrent.atomic.AtomicBoolean(false); + + // 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 o, com.aspose.html.dom.events.Event event) { + isLoading.set(true); + } + }); + + // Navigate asynchronously at the specified Uri + document.navigate("https://docs.aspose.com/html/net/creating-a-document/document.html"); + + // Here the document is not loaded yet + + // Wait 5 seconds for the file to load + Thread.sleep(5000); + + // Here is the loaded document + System.out.println("outerHTML = " + document.getDocumentElement().getOuterHTML()); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_SVG.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_SVG.java new file mode 100644 index 0000000..2effd27 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_SVG.java @@ -0,0 +1,13 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_SVG { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_SVG + // Initialize an SVG document from a string object + com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument("", "."); + + // Write the document content to the output stream + System.out.println(document.getDocumentElement().getOuterHTML()); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_DocumentTree.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_DocumentTree.java new file mode 100644 index 0000000..e9045e1 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_DocumentTree.java @@ -0,0 +1,30 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_EditDocuments_DocumentTree { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EditDocuments_DocumentTree + // Create an instance of an HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + com.aspose.html.HTMLElement body = document.getBody(); + + // Create a paragraph element + com.aspose.html.HTMLParagraphElement p = (com.aspose.html.HTMLParagraphElement) document.createElement("p"); + + // Set a custom attribute + p.setAttribute("id", "my-paragraph"); + + // Create a text node + com.aspose.html.dom.Text text = document.createTextNode("my first paragraph"); + + // Add the text to the paragraph + p.appendChild(text); + + // Attach paragraph to the document body + body.appendChild(p); + + // Save the HTML document to a file + document.save("edit-document-tree.html"); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_DocumentTree2.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_DocumentTree2.java new file mode 100644 index 0000000..23436a7 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_DocumentTree2.java @@ -0,0 +1,41 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_EditDocuments_DocumentTree2 { + public static void main(String [] args) throws java.io.IOException { + + // START_SNIPPET WorkingWithHTMLDocuments_EditDocuments_DocumentTree2 + // Create an instance of an HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + // Create a 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 the style element to the header + com.aspose.html.dom.Element head = document.getElementsByTagName("head").get_Item(0); + head.appendChild(style); + + // Create a paragraph element with class-name 'gr'. + com.aspose.html.HTMLParagraphElement p = (com.aspose.html.HTMLParagraphElement) document.createElement("p"); + p.setClassName("gr"); + + // Create a 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); + + // Save the HTML document to a file + document.save("using-dom.html"); + + // Create an 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("using-dom.pdf"); + + // Render HTML to PDF + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_ExternalCSS.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_ExternalCSS.java new file mode 100644 index 0000000..3d86606 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_ExternalCSS.java @@ -0,0 +1,42 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_EditDocuments_ExternalCSS { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EditDocuments_ExternalCSS + String content = "Internal CSS
An internal CSS is used to define a style for a single HTML page
External
\r\n" + + "CSS
\r\n"; + + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(htmlContent, "."); + + // Save the HTML document to a file + document.save("edit-external-css.html"); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InlineCSS.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InlineCSS.java new file mode 100644 index 0000000..ecdc130 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InlineCSS.java @@ -0,0 +1,24 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_EditDocuments_InlineCSS { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EditDocuments_InlineCSS + // Create an instance of an HTML document with specified content + String content = "Inline CSS
"; + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(content, "."); + + // Find the paragraph element to set a style attribute + com.aspose.html.HTMLElement paragraph = (com.aspose.html.HTMLElement) document.getElementsByTagName("p").get_Item(0); + + // Set the style attribute + paragraph.setAttribute("style", "font-size: 250%; font-family: verdana; color: #cd66aa"); + + // Save the HTML document to a file + document.save("edit-inline-css.html"); + + // 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("edit-inline-css.pdf"); + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InnerOuterHTMLProperties.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InnerOuterHTMLProperties.java new file mode 100644 index 0000000..fc7335e --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InnerOuterHTMLProperties.java @@ -0,0 +1,19 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_EditDocuments_InnerOuterHTMLProperties { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EditDocuments_InnerOuterHTMLProperties + // Create an instance of an HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + // Write the content of the HTML document into the console output + System.out.println(document.getDocumentElement().getOuterHTML()); // output: + + // Set the content of the body element + document.getBody().setInnerHTML("HTML is the standard markup language for Web pages.
"); + + // Write the content of the HTML document into the console output + System.out.println(document.getDocumentElement().getOuterHTML()); // output:HTML is the standard markup language for Web pages.
+ // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InternalCSS.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InternalCSS.java new file mode 100644 index 0000000..d4119c2 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_InternalCSS.java @@ -0,0 +1,47 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EditDocuments_InternalCSS { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EditDocuments_InternalCSS + // Create an instance of an HTML document with specified content + String content = "Internal CSS
An internal CSS is used to define a style for a single HTML page
The CharSet property sets the primary character-set for a document.
\r\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 { + // 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"); + + // Initialize an HTML document with specified configuration + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("user-agent-charset.html", configuration); + try { + // Convert HTML to PDF + com.aspose.html.converters.Converter.convertHTML( + document, + new com.aspose.html.saving.PdfSaveOptions(), + "user-agent-charset_out.pdf" + ); + } finally { + if (document != null) { + document.dispose(); + } + } + } finally { + if (configuration != null) { + configuration.dispose(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_Font.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_Font.java new file mode 100644 index 0000000..ed1553a --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_Font.java @@ -0,0 +1,50 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EnvironmentConfiguration_Font { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_Font + // Prepare an HTML code and save it to the file. + String code = "The FontsSettings property is used for configuration of fonts handling.
\r\n"; + + try (java.io.FileWriter fileWriter = new java.io.FileWriter("user-agent-fontsetting.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 style parameters for the "h1" and "p" elements + userAgent.setUserStyleSheet("h1 { color:#a52a2a; }\r\n" + + "p { color:grey; }\r\n"); + + // Set custom font folder path + userAgent.getFontsSettings().setFontsLookupFolder("fonts"); + + // Initialize an HTML document with specified configuration + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("user-agent-fontsetting.html", configuration); + try { + // Convert HTML to PDF + com.aspose.html.converters.Converter.convertHTML( + document, + new com.aspose.html.saving.PdfSaveOptions(), + "user-agent-fontsetting_out.pdf" + ); + } finally { + if (document != null) { + document.dispose(); + } + } + } finally { + if (configuration != null) { + configuration.dispose(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_MessageHandlers.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_MessageHandlers.java new file mode 100644 index 0000000..2d7a3e8 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_MessageHandlers.java @@ -0,0 +1,58 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EnvironmentConfiguration_MessageHandlers { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_MessageHandlers + // Prepare an HTML code with missing image file + String code = "The Runtime Service optimizes your system by helping it start apps and programs faster.
\r\n"; + + try (java.io.FileWriter fileWriter = new java.io.FileWriter("runtime-service.html")) { + fileWriter.write(code); + } + + // Create an instance of Configuration + com.aspose.html.Configuration configuration = new com.aspose.html.Configuration(); + try { + // Limit JS execution time to 5 seconds + com.aspose.html.services.IRuntimeService runtimeService = configuration.getService(com.aspose.html.services.IRuntimeService.class); + runtimeService.setJavaScriptTimeout(com.aspose.html.utils.TimeSpan.fromSeconds(5)); + + + // Initialize an HTML document with specified configuration + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("runtime-service.html", configuration); + try { + // Convert HTML to PNG + com.aspose.html.converters.Converter.convertHTML( + document, + new com.aspose.html.saving.ImageSaveOptions(), + "runtime-service_out.png" + ); + } finally { + if (document != null) { + document.dispose(); + } + } + } finally { + if (configuration != null) { + configuration.dispose(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_Sandboxing.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_Sandboxing.java new file mode 100644 index 0000000..00dd6e5 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_Sandboxing.java @@ -0,0 +1,43 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EnvironmentConfiguration_Sandboxing { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_Sandboxing + // Prepare an HTML code and save it to the file. + String code = "Hello World!!\n" + + "\n"; + + try (java.io.FileWriter fileWriter = new java.io.FileWriter("sandboxing.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("sandboxing.html", configuration); + try { + // Convert HTML to PDF + com.aspose.html.converters.Converter.convertHTML( + document, + new com.aspose.html.saving.PdfSaveOptions(), + "sandboxing_out.pdf" + ); + } finally { + if (document != null) { + document.dispose(); + } + } + } finally { + if (configuration != null) { + configuration.dispose(); + } + } + // END_SNIPPET + } +} \ No newline at end of file diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_UserStyleSheet.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_UserStyleSheet.java new file mode 100644 index 0000000..ba7a732 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_UserStyleSheet.java @@ -0,0 +1,47 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EnvironmentConfiguration_UserStyleSheet { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_UserStyleSheet + // Prepare an HTML code and save it to the file. + String code = "The User Agent Service allows you to specify a custom user stylesheet, a primary character set for the document, language and fonts settings.
\r\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 { + // 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("h1 { color:#a52a2a;; font-size:2em;}\r\n" + + "p { background-color:GhostWhite; color:SlateGrey; font-size:1.2em; }\r\n"); + + // Initialize an HTML document with specified configuration + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("user-agent-stylesheet.html", configuration); + try { + // Convert HTML to PDF + com.aspose.html.converters.Converter.convertHTML( + document, + new com.aspose.html.saving.PdfSaveOptions(), + "user-agent-stylesheet_out.pdf" + ); + } finally { + if (document != null) { + document.dispose(); + } + } + } finally { + if (configuration != null) { + configuration.dispose(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTML.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTML.java new file mode 100644 index 0000000..ccbbb98 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTML.java @@ -0,0 +1,22 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_SaveDocuments_SaveHTML { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_SaveDocuments_SaveHTML + // Prepare an output path for a document saving + String documentPath = "save-to-file.html"; + + // Initialize an empty HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + // Create a text node and add it to the document + com.aspose.html.dom.Text text = document.createTextNode("Hello World!"); + document.getBody().appendChild(text); + + // Save the HTML document to the file on a disk + document.save(documentPath); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToFile.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToFile.java new file mode 100644 index 0000000..5f1d7eb --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToFile.java @@ -0,0 +1,30 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToFile { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToFile + // Prepare an output path for a document + String documentPath = "save-with-linked-file.html"; + + // Prepare a simple HTML file with a linked document + java.nio.file.Files.write(java.nio.file.Paths.get(documentPath), "Hello World!
linked file".getBytes()); + // Prepare a simple linked HTML file + java.nio.file.Files.write(java.nio.file.Paths.get("linked.html"), "Hello linked file!
".getBytes()); + + // Load the "save-with-linked-file.html" into memory + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(documentPath); + + // Create a save options instance + com.aspose.html.saving.HTMLSaveOptions options = new com.aspose.html.saving.HTMLSaveOptions(); + + // The following line with value '0' cuts 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 with the save options + document.save("save-with-linked-file_out.html", options); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMHTML.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMHTML.java new file mode 100644 index 0000000..be9e1e3 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMHTML.java @@ -0,0 +1,23 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMHTML { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMHTML + // Prepare an output path for a document saving + String documentPath = "save-to-MTHML.mht"; + + // Prepare a simple HTML file with a linked document + java.nio.file.Files.write(java.nio.file.Paths.get("document.html"), "Hello World!
linked file".getBytes()); + // Prepare a simple linked HTML file + java.nio.file.Files.write(java.nio.file.Paths.get("linked-file.html"), "Hello linked file!
".getBytes()); + + // Load the "document.html" into memory + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); + + // Save the document to MHTML format + document.save(documentPath, com.aspose.html.saving.HTMLSaveFormat.MHTML); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMarkdown.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMarkdown.java new file mode 100644 index 0000000..f18ff22 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMarkdown.java @@ -0,0 +1,21 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMarkdown { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_SaveDocuments_SaveHTMLToMarkdown + // Prepare an output path for a document saving + String documentPath = "save-to-MD.md"; + + // Prepare HTML code + String html_code = "