Skip to content

Commit d82c6ce

Browse files
Updated document rendering examples
1 parent 6276451 commit d82c6ce

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed

content/english/java/document-rendering/document-printing-rendering/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Rendering documents is essential when you need to convert them to different form
4949

5050
```java
5151
// Render the document to PDF
52-
doc.save("output.pdf", SaveFormat.PDF);
52+
doc.save("output.pdf");
5353
```
5454

5555
You can replace `SaveFormat.PDF` with the desired format for rendering.

content/english/java/document-rendering/document-thumbnail-generation/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Now, let's dive into the process of generating thumbnails from the loaded docume
4040
```java
4141
// Java code to generate a document thumbnail
4242
ByteArrayOutputStream stream = new ByteArrayOutputStream();
43-
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
43+
ImageSaveOptions options = new ImageSaveOptions();
4444
doc.save(stream, options);
4545
```
4646

content/english/java/document-rendering/master-document-rendering/_index.md

+18-20
Original file line numberDiff line numberDiff line change
@@ -101,26 +101,24 @@ pageSetup.setOrientation(Orientation.LANDSCAPE);
101101
// Add headers and footers
102102
pageSetup.setHeaderDistance(20);
103103
pageSetup.setFooterDistance(10);
104-
pageSetup.setHeaderFooter(HeaderFooterType.HEADER_PRIMARY, new Paragraph(doc, "Header Text"));
105-
pageSetup.setHeaderFooter(HeaderFooterType.FOOTER_PRIMARY, new Paragraph(doc, "Footer Text"));
106104
```
107105

108106
### Headers and Footers
109107

110108
Headers and footers provide consistent information across document pages. You can add different content to primary, first-page, and even odd/even headers and footers.
111109

112110
```java
113-
// Adding content to primary header
114-
HeaderFooter primaryHeader = pageSetup.getHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
115-
Paragraph headerPara = new Paragraph(doc, "This is the header text.");
116-
primaryHeader.appendChild(headerPara);
117-
118-
// Adding content to primary footer
119-
HeaderFooter primaryFooter = pageSetup.getHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
120-
Paragraph footerPara = new Paragraph(doc, "Page number: ");
121-
FieldPage fieldPage = new FieldPage();
122-
footerPara.appendChild(fieldPage);
123-
primaryFooter.appendChild(footerPara);
111+
Document doc = new Document();
112+
DocumentBuilder builder = new DocumentBuilder(doc);
113+
114+
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
115+
builder.write("Header Text");
116+
builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
117+
118+
builder.write("Page Number: ");
119+
builder.insertField(FieldType.FIELD_PAGE, true);
120+
121+
doc.save("HeaderFooterDocument.docx");
124122
```
125123

126124
## Rendering Documents
@@ -133,13 +131,13 @@ To render a document, you need to use the Document class's save method and speci
133131

134132
```java
135133
// Render to PDF
136-
doc.save("output.pdf", SaveFormat.PDF);
134+
doc.save("output.pdf");
137135

138136
// Render to XPS
139-
doc.save("output.xps", SaveFormat.XPS);
137+
doc.save("output.xps");
140138

141139
// Render to images
142-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
140+
ImageSaveOptions saveOptions = new ImageSaveOptions();
143141
saveOptions.setResolution(300);
144142
doc.save("output.png", saveOptions);
145143
```
@@ -161,7 +159,7 @@ When rendering documents to image formats, you can control the image quality to
161159

162160
```java
163161
// Set image options
164-
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.PNG);
162+
ImageSaveOptions imageOptions = new ImageSaveOptions();
165163
imageOptions.setResolution(300);
166164
imageOptions.setPrettyFormat(true);
167165
doc.save("output.png", imageOptions);
@@ -179,7 +177,7 @@ You can render specific pages of a document, allowing you to display specific se
179177
// Render specific page range
180178
int startPage = 3;
181179
int endPage = 5;
182-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
180+
ImageSaveOptions saveOptions = new ImageSaveOptions();
183181
saveOptions.setPageSet(new PageSet(startPage, endPage));
184182
doc.save("output.png", saveOptions);
185183
```
@@ -191,7 +189,7 @@ If you want to render only specific parts of a document, such as paragraphs or s
191189
```java
192190
// Render specific paragraphs
193191
int[] paragraphIndices = {0, 2, 4};
194-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
192+
ImageSaveOptions saveOptions = new ImageSaveOptions();
195193
saveOptions.setPageSet(new PageSet(paragraphIndices));
196194
doc.save("output.png", saveOptions);
197195
```
@@ -203,7 +201,7 @@ For more granular control, you can render individual document elements like tabl
203201
```java
204202
// Render specific table
205203
int tableIndex = 1;
206-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
204+
ImageSaveOptions saveOptions = new ImageSaveOptions();
207205
saveOptions.setPageSet(new PageSet(tableIndex));
208206
doc.save("output.png", saveOptions);
209207
```

content/english/java/document-rendering/rendering-document-pages-images/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Aspose.Words provides various image save options to control the output format an
4848

4949
```java
5050
// Initialize image save options
51-
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
51+
ImageSaveOptions options = new ImageSaveOptions();
5252
```
5353

5454
## Step 4: Render Document Pages as Images

content/english/java/document-rendering/rendering-shapes-graphics/_index.md

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ type: docs
77
weight: 12
88
url: /java/document-rendering/rendering-shapes-graphics/
99
---
10-
1110
## Introduction
1211

1312
In this digital era, documents often need to be more than just plain text. Adding shapes and graphics can convey information more effectively and make your documents visually appealing. Aspose.Words for Java is a powerful Java API that allows you to manipulate Word documents, including adding and customizing shapes and graphics.

0 commit comments

Comments
 (0)