Skip to content

Commit f6ca10e

Browse files
Updated word processing examples
1 parent 2209269 commit f6ca10e

File tree

5 files changed

+59
-97
lines changed
  • content/english/java/word-processing

5 files changed

+59
-97
lines changed

content/english/java/word-processing/efficient-document-saving-options/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Sometimes, you may need to save each page of your document as an image. Aspose.W
5454

5555
```java
5656
// Java code to save a document as images
57-
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
57+
ImageSaveOptions imageSaveOptions = new ImageSaveOptions();
5858
imageSaveOptions.setResolution(300); // Set the resolution (DPI)
5959
doc.save("output.png", imageSaveOptions);
6060
```

content/english/java/word-processing/generate-word-document/_index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ type: docs
77
weight: 11
88
url: /java/word-processing/generate-word-document/
99
---
10-
1110
## Introduction
1211

1312
In this tutorial, we will walk you through the process of generating a Word document using Aspose.Words for Java. Aspose.Words is a powerful library that allows developers to work with Word documents programmatically. Whether you want to create dynamic reports, generate invoices, or simply manipulate Word documents, Aspose.Words for Java provides a comprehensive set of features to streamline your document processing tasks.
@@ -174,11 +173,11 @@ To make the most of Aspose.Words for Java, follow these best practices:
174173
- Use variables to store frequently used formatting settings, reducing redundancy.
175174
- Close the Document objects once you are done to free up resources.
176175

177-
## 11. Conclusion
176+
## Conclusion
178177

179178
Aspose.Words for Java is a powerful library that simplifies word processing tasks for Java developers. With its extensive features, you can effortlessly generate, manipulate, and convert Word documents. From basic text insertion to complex automation, Aspose.Words for Java streamlines document processing, saving you time and effort in your projects.
180179

181-
## FAQs
180+
## FAQ's
182181

183182
### 1. What is Aspose.Words for Java?
184183

content/english/java/word-processing/handling-different-document-formats/_index.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ One of the key strengths of Aspose.Words for Java is its ability to load various
3737
Document doc = new Document("sample.docx");
3838
```
3939

40-
### Loading a PDF Document
41-
42-
```java
43-
// Load a PDF document
44-
Document doc = new Document("sample.pdf");
45-
```
46-
4740
## Modifying and Saving Documents
4841

4942
Once you've loaded a document, you can perform a multitude of operations, from simple text replacement to complex formatting changes.
@@ -71,7 +64,7 @@ Aspose.Words for Java allows seamless conversion between different document form
7164
Document doc = new Document("sample.docx");
7265

7366
// Save as PDF
74-
doc.save("sample.pdf", SaveFormat.PDF);
67+
doc.save("sample.pdf");
7568
```
7669

7770
## Handling Images and Tables

content/english/java/word-processing/manipulating-document-content/_index.md

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ type: docs
77
weight: 14
88
url: /java/word-processing/manipulating-document-content/
99
---
10-
1110
## Introduction
1211

1312
In the world of Java programming, efficient document management is a crucial aspect of many applications. Whether you're working on generating reports, handling contracts, or dealing with any document-related task, Aspose.Words for Java is a powerful tool to have in your toolkit. In this comprehensive guide, we will delve into the intricacies of manipulating document content with cleanup, fields, and XML data using Aspose.Words for Java. We'll provide step-by-step instructions along with source code examples to empower you with the knowledge and skills needed to master this versatile library.
@@ -50,7 +49,8 @@ Empty paragraphs can be a nuisance. Remove them using this code:
5049

5150
```java
5251
Document doc = new Document("document.docx");
53-
doc.getRange().getParagraphs().removeIf(p -> p.getText().trim().isEmpty());
52+
List<Paragraph> paragraphs = Arrays.asList(doc.getFirstSection().getBody().getParagraphs().toArray());
53+
paragraphs.removeIf(p -> p.getText().trim().isEmpty());
5454
doc.save("document_without_empty_paragraphs.docx");
5555
```
5656

@@ -60,14 +60,13 @@ Hidden content might exist in your documents, potentially causing issues during
6060

6161
```java
6262
Document doc = new Document("document.docx");
63-
doc.getRange().getRuns().removeIf(run -> run.getFont().getHidden());
63+
List<Paragraph> paragraphs = Arrays.asList(doc.getFirstSection().getBody().getParagraphs().toArray());
64+
paragraphs.removeIf(p -> p.getText().trim().isEmpty());
6465
doc.save("document_stripped_of_hidden_content.docx");
6566
```
6667

6768
By following these steps, you can ensure that your document is clean and ready for further manipulation.
6869

69-
---
70-
7170
## Working with Fields
7271

7372
Fields in documents allow dynamic content, such as dates, page numbers, and document properties. Aspose.Words for Java simplifies working with fields.
@@ -96,80 +95,47 @@ doc.save("document_with_inserted_fields.docx");
9695

9796
Fields add dynamic capabilities to your documents, enhancing their utility.
9897

99-
---
100-
101-
## Incorporating XML Data
102-
103-
Integrating XML data into your documents can be powerful, especially for generating dynamic content. Aspose.Words for Java simplifies this process.
104-
105-
### Binding XML Data
106-
107-
Bind XML data to your document with ease:
108-
109-
```java
110-
Document doc = new Document("template.docx");
111-
XmlMapping xmlMapping = doc.getRange().getXmlMapping();
112-
xmlMapping.setMappingName("customer");
113-
xmlMapping.setXPath("/order/customer");
114-
xmlMapping.setPrefixMappings("xmlns:ns='http://schemas.example'");
115-
doc.save("document_with_xml_data.docx");
116-
```
98+
## Conclusion
11799

118-
This code binds XML data to specific parts of your document, making it dynamic and data-driven.
100+
In this extensive guide, we've explored the world of manipulating document content with cleanup, fields, and XML data using Aspose.Words for Java. You've learned how to clean up documents, work with fields, and incorporate XML data seamlessly. These skills are invaluable for anyone dealing with document management in Java applications.
119101

120-
## Frequently Asked Questions (FAQs)
102+
## FAQ's
121103

122104
### How do I remove empty paragraphs from a document?
123105

124-
To remove empty paragraphs from a document, you can iterate through the paragraphs and remove those that have no text content. Here's a code snippet to help you achieve this:
106+
To remove empty paragraphs from a document, you can iterate through the paragraphs and remove those that have no text content. Here's a code snippet to help you achieve this:
125107

126-
```java
127-
Document doc = new Document("document.docx");
128-
doc.getRange().getParagraphs().removeIf(p -> p.getText().trim().isEmpty());
129-
doc.save("document_without_empty_paragraphs.docx");
130-
```
108+
```java
109+
Document doc = new Document("document.docx");
110+
List<Paragraph> paragraphs = Arrays.asList(doc.getFirstSection().getBody().getParagraphs().toArray());
111+
paragraphs.removeIf(p -> p.getText().trim().isEmpty());
112+
doc.save("document_without_empty_paragraphs.docx");
113+
```
131114

132115
### Can I update all fields in a document programmatically?
133116

134-
Yes, you can update all fields in a document programmatically using Aspose.Words for Java. Here's how you can do it:
117+
Yes, you can update all fields in a document programmatically using Aspose.Words for Java. Here's how you can do it:
135118

136-
```java
137-
Document doc = new Document("document.docx");
138-
doc.updateFields();
139-
doc.save("document_with_updated_fields.docx");
140-
```
141-
142-
### How do I bind XML data to a document?
143-
144-
Binding XML data to a document is straightforward with Aspose.Words for Java. You can use XML mappings to achieve this. Here's an example:
145-
146-
```java
147-
Document doc = new Document("template.docx");
148-
XmlMapping xmlMapping = doc.getRange().getXmlMapping();
149-
xmlMapping.setMappingName("customer");
150-
xmlMapping.setXPath("/order/customer");
151-
xmlMapping.setPrefixMappings("xmlns:ns='http://schemas.example'");
152-
doc.save("document_with_xml_data.docx");
153-
```
119+
```java
120+
Document doc = new Document("document.docx");
121+
doc.updateFields();
122+
doc.save("document_with_updated_fields.docx");
123+
```
154124

155125
### What is the importance of cleaning up document content?
156126

157-
Cleaning up document content is important to ensure that your documents are free from unnecessary elements, which can improve readability and reduce file size. It also helps in maintaining document consistency.
127+
Cleaning up document content is important to ensure that your documents are free from unnecessary elements, which can improve readability and reduce file size. It also helps in maintaining document consistency.
158128

159129
### How can I remove unused styles from a document?
160130

161-
You can remove unused styles from a document using Aspose.Words for Java. Here's an example:
131+
You can remove unused styles from a document using Aspose.Words for Java. Here's an example:
162132

163-
```java
164-
Document doc = new Document("document.docx");
165-
doc.cleanup();
166-
doc.save("cleaned_document.docx");
167-
```
133+
```java
134+
Document doc = new Document("document.docx");
135+
doc.cleanup();
136+
doc.save("cleaned_document.docx");
137+
```
168138

169139
### Is Aspose.Words for Java suitable for generating dynamic documents with XML data?
170140

171-
Yes, Aspose.Words for Java is well-suited for generating dynamic documents with XML data. It provides robust features for binding XML data to templates and creating personalized documents.
172-
173-
## Conclusion
174-
175-
In this extensive guide, we've explored the world of manipulating document content with cleanup, fields, and XML data using Aspose.Words for Java. You've learned how to clean up documents, work with fields, and incorporate XML data seamlessly. These skills are invaluable for anyone dealing with document management in Java applications.
141+
Yes, Aspose.Words for Java is well-suited for generating dynamic documents with XML data. It provides robust features for binding XML data to templates and creating personalized documents.

content/english/java/word-processing/mastering-advanced-save-settings/_index.md

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type: docs
77
weight: 13
88
url: /java/word-processing/mastering-advanced-save-settings/
99
---
10+
1011
Are you ready to take your document processing skills to the next level? In this comprehensive guide, we'll delve deep into mastering advanced save settings for documents using Aspose.Words for Java. Whether you're a seasoned developer or just getting started, we'll walk you through the intricacies of document manipulation with Aspose.Words for Java.
1112

1213
## Introduction
@@ -25,13 +26,13 @@ Learn how to specify the format and orientation of your documents. Whether it's
2526
```java
2627
// Set document format to DOCX
2728
Document doc = new Document();
28-
doc.save("output.docx", SaveFormat.DOCX);
29+
doc.save("output.docx");
2930

3031
// Set page orientation to Landscape
3132
Document docLandscape = new Document();
3233
PageSetup pageSetup = docLandscape.getFirstSection().getPageSetup();
3334
pageSetup.setOrientation(Orientation.LANDSCAPE);
34-
docLandscape.save("landscape.docx", SaveFormat.DOCX);
35+
docLandscape.save("landscape.docx");
3536
```
3637

3738
## Controlling Page Margins
@@ -46,7 +47,7 @@ pageSetup.setLeftMargin(72.0); // 1 inch
4647
pageSetup.setRightMargin(72.0); // 1 inch
4748
pageSetup.setTopMargin(36.0); // 0.5 inch
4849
pageSetup.setBottomMargin(36.0); // 0.5 inch
49-
doc.save("custom_margins.docx", SaveFormat.DOCX);
50+
doc.save("custom_margins.docx");
5051
```
5152

5253
## Managing Headers and Footers
@@ -56,11 +57,11 @@ Headers and footers often contain critical information. Explore how to manage an
5657
```java
5758
// Add a header to the first page
5859
Document doc = new Document();
59-
Section section = doc.getSections().get(0);
60+
Section section = doc.getFirstSection();
6061
HeaderFooter header = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_FIRST);
6162
header.appendChild(new Paragraph(doc));
6263
header.getFirstParagraph().appendChild(new Run(doc, "Header on the First Page"));
63-
doc.save("header_first_page.docx", SaveFormat.DOCX);
64+
doc.save("header_first_page.docx");
6465
```
6566

6667
## Embedding Fonts for Cross-Platform Viewing
@@ -74,7 +75,7 @@ FontSettings fontSettings = new FontSettings();
7475
fontSettings.setFontsFolder("C:\\Windows\\Fonts", true);
7576
doc.setFontSettings(fontSettings);
7677
doc.getStyles().get(StyleIdentifier.NORMAL).getFont().setName("Arial");
77-
doc.save("embedded_fonts.docx", SaveFormat.DOCX);
78+
doc.save("embedded_fonts.docx");
7879
```
7980

8081
## Protecting Your Documents
@@ -85,7 +86,7 @@ Security matters, especially when dealing with sensitive documents. Learn how to
8586
// Protect the document with a password
8687
Document doc = new Document();
8788
doc.protect(ProtectionType.READ_ONLY, "my_password");
88-
doc.save("protected_document.docx", SaveFormat.DOCX);
89+
doc.save("protected_document.docx");
8990
```
9091

9192
## Customizing Watermarks
@@ -100,7 +101,7 @@ watermark.getTextPath().setText("Confidential");
100101
watermark.setWidth(100);
101102
watermark.setHeight(50);
102103
doc.getFirstSection().getBody().getFirstParagraph().appendChild(watermark);
103-
doc.save("watermarked_document.docx", SaveFormat.DOCX);
104+
doc.save("watermarked_document.docx");
104105
```
105106

106107
## Optimizing Document Size
@@ -111,7 +112,7 @@ Large document files can be unwieldy. Discover techniques to optimize document s
111112
// Optimize document size
112113
Document doc = new Document("large_document.docx");
113114
doc.cleanup();
114-
doc.save("optimized_document.docx", SaveFormat.DOCX);
115+
doc.save("optimized_document.docx");
115116
```
116117

117118
## Exporting to Different Formats
@@ -121,7 +122,7 @@ Sometimes, you need your document in various formats. Aspose.Words for Java make
121122
```java
122123
// Export to PDF
123124
Document doc = new Document("document.docx");
124-
doc.save("document.pdf", SaveFormat.PDF);
125+
doc.save("document.pdf");
125126
```
126127

127128
## Automating Document Generation
@@ -133,7 +134,7 @@ Automation is a game-changer for document generation. Learn how to automate the
133134
Document doc = new Document();
134135
DocumentBuilder builder = new DocumentBuilder(doc);
135136
builder.write("Hello, World!");
136-
doc.save("automated_document.docx", SaveFormat.DOCX);
137+
doc.save("automated_document.docx");
137138
```
138139

139140
## Working with Document Metadata
@@ -143,24 +144,27 @@ Metadata contains valuable information about a document. We'll explore how to wo
143144
```java
144145
// Access and modify document metadata
145146
Document doc = new Document("document.docx");
146-
DocumentProperty authorProperty = doc.getBuiltInDocumentProperties().getAuthor();
147-
authorProperty.setValue("John Doe");
148-
doc.save("modified_metadata.docx", SaveFormat.DOCX);
147+
doc.getBuiltInDocumentProperties().setAuthor("John Doe");
148+
doc.save("modified_metadata.docx");
149149
```
150150

151151
## Handling Document Versions
152152

153153
Document versioning is crucial in collaborative environments. Find out how to manage different versions of your documents effectively.
154154

155155
```java
156-
// Compare document versions
157-
Document doc1 = new Document("version1.docx");
158-
Document doc2 = new Document("version2.docx");
159-
DocumentComparer comparer = new DocumentComparer(doc1, doc2);
160-
comparer.compare("comparison_result.docx");
161-
``
156+
Document docOriginal = new Document();
157+
DocumentBuilder builder = new DocumentBuilder(docOriginal);
158+
builder.writeln("This is the original document.");
159+
160+
Document docEdited = new Document();
161+
builder = new DocumentBuilder(docEdited);
162+
builder.writeln("This is the edited document.");
162163

163-
`
164+
// Comparing documents with revisions will throw an exception.
165+
if (docOriginal.getRevisions().getCount() == 0 && docEdited.getRevisions().getCount() == 0)
166+
docOriginal.compare(docEdited, "authorName", new Date());
167+
```
164168

165169
## Advanced Document Comparison
166170

@@ -217,7 +221,7 @@ Aspose.Words for Java supports exporting documents to various formats, including
217221

218222
```java
219223
Document doc = new Document("document.docx");
220-
doc.save("document.pdf", SaveFormat.PDF);
224+
doc.save("document.pdf");
221225
```
222226

223227
### Is Aspose.Words for Java suitable for batch document generation?
@@ -228,7 +232,7 @@ Yes, Aspose.Words for Java is well-suited for batch document generation, making
228232
Document doc = new Document();
229233
DocumentBuilder builder = new DocumentBuilder(doc);
230234
builder.write("Hello, World!");
231-
doc.save("automated_document.docx", SaveFormat.DOCX);
235+
doc.save("automated_document.docx");
232236
```
233237

234238
### How can I compare two Word documents for differences?

0 commit comments

Comments
 (0)