diff --git a/build.gradle b/build.gradle index ec03471..14e1c75 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,7 @@ dependencies { "org.junit.jupiter:junit-jupiter-params:5.9.2", "org.junit.platform:junit-platform-runner:1.9.2", // 'com.github.javaparser:javaparser-core:3.16.1', + 'com.aspose:aspose-html:23.5.1:jdk1.8' ) } diff --git a/pom.xml b/pom.xml index 316191e..2718656 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 3.8.1 5.6.1 1.6.1 - 20.8 + 23.5.1 UTF-8 @@ -35,6 +35,7 @@ aspose-html ${com.aspose.html} jar + jdk1.8 diff --git a/src/test/java/com/aspose/html/documentation/examples/Advanced_CSSExtension.java b/src/test/java/com/aspose/html/documentation/examples/Advanced_CSSExtension.java new file mode 100644 index 0000000..83fab9f --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/Advanced_CSSExtension.java @@ -0,0 +1,46 @@ +package com.aspose.html.documentation.examples; + +public class Advanced_CSSExtension { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET Advanced_CSSExtension + // For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET + // Initialize configuration object and set up the page-margins for the document + + com.aspose.html.Configuration configuration = new com.aspose.html.Configuration(); + + // 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" + + " /* 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" + + " -aspose-content: \"Page \" currentPageNumber() \" of \" totalPagesNumber();\n" + + " color: green;\n" + + " }\n" + + " /* Page title located at the top-center box */\n" + + " @top-center {\n" + + " -aspose-content: \"Hello World Document Title!!!\";\n" + + " vertical-align: bottom;\n" + + " color: blue;\n" + + " }\n" + + "}" + ); + + // Initialize an HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("
Hello World!!!
", ".", configuration); + + // Initialize an output device + com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice("output/output.xps"); + + // Send the document to the output device + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/Advanced_CanvasRenderingContext2D.java b/src/test/java/com/aspose/html/documentation/examples/Advanced_CanvasRenderingContext2D.java new file mode 100644 index 0000000..992a3ad --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/Advanced_CanvasRenderingContext2D.java @@ -0,0 +1,45 @@ +package com.aspose.html.documentation.examples; + +public class Advanced_CanvasRenderingContext2D { + public static void main(String[] args) throws java.io.IOException { + // START_SNIPPET Advanced_HTML5Canvas + // For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-Java + // Create an empty HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + 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, 500); + + // 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.pdf"); + + // Render HTML5 Canvas to PDF + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/Advanced_HTML5Canvas.java b/src/test/java/com/aspose/html/documentation/examples/Advanced_HTML5Canvas.java new file mode 100644 index 0000000..ad3f890 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/Advanced_HTML5Canvas.java @@ -0,0 +1,26 @@ +package com.aspose.html.documentation.examples; + +public class Advanced_HTML5Canvas { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET Advanced_HTML5Canvas + // For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-Java + // Prepare a document with HTML5 Canvas inside and save it to the file 'document.html' + String code = "" + + ""; + java.io.FileWriter fileWriter = new java.io.FileWriter("document.html"); + fileWriter.write(code); + fileWriter.close(); + + // Initialize an HTML document from the html file + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("document.html"); + + com.aspose.html.converters.Converter.convertHTML(document, new com.aspose.html.saving.PdfSaveOptions(), "output.pdf"); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/Advanced_HTMLFormEditor.java b/src/test/java/com/aspose/html/documentation/examples/Advanced_HTMLFormEditor.java new file mode 100644 index 0000000..a28212b --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/Advanced_HTMLFormEditor.java @@ -0,0 +1,50 @@ +package com.aspose.html.documentation.examples; + +public class Advanced_HTMLFormEditor { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET Advanced_HTMLFormEditor + // For complete examples and data files, please go to https://github.com/aspose-html/Aspose.HTML-for-.NET + // 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"); + + // Create an instance of Form Editor + com.aspose.html.forms.FormEditor editor = com.aspose.html.forms.FormEditor.create(document, 0); + + // You can fill the data up using direct access to the input elements, like this: + com.aspose.html.forms.InputElement custname = editor.addInput("custname"); + custname.setValue("John Doe"); + + document.save("output/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 dictionary = new java.util.HashMap<>(); + dictionary.put("custemail", "john.doe@gmail.com"); + dictionary.put("custtel", "+1202-555-0290"); + + // Create an instance of form submitter + com.aspose.html.forms.FormSubmitter submitter = new com.aspose.html.forms.FormSubmitter(editor); + + // 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 doc = result.loadDocument(); + // Inspect HTML document here. + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/Advanced_MemoryStreamToFile.java b/src/test/java/com/aspose/html/documentation/examples/Advanced_MemoryStreamToFile.java new file mode 100644 index 0000000..009b9b9 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/Advanced_MemoryStreamToFile.java @@ -0,0 +1,20 @@ +package com.aspose.html.documentation.examples; + +public class Advanced_MemoryStreamToFile { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET Advanced_MemoryStreamToFile + MemoryStreamProvider streamProvider = new MemoryStreamProvider(); + + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("Hello World!!"); + + 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 memory = streamProvider.lStream.get(0); + memory.reset(); + + java.io.FileOutputStream fs = new java.io.FileOutputStream("output.jpg"); + java.nio.file.Files.copy(memory, new java.io.File("output.jpg").toPath()); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/Advanced_MutationObserver.java b/src/test/java/com/aspose/html/documentation/examples/Advanced_MutationObserver.java new file mode 100644 index 0000000..f42263d --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/Advanced_MutationObserver.java @@ -0,0 +1,41 @@ +package com.aspose.html.documentation.examples; + +public class Advanced_MutationObserver { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET Advanced_MutationObserver + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + 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(com.aspose.html.utils.collections.generic.IGenericList mutations, com.aspose.html.dom.mutations.MutationObserver mutationObserver) { + for (int i = 0 ; i < mutations.size(); i++) { + com.aspose.html.dom.mutations.MutationRecord record = mutations.get_Item(i); + for (com.aspose.html.dom.Node node : record.getAddedNodes().toArray()) { + System.out.println("The '" + node + "' node was added to the document."); + } + } + } + }); + + // 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); + + System.out.println("Waiting for mutation. Press any key to continue..."); + System.in.read(); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/CredentialHandler.java b/src/test/java/com/aspose/html/documentation/examples/CredentialHandler.java new file mode 100644 index 0000000..1e8ff5e --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/CredentialHandler.java @@ -0,0 +1,19 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.INetworkOperationContext; +import com.aspose.html.net.MessageHandler; + +// START_SNIPPET MessageHandlers_CredentialHandler + +public class CredentialHandler extends MessageHandler { + @Override + public void invoke(INetworkOperationContext context) { + // TODO: NetworkCredential is hidden class +// context.getRequest().setCredentials(new com.aspose.ms.System.Net.NetworkCredential("username", "securelystoredpassword"); + context.getRequest().setPreAuthenticate(true); + + a(context); + } +} + +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/CustomSchemaMessageFilter.java b/src/test/java/com/aspose/html/documentation/examples/CustomSchemaMessageFilter.java new file mode 100644 index 0000000..0e855c4 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/CustomSchemaMessageFilter.java @@ -0,0 +1,21 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.INetworkOperationContext; +import com.aspose.html.net.MessageFilter; + +// START_SNIPPET MessageHandlers_CustomeShemaMessageFilter +public class CustomSchemaMessageFilter extends MessageFilter { + + private final String schema; + + CustomSchemaMessageFilter(String schema) { + this.schema = schema; + } + + @Override + public boolean match(INetworkOperationContext context) { + String protocol = context.getRequest().getRequestUri().getProtocol(); + return (schema+":").equals(protocol); + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/CustomSchemaMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/CustomSchemaMessageHandler.java new file mode 100644 index 0000000..4a257c5 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/CustomSchemaMessageHandler.java @@ -0,0 +1,12 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.MessageHandler; + +// START_SNIPPET MessageHandlers_CustomeShemaMessageHandler +public abstract class CustomSchemaMessageHandler extends MessageHandler { + + protected CustomSchemaMessageHandler(String schema) { + getFilters().addItem(new CustomSchemaMessageFilter(schema)); + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/LogMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/LogMessageHandler.java new file mode 100644 index 0000000..38b9655 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/LogMessageHandler.java @@ -0,0 +1,16 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.INetworkOperationContext; +import com.aspose.html.net.MessageHandler; + +public class LogMessageHandler extends MessageHandler { + @Override + public void invoke(INetworkOperationContext context) { + System.out.println("Start processing request: " + context.getRequest().getRequestUri()); + + // Invoke the next message handler in the chain + a(context); + + System.out.println("Finish processing request: " + context.getRequest().getRequestUri()); + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/MemoryStreamProvider.java b/src/test/java/com/aspose/html/documentation/examples/MemoryStreamProvider.java new file mode 100644 index 0000000..25ec0c9 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MemoryStreamProvider.java @@ -0,0 +1,17 @@ +// START_SNIPPET Advanced_MemoryStreamProvider +package com.aspose.html.documentation.examples; + +// 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 lStream = new java.util.ArrayList<>(); + + @Override + public void close() throws java.io.IOException { + for (java.io.InputStream stream : lStream) { + stream.close(); + } + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_CredentialsPipeline.java b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_CredentialsPipeline.java new file mode 100644 index 0000000..7bd4bdd --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_CredentialsPipeline.java @@ -0,0 +1,23 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Configuration; +import com.aspose.html.HTMLDocument; +import com.aspose.html.net.MessageHandlerCollection; +import com.aspose.html.services.INetworkService; + +public class MessageHandlers_CredentialsPipeline { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET MessageHandlers_CredentialsPipeline + // Create an instance of the Configuration class + Configuration configuration = new Configuration(); + + // Add the CredentialHandler to the chain of existing message handlers + INetworkService service = configuration.getService(INetworkService.class); + MessageHandlerCollection handlers = service.getMessageHandlers(); + handlers.insertItem(0, new CredentialHandler()); + + // Initialize an HTML document with specified configuration + HTMLDocument document = new HTMLDocument("https://httpbin.org/basic-auth/username/securelystoredpassword", configuration); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_CustomMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_CustomMessageHandler.java new file mode 100644 index 0000000..3f7a616 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_CustomMessageHandler.java @@ -0,0 +1,28 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Configuration; +import com.aspose.html.HTMLDocument; +import com.aspose.html.net.MessageHandlerCollection; +import com.aspose.html.services.INetworkService; + +public class MessageHandlers_CustomMessageHandler { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET MessageHandlers_CustomMessageHandler + // Create an instance of the Configuration class + Configuration configuration = new Configuration(); + + // Add the LogMessageHandler to the chain of existing message handlers + INetworkService service = configuration.getService(INetworkService.class); + MessageHandlerCollection handlers = service.getMessageHandlers(); + + handlers.insertItem(0, new LogMessageHandler()); + + // Prepare path to a source document file + String documentPath = "input/input.htm"; + + // Initialize an HTML document with specified configuration + HTMLDocument document = new HTMLDocument(documentPath, configuration); + // END_SNIPPET + } +} + diff --git a/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_NetworkTimeout.java b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_NetworkTimeout.java new file mode 100644 index 0000000..e73ebff --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_NetworkTimeout.java @@ -0,0 +1,30 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Configuration; +import com.aspose.html.converters.Converter; +import com.aspose.html.saving.PdfSaveOptions; +import com.aspose.html.services.INetworkService; + +public class MessageHandlers_NetworkTimeout { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET MessageHandlers_NetworkTimeout + // Create an instance of the Configuration class + Configuration configuration = new Configuration(); + + // Call the INetworkService which contains the functionality for managing network operations + INetworkService network = configuration.getService(INetworkService.class); + + // Add the TimeoutMessageHandler to the top of existing message handler chain + network.getMessageHandlers().insertItem(0, new TimeoutMessageHandler()); + + // Prepare path to a source document file + String documentPath = "input/document.html"; + + // Prepare a path for converted file saving + String savePath = "output/document.pdf"; + + // Convert HTML to PDF with customized configuration + Converter.convertHTML(documentPath, configuration, new PdfSaveOptions(), savePath); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_Pipeline.java b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_Pipeline.java new file mode 100644 index 0000000..8a49de7 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_Pipeline.java @@ -0,0 +1,42 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Configuration; +import com.aspose.html.HTMLDocument; +import com.aspose.html.net.MessageHandlerCollection; +import com.aspose.html.rendering.pdf.PdfDevice; +import com.aspose.html.services.INetworkService; + +public class MessageHandlers_Pipeline { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET MessageHandlers_Pipeline + // Prepare path to a source zip file + String documentPath = "input/test.zip"; + + // Prepare path for converted file saving + String savePath = "output/zip-to-pdf-duration.pdf"; + + // Create an instance of the Configuration class + Configuration configuration = new Configuration(); + INetworkService service = configuration.getService(INetworkService.class); + MessageHandlerCollection handlers = service.getMessageHandlers(); + + // Custom Schema: ZIP. Add ZipFileSchemaMessageHandler to the end of the pipeline + handlers.addItem(new ZIPFileSchemaMessageHandler(documentPath)); + + // Duration Logging. Add the StartRequestDurationLoggingMessageHandler at the first place in the pipeline + handlers.insertItem(0, new StartRequestDurationLoggingMessageHandler()); + + // Add the StopRequestDurationLoggingMessageHandler to the end of the pipeline + handlers.addItem(new StopRequestDurationLoggingMessageHandler()); + + // Initialize an HTML document with specified configuration + HTMLDocument document = new HTMLDocument("zip-file:///test.html", configuration); + + // Create the PDF Device + PdfDevice device = new PdfDevice(savePath); + + // Render ZIP to PDF + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_WebRequestExecution.java b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_WebRequestExecution.java new file mode 100644 index 0000000..ebea046 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_WebRequestExecution.java @@ -0,0 +1,29 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Configuration; +import com.aspose.html.HTMLDocument; +import com.aspose.html.converters.Converter; +import com.aspose.html.net.MessageHandlerCollection; +import com.aspose.html.saving.PdfSaveOptions; +import com.aspose.html.services.INetworkService; + +public class MessageHandlers_WebRequestExecution { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET MessageHandlers_WebRequestExecution + // Create an instance of the Configuration class + Configuration configuration = new Configuration(); + + // Add the TimeLoggerMessageHandler to the chain of existing message handlers + INetworkService service = configuration.getService(INetworkService.class); + MessageHandlerCollection handlers = service.getMessageHandlers(); + + handlers.insertItem(0, new TimeLoggerMessageHandler()); + + // Prepare path to a source document file + String documentPath = "input/input.htm"; + + // Initialize an HTML document with specified configuration + HTMLDocument document = new HTMLDocument(documentPath, configuration); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_ZIPtoJPG.java b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_ZIPtoJPG.java new file mode 100644 index 0000000..ac31dbf --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_ZIPtoJPG.java @@ -0,0 +1,42 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Configuration; +import com.aspose.html.HTMLDocument; +import com.aspose.html.rendering.image.ImageDevice; +import com.aspose.html.rendering.image.ImageFormat; +import com.aspose.html.rendering.image.ImageRenderingOptions; +import com.aspose.html.services.INetworkService; + +public class MessageHandlers_ZIPtoJPG { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET MessageHandlers_ZIPtoJPG + // Prepare path to a source zip file + String documentPath = "input/test.zip"; + + // Prepare path for converted file saving + String savePath = "output/zip-to-jpg.jpg"; + + // Create an instance of ZipArchiveMessageHandler + ZIPArchiveMessageHandler zip = new ZIPArchiveMessageHandler(documentPath); + + // Create an instance of the Configuration class + Configuration configuration = new Configuration(); + + // Add ZipArchiveMessageHandler to the chain of existing message handlers + configuration.getService(INetworkService.class).getMessageHandlers().addItem(zip); + + // Initialize an HTML document with specified configuration + HTMLDocument document = new HTMLDocument("zip:///test.html", configuration); + + // Create an instance of Rendering Options + ImageRenderingOptions options = new ImageRenderingOptions(); + options.setFormat(ImageFormat.Jpeg); + + // Create an instance of Image Device + ImageDevice device = new ImageDevice(options, savePath); + + // Render ZIP to JPG + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_ZIPtoPDF.java b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_ZIPtoPDF.java new file mode 100644 index 0000000..db68675 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/MessageHandlers_ZIPtoPDF.java @@ -0,0 +1,36 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Configuration; +import com.aspose.html.HTMLDocument; +import com.aspose.html.net.MessageHandlerCollection; +import com.aspose.html.rendering.pdf.PdfDevice; +import com.aspose.html.services.INetworkService; + +public class MessageHandlers_ZIPtoPDF { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET MessageHandlers_ZIPtoPDF + // Prepare path to a source zip file + String documentPath = "input/test.zip"; + + // Prepare path for converted file saving + String savePath = "output/zip-to-pdf.pdf"; + + // Create an instance of the Configuration class + Configuration configuration = new Configuration(); + + // Add the LogMessageHandler to the chain of existing message handlers + INetworkService service = configuration.getService(INetworkService.class); + MessageHandlerCollection handlers = service.getMessageHandlers(); + + handlers.insertItem(0, new ZIPArchiveMessageHandler(documentPath)); + + HTMLDocument document = new HTMLDocument("zip:///test.html", configuration); + + // Create the PDF Device + PdfDevice device = new PdfDevice(savePath); + + // Render ZIP to PDF + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/RequestDurationLoggingMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/RequestDurationLoggingMessageHandler.java new file mode 100644 index 0000000..af8918e --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/RequestDurationLoggingMessageHandler.java @@ -0,0 +1,27 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.Url; +import com.aspose.html.net.MessageHandler; +import com.aspose.html.utils.TimeSpan; + +import java.util.HashMap; +import java.util.Map; + +// START_SNIPPET MessageHandlers_RequestDurationLoggingMessageHandler +public abstract class RequestDurationLoggingMessageHandler extends MessageHandler { + + private static Map requests = new HashMap<>(); + + protected void startTimer(Url url) + { + requests.put(url, System.currentTimeMillis()); + } + + protected TimeSpan stopTimer(Url url) + { + long end = System.currentTimeMillis(); + long start = requests.get(url); + return new TimeSpan(end - start); + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/StartRequestDurationLoggingMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/StartRequestDurationLoggingMessageHandler.java new file mode 100644 index 0000000..a52340c --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/StartRequestDurationLoggingMessageHandler.java @@ -0,0 +1,17 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.INetworkOperationContext; + +// START_SNIPPET MessageHandlers_StartRequestDurationLoggingMessageHandler +public class StartRequestDurationLoggingMessageHandler extends RequestDurationLoggingMessageHandler { + + @Override + public void invoke(INetworkOperationContext context) { + // Start the stopwatch + startTimer(context.getRequest().getRequestUri()); + + // Invoke the next message handler in the chain + a(context); + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/StopRequestDurationLoggingMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/StopRequestDurationLoggingMessageHandler.java new file mode 100644 index 0000000..32657b2 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/StopRequestDurationLoggingMessageHandler.java @@ -0,0 +1,17 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.INetworkOperationContext; + +// START_SNIPPET MessageHandlers_StopRequestDurationLoggingMessageHandler +public class StopRequestDurationLoggingMessageHandler extends RequestDurationLoggingMessageHandler { + + @Override + public void invoke(INetworkOperationContext context) { + // Start the stopwatch + stopTimer(context.getRequest().getRequestUri()); + + // Invoke the next message handler in the chain + a(context); + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/TimeLoggerMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/TimeLoggerMessageHandler.java new file mode 100644 index 0000000..027842b --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/TimeLoggerMessageHandler.java @@ -0,0 +1,25 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.INetworkOperationContext; +import com.aspose.html.net.MessageHandler; + +// START_SNIPPET MessageHandlers_TimeLoggerMessageHandler + +public class TimeLoggerMessageHandler extends MessageHandler { + @Override + public void invoke(INetworkOperationContext context) { + // Start the stopwatch + long start = System.currentTimeMillis(); + + // Invoke the next message handler in the chain + a(context); + + // Stop the stopwatch + long end = System.currentTimeMillis(); + + // Print the result + System.out.println("Request: " + context.getRequest().getRequestUri()); + System.out.println("Time: " + (end - start) + "ms"); + } +} +// END_SNIPPET \ No newline at end of file diff --git a/src/test/java/com/aspose/html/documentation/examples/TimeoutMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/TimeoutMessageHandler.java new file mode 100644 index 0000000..a30a6d0 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/TimeoutMessageHandler.java @@ -0,0 +1,15 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.net.INetworkOperationContext; +import com.aspose.html.net.MessageHandler; +import com.aspose.html.utils.TimeSpan; + +// START_SNIPPET MessageHandlers_TimeoutMessageHandler +public class TimeoutMessageHandler extends MessageHandler { + @Override + public void invoke(INetworkOperationContext context) { + context.getRequest().setTimeout(TimeSpan.fromSeconds(1)); + a(context); + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_Async.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_Async.java new file mode 100644 index 0000000..891eeec --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_Async.java @@ -0,0 +1,34 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_Async { + public static void main(String [] args) throws java.io.IOException, InterruptedException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_SVG + + + // Create an instance of an HTML document + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + + // Create a string variable for OuterHTML property reading + StringBuilder outerHTML = new StringBuilder(); + + // Subscribe to '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 the '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")) + { + // Fill the outerHTML variable by value of loaded document + outerHTML.append(document.getDocumentElement().getOuterHTML()); + } + } + }); + + Thread.sleep(5000); + + System.out.println("outerHTML = " + outerHTML); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_EmptyHTML.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_EmptyHTML.java new file mode 100644 index 0000000..e24e731 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_EmptyHTML.java @@ -0,0 +1,18 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_EmptyHTML { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_EmptyHTML + // Initialize an empty HTML Document. + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(); + try { + // Save the document to disk. + document.save("create-empty-document.html"); + } finally { + if (document != null) { + document.dispose(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile.java new file mode 100644 index 0000000..a2a7d49 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile.java @@ -0,0 +1,17 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile + // Prepare a 'load-from-file.html' file. + try (java.io.FileWriter fileWriter = new java.io.FileWriter("load-from-file.html")) { + fileWriter.write("Hello World!"); + } + + // Load from a 'load-from-file.html' file. + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("load-from-file.html"); + // 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_CreateDocuments_LoadFromFile2.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile2.java new file mode 100644 index 0000000..66a343d --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile2.java @@ -0,0 +1,15 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile2 { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_LoadFromFile2 + // Prepare a path to a file + String documentPath = "Sprite.html"; + + // Initialize an HTML document from a file + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(documentPath); + + document.save("Sprite_out.html"); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromStream.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromStream.java new file mode 100644 index 0000000..5cba26f --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_CreateDocuments_LoadFromStream.java @@ -0,0 +1,17 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_CreateDocuments_LoadFromStream { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_CreateDocuments_LoadFromStream + // Create a memory stream object + String code = "

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

"; + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(content, "."); + + com.aspose.html.dom.Element style = document.createElement("style"); + style.setTextContent(".frame1 { margin-top:50px; margin-left:50px; padding:20px; width:360px; height:90px; background-color:#a52a2a; font-family:verdana; color:#FFF5EE;} \r\n" + + ".frame2 { margin-top:-90px; margin-left:160px; text-align:center; padding:20px; width:360px; height:100px; background-color:#ADD8E6;}"); + + // 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); + + // Find the first paragraph element to inspect the styles + com.aspose.html.HTMLElement paragraph = (com.aspose.html.HTMLElement) document.getElementsByTagName("p").get_Item(0); + paragraph.setClassName("frame1"); + + // Find the last paragraph element to inspect the styles + com.aspose.html.HTMLElement lastParagraph = (com.aspose.html.HTMLElement) document.getElementsByTagName("p").get_Item(document.getElementsByTagName("p").getLength()-1); + lastParagraph.setClassName("frame2"); + + // Set a font-size to the first paragraph + paragraph.getStyle().setFontSize("250%"); + paragraph.getStyle().setTextAlign("center"); + + // Set a color and font-size to the last paragraph + lastParagraph.getStyle().setColor("#434343"); + lastParagraph.getStyle().setFontSize("150%"); + lastParagraph.getStyle().setFontFamily("verdana"); + + // Save the HTML document to a file + document.save("edit-internal-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-internal-css.pdf"); + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_ExternalCSS2.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_ExternalCSS2.java new file mode 100644 index 0000000..b60b063 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EditDocuments_ExternalCSS2.java @@ -0,0 +1,38 @@ +package com.aspose.html.documentation.examples; + +public class WorkingWithHTMLDocuments_EditDocuments_ExternalCSS2 { + public static void main(String [] args) throws java.io.IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EditDocuments_ExternalCSS2 + // Prepare content for a CSS file + String styleContent = ".flower1 { width:120px; height:40px; border-radius:20px; background:#4387be; margin-top:50px; } \r\n" + + ".flower2 { margin-left:0px; margin-top:-40px; background:#4387be; border-radius:20px; width:120px; height:40px; transform:rotate(60deg); } \r\n" + + ".flower3 { transform:rotate(-60deg); margin-left:0px; margin-top:-40px; width:120px; height:40px; border-radius:20px; background:#4387be; }\r\n" + + ".frame { margin-top:-50px; margin-left:310px; width:160px; height:50px; font-size:2em; font-family:Verdana; color:grey; }\r\n"; + + // Prepare a linked CSS file + java.nio.file.Files.write(java.nio.file.Paths.get("flower.css"), styleContent.getBytes()); + + // Create an instance of an HTML document with specified content + String htmlContent = " \r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "
\r\n" + + "

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

"; + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(content, "."); + + com.aspose.html.dom.Element style = document.createElement("style"); + style.setTextContent(".frame1 { margin-top:50px; margin-left:50px; padding:20px; width:360px; height:90px; background-color:#a52a2a; font-family:verdana; color:#FFF5EE;} \r\n" + + ".frame2 { margin-top:-90px; margin-left:160px; text-align:center; padding:20px; width:360px; height:100px; background-color:#ADD8E6;}"); + + // 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); + + // Find the first paragraph element to inspect the styles + com.aspose.html.HTMLElement paragraph = (com.aspose.html.HTMLElement) document.getElementsByTagName("p").get_Item(0); + paragraph.setClassName("frame1"); + + // Find the last paragraph element to inspect the styles + com.aspose.html.HTMLElement lastParagraph = (com.aspose.html.HTMLElement) document.getElementsByTagName("p").get_Item(document.getElementsByTagName("p").getLength() - 1); + lastParagraph.setClassName("frame2"); + + // Set a font-size to the first paragraph + paragraph.getStyle().setFontSize("250%"); + paragraph.getStyle().setTextAlign("center"); + + // Set a color and font-size to the last paragraph + lastParagraph.getStyle().setColor("#434343"); + lastParagraph.getStyle().setFontSize("150%"); + lastParagraph.getStyle().setFontFamily("verdana"); + + // Save the HTML document to a file + document.save("edit-internal-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-internal-css.pdf"); + + // Render HTML to PDF + document.renderTo(device); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_CharacterSet.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_CharacterSet.java new file mode 100644 index 0000000..1b9badb --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_CharacterSet.java @@ -0,0 +1,46 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EnvironmentConfiguration_CharacterSet { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_CharacterSet + // Prepare an HTML code and save it to the file. + String code = "

Character Set

\r\n" + + "

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 = "

FontsSettings property

\r\n" + + "

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 = ""; + + try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) { + fileWriter.write(code); + } + + // Create MessageHandler + com.aspose.html.net.MessageHandler handler = new com.aspose.html.net.MessageHandler() { + @Override + public void invoke(com.aspose.html.net.INetworkOperationContext context) { + if (context.getResponse().getStatusCode() != 200) + { + System.out.println(String.format("File '%s' Not Found", context.getRequest().getRequestUri().toString())); + } + + // Invoke the next message handler in the chain + a(context); + } + }; + + // 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(handler); + + // 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(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_NetworkService.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_NetworkService.java new file mode 100644 index 0000000..0eeeb76 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_NetworkService.java @@ -0,0 +1,47 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EnvironmentConfiguration_NetworkService { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_NetworkService + // Prepare an HTML code with missing image file + String code = "\r\n" + + "\r\n" + + "\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 { + // Add ErrorMessageHandler to the chain of existing message handlers + com.aspose.html.services.INetworkService network = configuration.getService(com.aspose.html.services.INetworkService.class); + com.aspose.html.net.MessageHandler logHandler = new LogMessageHandler(); + network.getMessageHandlers().addItem(logHandler); + + // 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(); + } + } + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_RuntimeService.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_RuntimeService.java new file mode 100644 index 0000000..afab47d --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_EnvironmentConfiguration_RuntimeService.java @@ -0,0 +1,46 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_EnvironmentConfiguration_RuntimeService { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_RuntimeService + // Prepare an HTML code and save it to the file. + String code = "

Runtime Service

\r\n" + + "\r\n" + + "

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 = "

User Agent Service

\r\n" + + "

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 = "

Hello World!

"; + + // Initialize a document from the string variable + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(html_code, "."); + + // Save the document as a Markdown file + document.save(documentPath, com.aspose.html.saving.HTMLSaveFormat.Markdown); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveSVG.java b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveSVG.java new file mode 100644 index 0000000..693da32 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/WorkingWithHTMLDocuments_SaveSVG.java @@ -0,0 +1,27 @@ +package com.aspose.html.documentation.examples; + +import java.io.IOException; + +public class WorkingWithHTMLDocuments_SaveSVG { + public static void main(String [] args) throws IOException { + // START_SNIPPET WorkingWithHTMLDocuments_SaveSVG + // Prepare an output path for an SVG document saving + String documentPath = "save-to-SVG.svg"; + + // Prepare SVG code + String code = "" + + "" + + "" + + "" + + "" + + "" + + ""; + + // Initialize an SVG instance from the content string + com.aspose.html.dom.svg.SVGDocument document = new com.aspose.html.dom.svg.SVGDocument(code, "."); + + // Save the SVG file to a disk + document.save(documentPath); + // END_SNIPPET + } +} diff --git a/src/test/java/com/aspose/html/documentation/examples/ZIPArchiveMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/ZIPArchiveMessageHandler.java new file mode 100644 index 0000000..1947616 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/ZIPArchiveMessageHandler.java @@ -0,0 +1,54 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.IDisposable; +import com.aspose.html.MimeType; +import com.aspose.html.net.ByteArrayContent; +import com.aspose.html.net.INetworkOperationContext; +import com.aspose.html.net.MessageHandler; +import com.aspose.html.net.ResponseMessage; +import com.aspose.html.net.messagefilters.ProtocolMessageFilter; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +// START_SNIPPET MessageHandlers_ZIPArchiveMessageHandler +public class ZIPArchiveMessageHandler extends MessageHandler implements IDisposable { + + private String filePath; + + // Initialize an instance of the ZipArchiveMessageHandler class + public ZIPArchiveMessageHandler(String path) { + this.filePath = path; + getFilters().addItem(new ProtocolMessageFilter("zip")); + } + + @Override + public void dispose() { + + } + + @Override + public void invoke(INetworkOperationContext context) { + // Call the GetFile() method that defines the logic in the Invoke() method + byte [] buff = new byte[0]; + try { + buff = Files.readAllBytes(Paths.get(context.getRequest().getRequestUri().getPathname().trim())); + } catch (IOException e) { + throw new RuntimeException(e); + } + if (buff != null) { + // Checking: if a resource is found in the archive, then return it as a Response + ResponseMessage msg = new ResponseMessage(200); + msg.setContent(new ByteArrayContent(buff)); + context.getResponse().getHeaders().getContentType().setMediaType(MimeType.fromFileExtension(context.getRequest().getRequestUri().getPathname())); + } + else { + context.setResponse(new ResponseMessage(404)); + } + + // Call the next message handler + a(context); + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/documentation/examples/ZIPFileSchemaMessageHandler.java b/src/test/java/com/aspose/html/documentation/examples/ZIPFileSchemaMessageHandler.java new file mode 100644 index 0000000..60f08a5 --- /dev/null +++ b/src/test/java/com/aspose/html/documentation/examples/ZIPFileSchemaMessageHandler.java @@ -0,0 +1,44 @@ +package com.aspose.html.documentation.examples; + +import com.aspose.html.MimeType; +import com.aspose.html.net.INetworkOperationContext; +import com.aspose.html.net.ResponseMessage; +import com.aspose.html.net.StreamContent; +import com.aspose.html.utils.Stream; + +// START_SNIPPET MessageHandlers_ZIPFileSchemaMessageHandler +public class ZIPFileSchemaMessageHandler extends CustomSchemaMessageHandler { + private final String archive; + + protected ZIPFileSchemaMessageHandler(String archive) { + super("zip-file"); + this.archive = archive; + } + + @Override + public void invoke(INetworkOperationContext context) { + String pathInsideArchive = context.getRequest().getRequestUri().getPathname().substring(1).replaceAll("\\\\", "/"); + Stream stream = GetFile(pathInsideArchive); + + if (stream != null) + { + // Checking: if a resource is found in the archive, then return it as a Response + ResponseMessage response = new ResponseMessage(200); + response.setContent(new StreamContent(stream)); + response.getHeaders().getContentType().setMediaType(MimeType.fromFileExtension(context.getRequest().getRequestUri().getPathname())); + context.setResponse(response); + } + else { + context.setResponse(new ResponseMessage(404)); + } + + // Invoke the next message handler in the chain + a(context); + } + + Stream GetFile(String path) { + // TODO: discuss here how to get zip stream + return null; + } +} +// END_SNIPPET diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_CSSExtensions_AddTitleAndPageNumber.java b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_CSSExtensions_AddTitleAndPageNumber.java index 1516517..5dc7a12 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_CSSExtensions_AddTitleAndPageNumber.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_CSSExtensions_AddTitleAndPageNumber.java @@ -1,63 +1,63 @@ -package com.aspose.html.examples; - -public class Examples_Java_AdvancedUsage_CSSExtensions_AddTitleAndPageNumber { - - @org.junit.jupiter.api.Test - @org.junit.jupiter.api.Disabled - public void execute() throws Exception { - //@START - // 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("
Hello World!!!
", ".", configuration); - try { - // Initialize an output device - com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice(Resources.output("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(); - } - } - //@END - } +package com.aspose.html.examples; + +public class Examples_Java_AdvancedUsage_CSSExtensions_AddTitleAndPageNumber { + + @org.junit.jupiter.api.Test + @org.junit.jupiter.api.Disabled + public void execute() throws Exception { + //@START + // 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("
Hello World!!!
", ".", configuration); + try { + // Initialize an output device + com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice(Resources.output("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(); + } + } + //@END + } } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_DOMMutationObserver_ObserveHowNodesAreAdded.java b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_DOMMutationObserver_ObserveHowNodesAreAdded.java index 1a4c1c3..91496a2 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_DOMMutationObserver_ObserveHowNodesAreAdded.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_DOMMutationObserver_ObserveHowNodesAreAdded.java @@ -1,67 +1,66 @@ -package com.aspose.html.examples; - -import com.aspose.html.dom.mutations.MutationObserver; -import com.aspose.html.dom.mutations.MutationRecord; -import com.aspose.ms.System.Collections.Generic.IGenericList; - -public class Examples_Java_AdvancedUsage_DOMMutationObserver_ObserveHowNodesAreAdded { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // 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( - IGenericList 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(); - } - } - //@END - } +package com.aspose.html.examples; + +import com.aspose.html.dom.mutations.MutationRecord; +import com.aspose.html.utils.collections.generic.IGenericList; + +public class Examples_Java_AdvancedUsage_DOMMutationObserver_ObserveHowNodesAreAdded { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // 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( + IGenericList 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(); + } + } + //@END + } } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingCode.java b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingCode.java index 4c6d512..7057187 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingCode.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingCode.java @@ -1,57 +1,57 @@ -package com.aspose.html.examples; - -public class Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingCode { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // 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(Resources.output("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(); - } - } - //@END - } -} +package com.aspose.html.examples; + +public class Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingCode { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // 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(Resources.output("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(); + } + } + //@END + } +} diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingJavaScript.java b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingJavaScript.java index d6a3938..16c6a93 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingJavaScript.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingJavaScript.java @@ -1,37 +1,37 @@ -package com.aspose.html.examples; - -public class Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingJavaScript { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // 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;' >\n" + - "\n"; - try (java.io.FileWriter fileWriter = new java.io.FileWriter(Resources.output("document.html"))) { - fileWriter.write(code); - } - - // Initialize an HTML document from the html file - com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(Resources.output("document.html")); - try { - // Convert HTML to PDF - com.aspose.html.converters.Converter.convertHTML( - document, - new com.aspose.html.saving.PdfSaveOptions(), - Resources.output("output.pdf") - ); - } finally { - if (document != null) { - document.dispose(); - } - } - //@END - } -} +package com.aspose.html.examples; + +public class Examples_Java_AdvancedUsage_HTML5Canvas_ManipulateUsingJavaScript { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // 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;' >\n" + + "\n"; + try (java.io.FileWriter fileWriter = new java.io.FileWriter(Resources.output("document.html"))) { + fileWriter.write(code); + } + + // Initialize an HTML document from the html file + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(Resources.output("document.html")); + try { + // Convert HTML to PDF + com.aspose.html.converters.Converter.convertHTML( + document, + new com.aspose.html.saving.PdfSaveOptions(), + Resources.output("output.pdf") + ); + } finally { + if (document != null) { + document.dispose(); + } + } + //@END + } +} diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTMLFormEditor_FillFormAndSubmitIt.java b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTMLFormEditor_FillFormAndSubmitIt.java index 3e721fc..94aa252 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTMLFormEditor_FillFormAndSubmitIt.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_AdvancedUsage_HTMLFormEditor_FillFormAndSubmitIt.java @@ -1,73 +1,73 @@ -package com.aspose.html.examples; - -public class Examples_Java_AdvancedUsage_HTMLFormEditor_FillFormAndSubmitIt { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // 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(Resources.output("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 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(); - } - } - //@END - } -} +package com.aspose.html.examples; + +public class Examples_Java_AdvancedUsage_HTMLFormEditor_FillFormAndSubmitIt { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // 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(Resources.output("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 map = new java.util.HashMap<>(); + map.put("custemail", "john.doe@gmail.com"); + map.put("custtel", "+1202-555-0290"); + editor.a(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(); + } + } + //@END + } +} diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustPdfPageSize_AdjustPdfPageSize.java b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustPdfPageSize_AdjustPdfPageSize.java index c59762f..e29d2b7 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustPdfPageSize_AdjustPdfPageSize.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustPdfPageSize_AdjustPdfPageSize.java @@ -1,84 +1,84 @@ -package com.aspose.html.examples; - -public class Examples_Java_Conversion_AdjustPdfPageSize_AdjustPdfPageSize { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("FirstFile.html"))) { - try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(Resources.output("FirstFileOut.html"))) { - byte[] bytes = new byte[fileInputStream.available()]; - fileInputStream.read(bytes); - fileOutputStream.write(bytes); - String style = "\n" + - "
Aspose.Html rendering Text in Black Color
\n" + - "
Aspose.Html rendering Text in Green Color
\n" + - "
Aspose.Html rendering Text in Blue Color
\n" + - "
Aspose.Html rendering Text in Red\n" + - "Color
\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(Resources.output("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 = Resources.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 = Resources.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(); - } - } - } - //@END - } +package com.aspose.html.examples; + +public class Examples_Java_Conversion_AdjustPdfPageSize_AdjustPdfPageSize { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("FirstFile.html"))) { + try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(Resources.output("FirstFileOut.html"))) { + byte[] bytes = new byte[fileInputStream.available()]; + fileInputStream.read(bytes); + fileOutputStream.write(bytes); + String style = "\n" + + "
Aspose.Html rendering Text in Black Color
\n" + + "
Aspose.Html rendering Text in Green Color
\n" + + "
Aspose.Html rendering Text in Blue Color
\n" + + "
Aspose.Html rendering Text in Red\n" + + "Color
\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(Resources.output("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 = Resources.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 = Resources.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(); + } + } + } + //@END + } } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustXPSPageSize_AdjustXPSPageSize.java b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustXPSPageSize_AdjustXPSPageSize.java index 757e4b0..15d08ef 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustXPSPageSize_AdjustXPSPageSize.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_AdjustXPSPageSize_AdjustXPSPageSize.java @@ -1,84 +1,84 @@ -package com.aspose.html.examples; - -public class Examples_Java_Conversion_AdjustXPSPageSize_AdjustXPSPageSize { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // Set input file name. - try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("FirstFile.html"))) { - try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(Resources.output("FirstFileOut.html"))) { - byte[] bytes = new byte[fileInputStream.available()]; - fileInputStream.read(bytes); - fileOutputStream.write(bytes); - String style = "\n" + - "
Aspose.Html rendering Text in Black Color
\n" + - "
Aspose.Html rendering Text in Green Color
\n" + - "
Aspose.Html rendering Text in Blue Color
\n" + - "
Aspose.Html rendering Text in Red Color
\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(Resources.output("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 = Resources.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 = Resources.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(); - } - } - } - //@END - } -} +package com.aspose.html.examples; + +public class Examples_Java_Conversion_AdjustXPSPageSize_AdjustXPSPageSize { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // Set input file name. + try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("FirstFile.html"))) { + try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(Resources.output("FirstFileOut.html"))) { + byte[] bytes = new byte[fileInputStream.available()]; + fileInputStream.read(bytes); + fileOutputStream.write(bytes); + String style = "\n" + + "
Aspose.Html rendering Text in Black Color
\n" + + "
Aspose.Html rendering Text in Green Color
\n" + + "
Aspose.Html rendering Text in Blue Color
\n" + + "
Aspose.Html rendering Text in Red Color
\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(Resources.output("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 = Resources.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 = Resources.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(); + } + } + } + //@END + } +} diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_CanvasToPDF_CanvasToPDF.java b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_CanvasToPDF_CanvasToPDF.java index 15b6e74..3f74650 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_CanvasToPDF_CanvasToPDF.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_CanvasToPDF_CanvasToPDF.java @@ -1,34 +1,34 @@ -package com.aspose.html.examples; - -public class Examples_Java_Conversion_CanvasToPDF_CanvasToPDF { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(Resources.input("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(Resources.output("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(); - } - } - //@END - } +package com.aspose.html.examples; + +public class Examples_Java_Conversion_CanvasToPDF_CanvasToPDF { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument(Resources.input("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(Resources.output("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(); + } + } + //@END + } } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoImage_1.java b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoImage_1.java index cd241f9..4e9c89e 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoImage_1.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoImage_1.java @@ -1,23 +1,23 @@ -package com.aspose.html.examples; - -public class Examples_Java_Conversion_EPUBtoImage_1 { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // Source EPUB document - try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("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 = Resources.output("EPUBtoImageOutput.jpeg"); - // Convert SVG to Image - com.aspose.html.converters.Converter.convertEPUB( - fileInputStream, - options, - outputFile - ); - } - //@END - } +package com.aspose.html.examples; + +public class Examples_Java_Conversion_EPUBtoImage_1 { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // Source EPUB document + try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("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 = Resources.output("EPUBtoImageOutput.jpeg"); + // Convert SVG to Image + com.aspose.html.converters.Converter.convertEPUB( + fileInputStream, + options, + outputFile + ); + } + //@END + } } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoPDF_1.java b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoPDF_1.java index 2f8983c..18319a6 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoPDF_1.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoPDF_1.java @@ -1,24 +1,24 @@ -package com.aspose.html.examples; - -public class Examples_Java_Conversion_EPUBtoPDF_1 { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // Source EPUB document - try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("input.epub"))) { - // Initialize pdfSaveOptions - com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); - options.setJpegQuality(100); - // Output file path - String outputFile = Resources.output("EPUBtoPDF_Output.pdf"); - // Convert EPUB to PDF - com.aspose.html.converters.Converter.convertEPUB( - fileInputStream, - options, - outputFile - ); - } - //@END - } -} +package com.aspose.html.examples; + +public class Examples_Java_Conversion_EPUBtoPDF_1 { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // Source EPUB document + try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("input.epub"))) { + // Initialize pdfSaveOptions + com.aspose.html.saving.PdfSaveOptions options = new com.aspose.html.saving.PdfSaveOptions(); + options.setJpegQuality(100); + // Output file path + String outputFile = Resources.output("EPUBtoPDF_Output.pdf"); + // Convert EPUB to PDF + com.aspose.html.converters.Converter.convertEPUB( + fileInputStream, + options, + outputFile + ); + } + //@END + } +} diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoXPS_1.java b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoXPS_1.java index 1e401e5..e689ce3 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoXPS_1.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_EPUBtoXPS_1.java @@ -1,21 +1,21 @@ -package com.aspose.html.examples; - -public class Examples_Java_Conversion_EPUBtoXPS_1 { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // Source EPUB document - try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("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 = Resources.output("EPUBtoXPS_Output.xps"); - // Convert EPUB to XPS - com.aspose.html.converters.Converter.convertEPUB(fileInputStream, options, outputFile); - } - //@END - } +package com.aspose.html.examples; + +public class Examples_Java_Conversion_EPUBtoXPS_1 { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // Source EPUB document + try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("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 = Resources.output("EPUBtoXPS_Output.xps"); + // Convert EPUB to XPS + com.aspose.html.converters.Converter.convertEPUB(fileInputStream, options, outputFile); + } + //@END + } } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_HTMLtoBMP_1.java b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_HTMLtoBMP_1.java index 1c044ca..a5073f4 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_HTMLtoBMP_1.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_Conversion_HTMLtoBMP_1.java @@ -1,18 +1,18 @@ -package com.aspose.html.examples; - -public class Examples_Java_Conversion_HTMLtoBMP_1 { - - @org.junit.jupiter.api.Test - public void execute() throws Exception { - //@START - // Source HTML document - com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument(Resources.input("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 = Resources.output("HTMLtoBMP_Output.bmp"); - // Convert HTML to BMP - com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); - //@END - } +package com.aspose.html.examples; + +public class Examples_Java_Conversion_HTMLtoBMP_1 { + + @org.junit.jupiter.api.Test + public void execute() throws Exception { + //@START + // Source HTML document + com.aspose.html.HTMLDocument htmlDocument = new com.aspose.html.HTMLDocument(Resources.input("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 = Resources.output("HTMLtoBMP_Output.bmp"); + // Convert HTML to BMP + com.aspose.html.converters.Converter.convertHTML(htmlDocument, options, outputFile); + //@END + } } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_ConvertingBetweenFormats_FineTuningConverters_SpecifyImageSpecificOptions.java b/src/test/java/com/aspose/html/examples/Examples_Java_ConvertingBetweenFormats_FineTuningConverters_SpecifyImageSpecificOptions.java index d3b243a..48c076f 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_ConvertingBetweenFormats_FineTuningConverters_SpecifyImageSpecificOptions.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_ConvertingBetweenFormats_FineTuningConverters_SpecifyImageSpecificOptions.java @@ -14,7 +14,8 @@ public void execute() throws Exception { 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); + options.setSmoothingMode(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)); diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithMutationObserver_MutationObserverExample_MutationObserver.java b/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithMutationObserver_MutationObserverExample_MutationObserver.java index a8fae33..14878ed 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithMutationObserver_MutationObserverExample_MutationObserver.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithMutationObserver_MutationObserverExample_MutationObserver.java @@ -1,8 +1,7 @@ package com.aspose.html.examples; -import com.aspose.html.dom.mutations.MutationObserver; import com.aspose.html.dom.mutations.MutationRecord; -import com.aspose.ms.System.Collections.Generic.IGenericList; +import com.aspose.html.utils.collections.generic.IGenericList; public class Examples_Java_WorkingWithMutationObserver_MutationObserverExample_MutationObserver { @@ -20,7 +19,7 @@ public void execute() throws Exception { @Override public void invoke( - IGenericList mutations, + IGenericList mutations, com.aspose.html.dom.mutations.MutationObserver mutationObserver ) { synchronized (this) { diff --git a/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithRenderers_RenderingTimeout_RenderingTimeout.java b/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithRenderers_RenderingTimeout_RenderingTimeout.java index 8595b94..2d37624 100644 --- a/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithRenderers_RenderingTimeout_RenderingTimeout.java +++ b/src/test/java/com/aspose/html/examples/Examples_Java_WorkingWithRenderers_RenderingTimeout_RenderingTimeout.java @@ -16,7 +16,7 @@ public void execute() throws Exception { 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); + renderer.render(device, com.aspose.html.utils.TimeSpan.fromSeconds(5), document); } finally { if (device != null) { device.dispose(); diff --git a/src/test/java/com/aspose/html/examples/HTMLDocumentWaiter.java b/src/test/java/com/aspose/html/examples/HTMLDocumentWaiter.java index db035a9..3aa877d 100644 --- a/src/test/java/com/aspose/html/examples/HTMLDocumentWaiter.java +++ b/src/test/java/com/aspose/html/examples/HTMLDocumentWaiter.java @@ -1,23 +1,23 @@ -package com.aspose.html.examples; - -public class HTMLDocumentWaiter implements Runnable { - - private final Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html; - - public HTMLDocumentWaiter(Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html) throws Exception { - this.html = html; - this.html.execute(); - } - - @Override - public void run() { - System.out.println("Current Thread: " + Thread.currentThread().getName() + "; " + Thread.currentThread().getId()); - try { - while (!Thread.currentThread().isInterrupted() && html.getMsg() == null) { - Thread.sleep(60000); - } - } catch (InterruptedException ex) { - Thread.currentThread().interrupt(); - } - } -} +package com.aspose.html.examples; + +public class HTMLDocumentWaiter implements Runnable { + + private final Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html; + + public HTMLDocumentWaiter(Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html) throws Exception { + this.html = html; + this.html.execute(); + } + + @Override + public void run() { + System.out.println("Current Thread: " + Thread.currentThread().getName() + "; " + Thread.currentThread().getId()); + try { + while (!Thread.currentThread().isInterrupted() && html.getMsg() == null) { + Thread.sleep(60000); + } + } catch (InterruptedException ex) { + Thread.currentThread().interrupt(); + } + } +} diff --git a/src/test/java/com/aspose/html/examples/HttpStatus.java b/src/test/java/com/aspose/html/examples/HttpStatus.java index 7cc44dd..2bd14d7 100644 --- a/src/test/java/com/aspose/html/examples/HttpStatus.java +++ b/src/test/java/com/aspose/html/examples/HttpStatus.java @@ -1,7 +1,7 @@ -package com.aspose.html.examples; - -public class HttpStatus { - - public static final int SC_OK = 200; - -} +package com.aspose.html.examples; + +public class HttpStatus { + + public static final int SC_OK = 200; + +} diff --git a/src/test/java/com/aspose/html/examples/SimpleWait.java b/src/test/java/com/aspose/html/examples/SimpleWait.java index 4406739..289e6f7 100644 --- a/src/test/java/com/aspose/html/examples/SimpleWait.java +++ b/src/test/java/com/aspose/html/examples/SimpleWait.java @@ -1,14 +1,14 @@ -package com.aspose.html.examples; - -public class SimpleWait { - - public static void main(String... args) throws Exception { - - Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html = - new Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad(); - HTMLDocumentWaiter htmlDocumentWaiter = new HTMLDocumentWaiter(html); - new Thread(htmlDocumentWaiter, "html").start(); - - } - +package com.aspose.html.examples; + +public class SimpleWait { + + public static void main(String... args) throws Exception { + + Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad html = + new Examples_Java_WorkingWithDocuments_CreatingADocument_HTMLDocumentAsynchronouslyOnLoad(); + HTMLDocumentWaiter htmlDocumentWaiter = new HTMLDocumentWaiter(html); + new Thread(htmlDocumentWaiter, "html").start(); + + } + } \ No newline at end of file diff --git a/src/test/java/com/aspose/html/examples/SmoothingMode.java b/src/test/java/com/aspose/html/examples/SmoothingMode.java new file mode 100644 index 0000000..f05738b --- /dev/null +++ b/src/test/java/com/aspose/html/examples/SmoothingMode.java @@ -0,0 +1,10 @@ +package com.aspose.html.examples; + +public class SmoothingMode { + public static final int AntiAlias = 4; + public static final int Default = 0; + public static final int HighQuality = 2; + public static final int HighSpeed = 1; + public static final int Invalid = -1; + public static final int None = 3; +}