Skip to content

Commit a5875e8

Browse files
HTML Java Examples Structure
1 parent 3e45da4 commit a5875e8

File tree

92 files changed

+2661
-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.

92 files changed

+2661
-0
lines changed

content/english/java/_index.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Aspose.HTML for Java Tutorials
3+
linktitle: Aspose.HTML for Java Tutorials
4+
type: docs
5+
weight: 10
6+
url: /java/
7+
description:
8+
is_root: true
9+
---
10+
11+
### [Advanced Aspose.HTML Usage](./advanced-aspose.html-usage/)
12+
13+
### [EPUB Conversion](./epub-conversion/)
14+
15+
### [HTML Conversion - Image](./html-conversion---image/)
16+
17+
### [HTML Conversion - Markdown](./html-conversion---markdown/)
18+
19+
### [HTML Conversion - PDF](./html-conversion---pdf/)
20+
21+
### [HTML Conversion - XPS](./html-conversion---xps/)
22+
23+
### [Converting Between Formats - Image](./converting-between-formats---image/)
24+
25+
### [Converting Between Formats - PDF](./converting-between-formats---pdf/)
26+
27+
### [Converting Between Formats - HTML to Image](./converting-between-formats---html-to-image/)
28+
29+
### [Converting Between Formats - HTML to Markdown](./converting-between-formats---html-to-markdown/)
30+
31+
### [Converting Between Formats - HTML to PDF](./converting-between-formats---html-to-pdf/)
32+
33+
### [Converting Between Formats - HTML to XPS](./converting-between-formats---html-to-xps/)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Advanced Aspose.HTML Usage
3+
linktitle: Advanced Aspose.HTML Usage
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 20
8+
url: /java/advanced-aspose.html-usage/
9+
---
10+
11+
## Advanced Aspose.HTML Usage Tutorials
12+
### [Add Title and Page Number with CSS Extensions](./add-title-and-page-number/)
13+
### [Observe How Nodes Are Added with DOM Mutation Observer](./observe-nodes-mutation/)
14+
### [Manipulate HTML5 Canvas Using Code](./manipulate-html5-canvas-code/)
15+
### [Manipulate HTML5 Canvas Using JavaScript](./manipulate-html5-canvas-javascript/)
16+
### [Fill HTML Forms and Submit](./fill-html-form-submit/)
17+
### [Adjust PDF Page Size](./adjust-pdf-page-size/)
18+
### [Adjust XPS Page Size](./adjust-xps-page-size/)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Add Title and Page Number with CSS Extensions
3+
linktitle: Add Title and Page Number with CSS Extensions
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 10
8+
url: /java/advanced-aspose.html-usage/add-title-and-page-number/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
//@START
14+
// Initialize configuration object and set up the page-margins for the document
15+
com.aspose.html.Configuration configuration = new com.aspose.html.Configuration();
16+
try {
17+
// Get the User Agent service
18+
com.aspose.html.services.IUserAgentService userAgent = configuration.getService(com.aspose.html.services.IUserAgentService.class);
19+
// Set the style of custom margins and create marks on it
20+
userAgent.setUserStyleSheet("@page\n" +
21+
"{\n" +
22+
" /* Page margins should be not empty in order to write content inside the margin-boxes */\n" +
23+
" margin-top: 1cm;\n" +
24+
" margin-left: 2cm;\n" +
25+
" margin-right: 2cm;\n" +
26+
" margin-bottom: 2cm;\n" +
27+
" /* Page counter located at the bottom of the page */\n" +
28+
" @bottom-right\n" +
29+
" {\n" +
30+
" -aspose-content: \"\"Page \"\" currentPageNumber() \"\" of \"\" totalPagesNumber();\n" +
31+
" color: green;\n" +
32+
" }\n" +
33+
"\n" +
34+
" /* Page title located at the top-center box */\n" +
35+
" @top-center\n" +
36+
" {\n" +
37+
" -aspose-content: \"\"Hello World Document Title!!!\"\";\n" +
38+
" vertical-align: bottom;\n" +
39+
" color: blue;\n" +
40+
" }\n" +
41+
"}\n");
42+
// Initialize an HTML document
43+
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("<div>Hello World!!!</div>", ".", configuration);
44+
try {
45+
// Initialize an output device
46+
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice(Resources.output("output.xps"));
47+
try {
48+
// Send the document to the output device
49+
document.renderTo(device);
50+
} finally {
51+
if (device != null) {
52+
device.dispose();
53+
}
54+
}
55+
} finally {
56+
if (document != null) {
57+
document.dispose();
58+
}
59+
}
60+
} finally {
61+
if (configuration != null) {
62+
configuration.dispose();
63+
}
64+
}
65+
//@END
66+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Adjust PDF Page Size
3+
linktitle: Adjust PDF Page Size
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 15
8+
url: /java/advanced-aspose.html-usage/adjust-pdf-page-size/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
//@START
14+
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("FirstFile.html"))) {
15+
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(Resources.output("FirstFileOut.html"))) {
16+
byte[] bytes = new byte[fileInputStream.available()];
17+
fileInputStream.read(bytes);
18+
fileOutputStream.write(bytes);
19+
String style = "<style>\n" +
20+
".st\n" +
21+
"{\n" +
22+
"color:\n" +
23+
"green;\n" +
24+
"}\n" +
25+
"</style >\n" +
26+
"<div id = id1 > Aspose.Html rendering Text in Black Color</div >\n" +
27+
"<div id = id2 class='' st '' > Aspose.Html rendering Text in Green Color</div >\n" +
28+
"<div id = id3 class='' st '' style = 'color: blue;' > Aspose.Html rendering Text in Blue Color</div >\n" +
29+
"<div id = id3 class='' st '' style = 'color: red;' ><font face = 'Arial' > Aspose.Html rendering Text in Red\n" +
30+
"Color</font ></div >\n";
31+
fileOutputStream.write(style.getBytes(java.nio.charset.StandardCharsets.UTF_8));
32+
}
33+
String pdf_output;
34+
// Create HtmlRenderer object
35+
com.aspose.html.rendering.HtmlRenderer pdf_renderer = new com.aspose.html.rendering.HtmlRenderer();
36+
try {
37+
// Create HtmlDocument instnace while passing path of already created HTML file
38+
com.aspose.html.HTMLDocument html_document = new com.aspose.html.HTMLDocument(Resources.output("FirstFileOut.html"));
39+
try {
40+
// Set the page size less than document min-width. The content in the resulting file will be cropped becuase of element with width: 200px
41+
com.aspose.html.rendering.pdf.PdfRenderingOptions pdf_options =
42+
new com.aspose.html.rendering.pdf.PdfRenderingOptions();
43+
com.aspose.html.rendering.PageSetup pageSetup = new com.aspose.html.rendering.PageSetup();
44+
pageSetup.setAnyPage(new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100)));
45+
pageSetup.setAdjustToWidestPage(false);
46+
pdf_options.setPageSetup(pageSetup);
47+
pdf_output = Resources.output("not-adjusted-to-widest-page_out.pdf");
48+
com.aspose.html.rendering.pdf.PdfDevice device = new com.aspose.html.rendering.pdf.PdfDevice(pdf_options, pdf_output);
49+
try {
50+
// Render the output
51+
pdf_renderer.render(device, html_document);
52+
} finally {
53+
if (device != null) {
54+
device.dispose();
55+
}
56+
}
57+
// 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
58+
pdf_options = new com.aspose.html.rendering.pdf.PdfRenderingOptions();
59+
pageSetup = new com.aspose.html.rendering.PageSetup();
60+
pageSetup.setAnyPage(new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100)));
61+
pageSetup.setAdjustToWidestPage(true);
62+
pdf_options.setPageSetup(pageSetup);
63+
pdf_output = Resources.output("adjusted-to-widest-page_out.pdf");
64+
device = new com.aspose.html.rendering.pdf.PdfDevice(pdf_options, pdf_output);
65+
try {
66+
// Render the output
67+
pdf_renderer.render(device, html_document);
68+
} finally {
69+
if (device != null) {
70+
device.dispose();
71+
}
72+
}
73+
} finally {
74+
if (html_document != null) {
75+
html_document.dispose();
76+
}
77+
}
78+
} finally {
79+
if (pdf_renderer != null) {
80+
pdf_renderer.dispose();
81+
}
82+
}
83+
}
84+
//@END
85+
```
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
title: Adjust XPS Page Size
3+
linktitle: Adjust XPS Page Size
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 16
8+
url: /java/advanced-aspose.html-usage/adjust-xps-page-size/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
//@START
14+
// Set input file name.
15+
try (java.io.FileInputStream fileInputStream = new java.io.FileInputStream(Resources.input("FirstFile.html"))) {
16+
try (java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(Resources.output("FirstFileOut.html"))) {
17+
byte[] bytes = new byte[fileInputStream.available()];
18+
fileInputStream.read(bytes);
19+
fileOutputStream.write(bytes);
20+
String style = "<style>\n" +
21+
".st\n" +
22+
"{\n" +
23+
"color: green;\n" +
24+
"}\n" +
25+
"</style>\n" +
26+
"<div id=id1>Aspose.Html rendering Text in Black Color</div>\n" +
27+
"<div id=id2 class=''st''>Aspose.Html rendering Text in Green Color</div>\n" +
28+
"<div id=id3 class=''st'' style='color: blue;'>Aspose.Html rendering Text in Blue Color</div>\n" +
29+
"<div id=id3 class=''st'' style='color: red;'>Aspose.Html rendering Text in Red Color</div>\n";
30+
fileOutputStream.write(style.getBytes(java.nio.charset.StandardCharsets.UTF_8));
31+
}
32+
// Create HtmlRenderer object
33+
com.aspose.html.rendering.HtmlRenderer renderer = new com.aspose.html.rendering.HtmlRenderer();
34+
try {
35+
// Create HtmlDocument instnace while passing path of already created HTML file
36+
com.aspose.html.HTMLDocument html_document = new com.aspose.html.HTMLDocument(Resources.output("FirstFileOut.html"));
37+
try {
38+
// Set the page size less than document min-width. The content in the resulting file will be cropped becuase of element with width: 200px
39+
com.aspose.html.rendering.xps.XpsRenderingOptions xps_options = new com.aspose.html.rendering.xps.XpsRenderingOptions();
40+
com.aspose.html.drawing.Page page = new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100));
41+
com.aspose.html.rendering.PageSetup pageSetup = new com.aspose.html.rendering.PageSetup();
42+
pageSetup.setAnyPage(page);
43+
pageSetup.setAdjustToWidestPage(false);
44+
xps_options.setPageSetup(pageSetup);
45+
String output = Resources.output("not-adjusted-to-widest-page_out.1.xps");
46+
com.aspose.html.rendering.xps.XpsDevice device = new com.aspose.html.rendering.xps.XpsDevice(xps_options, output);
47+
try {
48+
// Render the output
49+
renderer.render(device, html_document);
50+
} finally {
51+
if (device != null) {
52+
device.dispose();
53+
}
54+
}
55+
// Set the page size less than document min-width and enable AdjustToWidestPage option
56+
// The page size of the resulting file will be changed according to content width
57+
xps_options = new com.aspose.html.rendering.xps.XpsRenderingOptions();
58+
page = new com.aspose.html.drawing.Page(new com.aspose.html.drawing.Size(100, 100));
59+
pageSetup = new com.aspose.html.rendering.PageSetup();
60+
pageSetup.setAnyPage(page);
61+
pageSetup.setAdjustToWidestPage(true);
62+
xps_options.setPageSetup(pageSetup);
63+
output = Resources.output("not-adjusted-to-widest-page_out.2.xps");
64+
device = new com.aspose.html.rendering.xps.XpsDevice(xps_options, output);
65+
try {
66+
// Render the output
67+
renderer.render(device, html_document);
68+
} finally {
69+
if (device != null) {
70+
device.dispose();
71+
}
72+
}
73+
} finally {
74+
if (html_document != null) {
75+
html_document.dispose();
76+
}
77+
}
78+
} finally {
79+
if (renderer != null) {
80+
renderer.dispose();
81+
}
82+
}
83+
}
84+
//@END
85+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Fill HTML Forms and Submit
3+
linktitle: Fill HTML Forms and Submit
4+
second_title: Java HTML Processing with Aspose.HTML
5+
description:
6+
type: docs
7+
weight: 14
8+
url: /java/advanced-aspose.html-usage/fill-html-form-submit/
9+
---
10+
11+
## Complete Source Code
12+
```java
13+
//@START
14+
// Initialize an instance of HTML document from 'https://httpbin.org/forms/post' url
15+
com.aspose.html.HTMLDocument document = new com.aspose.html.HTMLDocument("https://httpbin.org/forms/post");
16+
try {
17+
// Create an instance of Form Editor
18+
com.aspose.html.forms.FormEditor editor = com.aspose.html.forms.FormEditor.create(document, 0);
19+
try {
20+
// You can fill the data up using direct access to the input elements, like this:
21+
editor.get_Item("custname").setValue("John Doe");
22+
document.save(Resources.output("out.html"));
23+
// or this:
24+
com.aspose.html.forms.TextAreaElement comments = editor.getElement(com.aspose.html.forms.TextAreaElement.class, "comments");
25+
comments.setValue("MORE CHEESE PLEASE!");
26+
// or even by performing a bulk operation, like this one:
27+
java.util.Map<String, String> map = new java.util.HashMap<>();
28+
map.put("custemail", "john.doe@gmail.com");
29+
map.put("custtel", "+1202-555-0290");
30+
editor.fill(map);
31+
// Create an instance of form submitter
32+
com.aspose.html.forms.FormSubmitter submitter = new com.aspose.html.forms.FormSubmitter(editor);
33+
try {
34+
// Submit the form data to the remote server.
35+
// If you need you can specify user-credentials and timeout for the request, etc.
36+
com.aspose.html.forms.SubmissionResult result = submitter.submit();
37+
// Check the status of the result object
38+
if (result.isSuccess()) {
39+
// Check whether the result is in json format
40+
if (result.getResponseMessage().getHeaders().getContentType().getMediaType().equals("application/json")) {
41+
// Dump result data to the console
42+
System.out.println(result.getContent().readAsString());
43+
} else {
44+
// Load the result data as an HTML document
45+
com.aspose.html.dom.Document resultDocument = result.loadDocument();
46+
try {
47+
// Inspect HTML document here.
48+
System.out.println(resultDocument.getDocumentElement().getTextContent());
49+
} finally {
50+
if (resultDocument != null) {
51+
resultDocument.dispose();
52+
}
53+
}
54+
}
55+
}
56+
} finally {
57+
if (submitter != null) {
58+
submitter.dispose();
59+
}
60+
}
61+
} finally {
62+
if (editor != null) {
63+
editor.dispose();
64+
}
65+
}
66+
} finally {
67+
if (document != null) {
68+
document.dispose();
69+
}
70+
}
71+
//@END
72+
```

0 commit comments

Comments
 (0)