Skip to content

Commit c4dc636

Browse files
More Examples
1 parent 35f8e4e commit c4dc636

File tree

65 files changed

+2568
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2568
-0
lines changed

content/english/java/_index.md

+48
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,51 @@ Discover the step-by-step process of converting EPUB to XPS using Aspose.HTML Ja
6666
### [Converting HTML to Various Image Formats](./converting-html-to-various-image-formats/)
6767
Explore tutorials on converting HTML to BMP, GIF, JPG, and PNG effortlessly with Aspose.HTML for Java. Create stunning images from HTML documents.
6868

69+
70+
### [HTML5 and Canvas Rendering with Aspose.HTML for Java](./html5-canvas-rendering/)
71+
72+
### [CSS and HTML Form Editing with Aspose.HTML for Java](./css-html-form-editing/)
73+
74+
### [Data Handling and Stream Management in Aspose.HTML for Java](./data-handling-stream-management/)
75+
76+
### [Mutation Observers and Handlers in Aspose.HTML for Java](./mutation-observers-handlers/)
77+
78+
### [Custom Schema and Message Handling in Aspose.HTML for Java](./custom-schema-message-handling/)
79+
80+
### [Message Handling and Networking in Aspose.HTML for Java](./message-handling-networking/)
81+
82+
### [Logging and Timeout Management in Aspose.HTML for Java](./logging-timeout-management/)
83+
84+
### [Creating and Managing HTML Documents in Aspose.HTML for Java](./creating-managing-html-documents/)
85+
86+
### [Editing HTML Documents in Aspose.HTML for Java](./editing-html-documents/)
87+
88+
### [Configuring Environment in Aspose.HTML for Java](./configuring-environment/)
89+
90+
### [Saving HTML Documents in Aspose.HTML for Java](./saving-html-documents/)
91+
92+
### [Handling ZIP Files in Aspose.HTML for Java](./handling-zip-files/)
93+
94+
### [HTML5 and Canvas Rendering with Aspose.HTML for Java](./html5-canvas-rendering/)
95+
96+
### [CSS and HTML Form Editing with Aspose.HTML for Java](./css-html-form-editing/)
97+
98+
### [Data Handling and Stream Management in Aspose.HTML for Java](./data-handling-stream-management/)
99+
100+
### [Mutation Observers and Handlers in Aspose.HTML for Java](./mutation-observers-handlers/)
101+
102+
### [Custom Schema and Message Handling in Aspose.HTML for Java](./custom-schema-message-handling/)
103+
104+
### [Message Handling and Networking in Aspose.HTML for Java](./message-handling-networking/)
105+
106+
### [Logging and Timeout Management in Aspose.HTML for Java](./logging-timeout-management/)
107+
108+
### [Creating and Managing HTML Documents in Aspose.HTML for Java](./creating-managing-html-documents/)
109+
110+
### [Editing HTML Documents in Aspose.HTML for Java](./editing-html-documents/)
111+
112+
### [Configuring Environment in Aspose.HTML for Java](./configuring-environment/)
113+
114+
### [Saving HTML Documents in Aspose.HTML for Java](./saving-html-documents/)
115+
116+
### [Handling ZIP Files in Aspose.HTML for Java](./handling-zip-files/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Configuring Environment in Aspose.HTML for Java
3+
linktitle: Configuring Environment in Aspose.HTML for Java
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 29
8+
url: /java/configuring-environment/
9+
---
10+
11+
## Configuring Environment in Aspose.HTML for Java Tutorials
12+
### [Set Character Set in Aspose.HTML for Java](./set-character-set/)
13+
### [Configure Fonts in Aspose.HTML for Java](./configure-fonts/)
14+
### [Use Message Handlers in Aspose.HTML for Java](./use-message-handlers/)
15+
### [Set Up Network Service in Aspose.HTML for Java](./setup-network-service/)
16+
### [Configure Runtime Service in Aspose.HTML for Java](./configure-runtime-service/)
17+
### [Implement Sandboxing in Aspose.HTML for Java](./implement-sandboxing/)
18+
### [Set User Style Sheet in Aspose.HTML for Java](./set-user-style-sheet/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Configure Fonts in Aspose.HTML for Java
3+
linktitle: Configure Fonts in Aspose.HTML for Java
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 11
8+
url: /java/configuring-environment/configure-fonts/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
package com.aspose.html.documentation.examples;
14+
15+
import java.io.IOException;
16+
17+
public class WorkingWithHTMLDocuments_EnvironmentConfiguration_Font {
18+
public static void main(String [] args) throws IOException {
19+
// START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_Font
20+
// Prepare an HTML code and save it to the file.
21+
String code = "<h1>FontsSettings property</h1>\r\n" +
22+
"<p>The FontsSettings property is used for configuration of fonts handling.</p>\r\n";
23+
24+
try (java.io.FileWriter fileWriter = new java.io.FileWriter("user-agent-fontsetting.html")) {
25+
fileWriter.write(code);
26+
}
27+
28+
// Create an instance of Configuration
29+
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
30+
try {
31+
// Get the IUserAgentService
32+
com.aspose.html.services.IUserAgentService userAgent = configuration.getService(com.aspose.html.services.IUserAgentService.class);
33+
34+
// Set the custom style parameters for the "h1" and "p" elements
35+
userAgent.setUserStyleSheet("h1 { color:#a52a2a; }\r\n" +
36+
"p { color:grey; }\r\n");
37+
38+
// Set custom font folder path
39+
userAgent.getFontsSettings().setFontsLookupFolder("fonts");
40+
41+
// Initialize an HTML document with specified configuration
42+
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("user-agent-fontsetting.html", configuration);
43+
try {
44+
// Convert HTML to PDF
45+
com.aspose.html.converters.Converter.convertHTML(
46+
document,
47+
new com.aspose.html.saving.PdfSaveOptions(),
48+
"user-agent-fontsetting_out.pdf"
49+
);
50+
} finally {
51+
if (document != null) {
52+
document.dispose();
53+
}
54+
}
55+
} finally {
56+
if (configuration != null) {
57+
configuration.dispose();
58+
}
59+
}
60+
// END_SNIPPET
61+
}
62+
}
63+
64+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Configure Runtime Service in Aspose.HTML for Java
3+
linktitle: Configure Runtime Service in Aspose.HTML for Java
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 14
8+
url: /java/configuring-environment/configure-runtime-service/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
package com.aspose.html.documentation.examples;
14+
15+
import java.io.IOException;
16+
17+
public class WorkingWithHTMLDocuments_EnvironmentConfiguration_RuntimeService {
18+
public static void main(String [] args) throws IOException {
19+
// START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_RuntimeService
20+
// Prepare an HTML code and save it to the file.
21+
String code = "<h1>Runtime Service</h1>\r\n" +
22+
"<script> while(true) {} </script>\r\n" +
23+
"<p>The Runtime Service optimizes your system by helping it start apps and programs faster.</p>\r\n";
24+
25+
try (java.io.FileWriter fileWriter = new java.io.FileWriter("runtime-service.html")) {
26+
fileWriter.write(code);
27+
}
28+
29+
// Create an instance of Configuration
30+
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
31+
try {
32+
// Limit JS execution time to 5 seconds
33+
com.aspose.html.services.IRuntimeService runtimeService = configuration.getService(com.aspose.html.services.IRuntimeService.class);
34+
runtimeService.setJavaScriptTimeout(com.aspose.html.utils.TimeSpan.fromSeconds(5));
35+
36+
37+
// Initialize an HTML document with specified configuration
38+
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("runtime-service.html", configuration);
39+
try {
40+
// Convert HTML to PNG
41+
com.aspose.html.converters.Converter.convertHTML(
42+
document,
43+
new com.aspose.html.saving.ImageSaveOptions(),
44+
"runtime-service_out.png"
45+
);
46+
} finally {
47+
if (document != null) {
48+
document.dispose();
49+
}
50+
}
51+
} finally {
52+
if (configuration != null) {
53+
configuration.dispose();
54+
}
55+
}
56+
// END_SNIPPET
57+
}
58+
}
59+
60+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: Implement Sandboxing in Aspose.HTML for Java
3+
linktitle: Implement Sandboxing in Aspose.HTML for Java
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 15
8+
url: /java/configuring-environment/implement-sandboxing/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
package com.aspose.html.documentation.examples;
14+
15+
import java.io.IOException;
16+
17+
public class WorkingWithHTMLDocuments_EnvironmentConfiguration_Sandboxing {
18+
public static void main(String [] args) throws IOException {
19+
// START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_Sandboxing
20+
// Prepare an HTML code and save it to the file.
21+
String code = "<span>Hello World!!</span>\n" +
22+
"<script>document.write('Have a nice day!');</script>\n";
23+
24+
try (java.io.FileWriter fileWriter = new java.io.FileWriter("sandboxing.html")) {
25+
fileWriter.write(code);
26+
}
27+
28+
// Create an instance of Configuration
29+
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
30+
try {
31+
// Mark 'scripts' as an untrusted resource
32+
configuration.setSecurity(com.aspose.html.Sandbox.Scripts);
33+
34+
// Initialize an HTML document with specified configuration
35+
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("sandboxing.html", configuration);
36+
try {
37+
// Convert HTML to PDF
38+
com.aspose.html.converters.Converter.convertHTML(
39+
document,
40+
new com.aspose.html.saving.PdfSaveOptions(),
41+
"sandboxing_out.pdf"
42+
);
43+
} finally {
44+
if (document != null) {
45+
document.dispose();
46+
}
47+
}
48+
} finally {
49+
if (configuration != null) {
50+
configuration.dispose();
51+
}
52+
}
53+
// END_SNIPPET
54+
}
55+
}
56+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: Set Character Set in Aspose.HTML for Java
3+
linktitle: Set Character Set in Aspose.HTML for Java
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 10
8+
url: /java/configuring-environment/set-character-set/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
package com.aspose.html.documentation.examples;
14+
15+
import java.io.IOException;
16+
17+
public class WorkingWithHTMLDocuments_EnvironmentConfiguration_CharacterSet {
18+
public static void main(String [] args) throws IOException {
19+
// START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_CharacterSet
20+
// Prepare an HTML code and save it to the file.
21+
String code = "<h1>Character Set</h1>\r\n" +
22+
"<p>The <b>CharSet</b> property sets the primary character-set for a document.</p>\r\n";
23+
24+
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
25+
fileWriter.write(code);
26+
}
27+
28+
// Create an instance of Configuration
29+
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
30+
try {
31+
// Get the IUserAgentService
32+
com.aspose.html.services.IUserAgentService userAgent = configuration.getService(com.aspose.html.services.IUserAgentService.class);
33+
34+
// Set ISO-8859-1 encoding to parse the document
35+
userAgent.setCharSet("ISO-8859-1");
36+
37+
// Initialize an HTML document with specified configuration
38+
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("user-agent-charset.html", configuration);
39+
try {
40+
// Convert HTML to PDF
41+
com.aspose.html.converters.Converter.convertHTML(
42+
document,
43+
new com.aspose.html.saving.PdfSaveOptions(),
44+
"user-agent-charset_out.pdf"
45+
);
46+
} finally {
47+
if (document != null) {
48+
document.dispose();
49+
}
50+
}
51+
} finally {
52+
if (configuration != null) {
53+
configuration.dispose();
54+
}
55+
}
56+
// END_SNIPPET
57+
}
58+
}
59+
60+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: Set User Style Sheet in Aspose.HTML for Java
3+
linktitle: Set User Style Sheet in Aspose.HTML for Java
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 16
8+
url: /java/configuring-environment/set-user-style-sheet/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
package com.aspose.html.documentation.examples;
14+
15+
import java.io.IOException;
16+
17+
public class WorkingWithHTMLDocuments_EnvironmentConfiguration_UserStyleSheet {
18+
public static void main(String [] args) throws IOException {
19+
// START_SNIPPET WorkingWithHTMLDocuments_EnvironmentConfiguration_UserStyleSheet
20+
// Prepare an HTML code and save it to the file.
21+
String code = "<h1>User Agent Service </h1>\r\n" +
22+
"<p>The User Agent Service allows you to specify a custom user stylesheet, a primary character set for the document, language and fonts settings.</p>\r\n";
23+
24+
try (java.io.FileWriter fileWriter = new java.io.FileWriter("document.html")) {
25+
fileWriter.write(code);
26+
}
27+
28+
// Create an instance of Configuration
29+
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
30+
try {
31+
// Get the IUserAgentService
32+
com.aspose.html.services.IUserAgentService userAgent = configuration.getService(com.aspose.html.services.IUserAgentService.class);
33+
34+
// Set the custom color to the SPAN element
35+
userAgent.setUserStyleSheet("h1 { color:#a52a2a;; font-size:2em;}\r\n" +
36+
"p { background-color:GhostWhite; color:SlateGrey; font-size:1.2em; }\r\n");
37+
38+
// Initialize an HTML document with specified configuration
39+
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("user-agent-stylesheet.html", configuration);
40+
try {
41+
// Convert HTML to PDF
42+
com.aspose.html.converters.Converter.convertHTML(
43+
document,
44+
new com.aspose.html.saving.PdfSaveOptions(),
45+
"user-agent-stylesheet_out.pdf"
46+
);
47+
} finally {
48+
if (document != null) {
49+
document.dispose();
50+
}
51+
}
52+
} finally {
53+
if (configuration != null) {
54+
configuration.dispose();
55+
}
56+
}
57+
// END_SNIPPET
58+
}
59+
}
60+
61+
```

0 commit comments

Comments
 (0)