Skip to content

Commit 6bfdffd

Browse files
authored
Merge pull request #26 from aspose-words/staging
Staging
2 parents 95a95ef + 9dfb035 commit 6bfdffd

File tree

42 files changed

+1069
-1044
lines changed

Some content is hidden

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

42 files changed

+1069
-1044
lines changed

content/english/java/document-conversion-and-export/using-document-shapes/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ builder.writeln();
6767
shape = builder.insertShape(ShapeType.TEXT_BOX, 50.0, 50.0);
6868
shape.setRotation(30.0);
6969

70-
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.DOCX);
70+
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
7171
saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_TRANSITIONAL);
7272

7373
doc.save("Your Directory Path" + "WorkingWithShapes.InsertShape.docx", saveOptions);

content/english/java/document-converting/converting-documents-different-formats/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Now, it's time to convert the loaded document to the chosen output format. Aspos
4747

4848
```java
4949
// Convert the document to PDF
50-
doc.save("output.pdf", SaveFormat.PDF);
50+
doc.save("output.pdf");
5151
```
5252

5353
## Conclusion

content/english/java/document-converting/converting-documents-images/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Once the document is loaded, the next step is to set up the options for saving t
7171
`ImageSaveOptions` is a class that allows you to specify how the document should be saved as an image.
7272

7373
```java
74-
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
74+
ImageSaveOptions imageSaveOptions = new ImageSaveOptions();
7575
```
7676

7777
Explanation:

content/english/java/document-converting/document-conversion-saveoptions/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Next, you'll configure the save options for the document. This is where you can
4949

5050
```java
5151
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
52-
saveOptions.setSaveFormat(SaveFormat.EPUB);
52+
saveOptions.setSaveFormat();
5353
saveOptions.setEncoding(StandardCharsets.UTF_8);
5454
```
5555

content/english/java/document-converting/using-document-converting/_index.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Next, convert the loaded Word document to PDF:
5656

5757
```java
5858
// Save the document as PDF
59-
doc.save("output.pdf", SaveFormat.PDF);
59+
doc.save("output.pdf");
6060
```
6161

6262
## Step 4: Converting to Other Formats
@@ -67,21 +67,21 @@ Besides PDF, Aspose.Words for Java allows you to convert documents to various ot
6767

6868
```java
6969
// Save the document as RTF
70-
doc.save("output.rtf", SaveFormat.RTF);
70+
doc.save("output.rtf");
7171
```
7272

7373
### Converting to HTML
7474

7575
```java
7676
// Save the document as HTML
77-
doc.save("output.html", SaveFormat.HTML);
77+
doc.save("output.html");
7878
```
7979

8080
### Converting to EPUB
8181

8282
```java
8383
// Save the document as EPUB
84-
doc.save("output.epub", SaveFormat.EPUB);
84+
doc.save("output.epub");
8585
```
8686

8787
## Tips for Effective Document Converting

content/english/java/document-loading-and-saving/advance-html-documents-saving-options/_index.md

+71-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void exportRoundtripInformation() throws Exception {
2929
With the `exportFontsAsBase64` method, you can export fonts used in the document as Base64-encoded data in the HTML. This ensures that the HTML representation retains the same font styles as the original Word document.
3030

3131
```java
32-
@Test
32+
3333
public void exportFontsAsBase64() throws Exception {
3434
Document doc = new Document("Your Directory Path" + "Rendering.docx");
3535
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
@@ -42,7 +42,7 @@ public void exportFontsAsBase64() throws Exception {
4242
The `exportResources` method allows you to specify the type of CSS stylesheet and export font resources. You can also set a resource folder and an alias for resources in the HTML.
4343

4444
```java
45-
@Test
45+
4646
public void exportResources() throws Exception {
4747
Document doc = new Document("Your Directory Path" + "Rendering.docx");
4848
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
@@ -58,27 +58,48 @@ public void exportResources() throws Exception {
5858
The `convertMetafilesToEmfOrWmf` method allows you to convert metafiles in the document to either EMF or WMF format, ensuring compatibility and smooth rendering in HTML.
5959

6060
```java
61-
@Test
61+
6262
public void convertMetafilesToEmfOrWmf() throws Exception {
63-
// Code snippet not shown for brevity.
63+
64+
string dataDir = "Your Document Directory";
65+
Document doc = new Document();
66+
DocumentBuilder builder = new DocumentBuilder(doc);
67+
68+
builder.write("Here is an image as is: ");
69+
builder.insertHtml(
70+
"<img src=\"data:image/png;base64,\r\n iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAABGdBTUEAALGP\r\n C/xhBQAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9YGARc5KB0XV+IA\r\n AAAddEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIFRoZSBHSU1Q72QlbgAAAF1J\r\n REFUGNO9zL0NglAAxPEfdLTs4BZM4DIO4C7OwQg2JoQ9LE1exdlYvBBeZ7jq\r\n ch9//q1uH4TLzw4d6+ErXMMcXuHWxId3KOETnnXXV6MJpcq2MLaI97CER3N0\r\n vr4MkhoXe0rZigAAAABJRU5ErkJggg==\" alt=\"Red dot\" />");
71+
72+
HtmlSaveOptions saveOptions = new HtmlSaveOptions(); { saveOptions.setMetafileFormat(HtmlMetafileFormat.EMF_OR_WMF); }
73+
74+
doc.save(dataDir + "WorkingWithHtmlSaveOptions.ConvertMetafilesToEmfOrWmf.html", saveOptions);
6475
}
6576
```
6677

6778
## 6. Convert Metafiles to SVG
6879
Use the `convertMetafilesToSvg` method to convert metafiles to SVG format. This format is ideal for displaying vector graphics in HTML documents.
6980

7081
```java
71-
@Test
82+
7283
public void convertMetafilesToSvg() throws Exception {
73-
// Code snippet not shown for brevity.
84+
string dataDir = "Your Document Directory";
85+
Document doc = new Document();
86+
DocumentBuilder builder = new DocumentBuilder(doc);
87+
88+
builder.write("Here is an SVG image: ");
89+
builder.insertHtml(
90+
"<svg height='210' width='500'>\r\n <polygon points='100,10 40,198 190,78 10,78 160,198' \r\n style='fill:lime;stroke:purple;stroke-width:5;fill-rule:evenodd;' />\r\n </svg> ");
91+
92+
HtmlSaveOptions saveOptions = new HtmlSaveOptions(); { saveOptions.setMetafileFormat(HtmlMetafileFormat.SVG); }
93+
94+
doc.save(dataDir + "WorkingWithHtmlSaveOptions.ConvertMetafilesToSvg.html", saveOptions);
7495
}
7596
```
7697

7798
## 7. Add CSS Class Name Prefix
7899
With the `addCssClassNamePrefix` method, you can add a prefix to CSS class names in the exported HTML. This helps prevent conflicts with existing styles.
79100

80101
```java
81-
@Test
102+
82103
public void addCssClassNamePrefix() throws Exception {
83104
Document doc = new Document("Your Directory Path" + "Rendering.docx");
84105
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
@@ -92,36 +113,71 @@ public void addCssClassNamePrefix() throws Exception {
92113
The `exportCidUrlsForMhtmlResources` method is used when saving documents in MHTML format. It allows exporting Content-ID URLs for resources.
93114

94115
```java
95-
@Test
116+
96117
public void exportCidUrlsForMhtmlResources() throws Exception {
97-
// Code snippet not shown for brevity.
118+
string dataDir = "Your Document Directory";
119+
Document doc = new Document(dataDir + "Content-ID.docx");
120+
121+
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.MHTML);
122+
{
123+
saveOptions.setPrettyFormat(true); saveOptions.setExportCidUrlsForMhtmlResources(true);
124+
}
125+
126+
doc.save(dataDir + "WorkingWithHtmlSaveOptions.ExportCidUrlsForMhtmlResources.mhtml", saveOptions);
98127
}
99128
```
100129

101130
## 9. Resolve Font Names
102131
The `resolveFontNames` method helps resolve font names when saving documents in HTML format, ensuring consistent rendering across different platforms.
103132

104133
```java
105-
@Test
134+
106135
public void resolveFontNames() throws Exception {
107-
// Code snippet not shown for brevity.
136+
137+
string dataDir = "Your Document Directory";
138+
Document doc = new Document(dataDir + "Missing font.docx");
139+
140+
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);
141+
{
142+
saveOptions.setPrettyFormat(true); saveOptions.setResolveFontNames(true);
143+
}
144+
145+
doc.save(dataDir + "WorkingWithHtmlSaveOptions.ResolveFontNames.html", saveOptions);
108146
}
109147
```
110148

111149
## 10. Export Text Input Form Field as Text
112150
The `exportTextInputFormFieldAsText` method exports form fields as plain text in the HTML, making them easily readable and editable.
113151

114152
```java
115-
@Test
153+
116154
public void exportTextInputFormFieldAsText() throws Exception {
117-
// Code snippet not shown for brevity.
155+
156+
string dataDir = "Your Document Directory";
157+
Document doc = new Document(dataDir + "Rendering.docx");
158+
159+
String imagesDir = Path.combine(dataDir, "Images");
160+
161+
// The folder specified needs to exist and should be empty.
162+
if (Directory.exists(imagesDir))
163+
Directory.delete(imagesDir, true);
164+
165+
Directory.createDirectory(imagesDir);
166+
167+
// Set an option to export form fields as plain text, not as HTML input elements.
168+
HtmlSaveOptions saveOptions = new HtmlSaveOptions(SaveFormat.HTML);
169+
{
170+
saveOptions.setExportTextInputFormFieldAsText(true); saveOptions.setImagesFolder(imagesDir);
171+
}
172+
173+
doc.save(dataDir + "WorkingWithHtmlSaveOptions.ExportTextInputFormFieldAsText.html", saveOptions);
118174
}
119175
```
120176

121-
## 11. Conclusion
177+
## Conclusion
122178
In this tutorial, we explored the advanced HTML document saving options provided by Aspose.Words for Java. These options give you fine-grained control over the conversion process, allowing you to create HTML documents that closely resemble the original Word documents.
123179

124-
## 12. FAQs
180+
## FAQ's
125181
Here are some frequently asked questions about working with Aspose.Words for Java and HTML document saving options:
126182

127183
### Q1: How can I convert HTML back to Word format using Aspose.Words for Java?

content/english/java/document-loading-and-saving/loading-and-saving-html-documents/_index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ In this code, we create an HTML string and use `HtmlLoadOptions` to specify that
4848
Now that we have loaded the HTML into a `Document`, we can save it as a Word document. Let's save it in DOCX format:
4949

5050
```java
51-
doc.save("Your Directory Path" + "WorkingWithHtmlLoadOptions.PreferredControlType.docx", SaveFormat.DOCX);
51+
doc.save("Your Directory Path" + "WorkingWithHtmlLoadOptions.PreferredControlType.docx");
5252
```
5353

5454
This code saves the `Document` as a DOCX file, which is a common format for Word documents.
@@ -68,7 +68,7 @@ HtmlLoadOptions loadOptions = new HtmlLoadOptions();
6868
loadOptions.setPreferredControlType(HtmlControlType.STRUCTURED_DOCUMENT_TAG);
6969
}
7070
Document doc = new Document(new ByteArrayInputStream(HTML.getBytes(StandardCharsets.UTF_8)), loadOptions);
71-
doc.save("Your Directory Path" + "WorkingWithHtmlLoadOptions.PreferredControlType.docx", SaveFormat.DOCX);
71+
doc.save("Your Directory Path" + "WorkingWithHtmlLoadOptions.PreferredControlType.docx");
7272
```
7373

7474
## Conclusion

content/english/java/document-loading-and-saving/saving-documents-as-ooxml-format/_index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ import com.aspose.words.SaveFormat;
9191
Document doc = new Document("LegacyControlChars.doc");
9292

9393
// Create OoxmlSaveOptions with the FLAT_OPC format and enable keeping legacy control characters
94-
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.FLAT_OPC);
94+
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
9595
saveOptions.setKeepLegacyControlChars(true);
9696

9797
// Save the document with legacy control characters
@@ -148,7 +148,7 @@ public void updateLastSavedTimeProperty() throws Exception
148148
public void keepLegacyControlChars() throws Exception
149149
{
150150
Document doc = new Document("Your Directory Path" + "Legacy control character.doc");
151-
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.FLAT_OPC); { saveOptions.setKeepLegacyControlChars(true); }
151+
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(); { saveOptions.setKeepLegacyControlChars(true); }
152152
doc.save("Your Directory Path" + "WorkingWithOoxmlSaveOptions.KeepLegacyControlChars.docx", saveOptions);
153153
}
154154
@Test

content/english/java/document-loading-and-saving/saving-documents-as-pcl-format/_index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Next, you'll need to configure the PCL save options. These options specify the f
3535
```java
3636
PclSaveOptions saveOptions = new PclSaveOptions();
3737
{
38-
saveOptions.setSaveFormat(SaveFormat.PCL);
38+
saveOptions.setSaveFormat();
3939
saveOptions.setRasterizeTransformedElements(false);
4040
}
4141
```
@@ -56,7 +56,7 @@ Replace `"YourPCLDocument.pcl"` with the desired name for your PCL file.
5656
Document doc = new Document("Your Directory Path" + "Rendering.docx");
5757
PclSaveOptions saveOptions = new PclSaveOptions();
5858
{
59-
saveOptions.setSaveFormat(SaveFormat.PCL); saveOptions.setRasterizeTransformedElements(false);
59+
saveOptions.setSaveFormat(); saveOptions.setRasterizeTransformedElements(false);
6060
}
6161
doc.save("Your Directory Path" + "WorkingWithPclSaveOptions.RasterizeTransformedElements.pcl", saveOptions);
6262
```

content/english/java/document-loading-and-saving/saving-images-from-documents/_index.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ To save images as TIFF format with threshold control, follow these steps:
2222

2323
```java
2424
Document doc = new Document("Your Directory Path" + "Rendering.docx");
25-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.TIFF);
25+
ImageSaveOptions saveOptions = new ImageSaveOptions();
2626
saveOptions.setTiffCompression(TiffCompression.CCITT_3);
2727
saveOptions.setImageColorMode(ImageColorMode.GRAYSCALE);
2828
saveOptions.setTiffBinarizationMethod(ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING);
@@ -36,7 +36,7 @@ To save a specific page as a multipage TIFF, use the following code:
3636

3737
```java
3838
Document doc = new Document("Your Directory Path" + "Rendering.docx");
39-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.TIFF);
39+
ImageSaveOptions saveOptions = new ImageSaveOptions();
4040
saveOptions.setPageSet(new PageSet(new PageRange(0, 1)));
4141
saveOptions.setTiffCompression(TiffCompression.CCITT_4);
4242
saveOptions.setResolution(160f);
@@ -49,7 +49,7 @@ To save images as 1 BPP indexed PNG, follow these steps:
4949

5050
```java
5151
Document doc = new Document("Your Directory Path" + "Rendering.docx");
52-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
52+
ImageSaveOptions saveOptions = new ImageSaveOptions();
5353
saveOptions.setPageSet(new PageSet(1));
5454
saveOptions.setImageColorMode(ImageColorMode.BLACK_AND_WHITE);
5555
saveOptions.setPixelFormat(ImagePixelFormat.FORMAT_1_BPP_INDEXED);
@@ -62,7 +62,7 @@ To save a specific page as JPEG with customization options, use this code:
6262

6363
```java
6464
Document doc = new Document("Your Directory Path" + "Rendering.docx");
65-
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
65+
ImageSaveOptions options = new ImageSaveOptions();
6666
options.setPageSet(new PageSet(0));
6767
options.setImageBrightness(0.3f);
6868
options.setImageContrast(0.7f);
@@ -76,7 +76,7 @@ You can use a callback to customize page saving. Here's an example:
7676

7777
```java
7878
Document doc = new Document("Your Directory Path" + "Rendering.docx");
79-
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
79+
ImageSaveOptions imageSaveOptions = new ImageSaveOptions();
8080
imageSaveOptions.setPageSet(new PageSet(new PageRange(0, doc.getPageCount() - 1)));
8181
imageSaveOptions.setPageSavingCallback(new HandlePageSavingCallback());
8282
doc.save("Your Directory Path" + "PageSavingCallback.png", imageSaveOptions);
@@ -96,7 +96,7 @@ private static class HandlePageSavingCallback implements IPageSavingCallback {
9696
public void exposeThresholdControlForTiffBinarization() throws Exception
9797
{
9898
Document doc = new Document("Your Directory Path" + "Rendering.docx");
99-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.TIFF);
99+
ImageSaveOptions saveOptions = new ImageSaveOptions();
100100
{
101101
saveOptions.setTiffCompression(TiffCompression.CCITT_3);
102102
saveOptions.setImageColorMode(ImageColorMode.GRAYSCALE);
@@ -110,7 +110,7 @@ public void getTiffPageRange() throws Exception
110110
{
111111
Document doc = new Document("Your Directory Path" + "Rendering.docx");
112112
doc.save("Your Directory Path" + "WorkingWithImageSaveOptions.MultipageTiff.tiff");
113-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.TIFF);
113+
ImageSaveOptions saveOptions = new ImageSaveOptions();
114114
{
115115
saveOptions.setPageSet(new PageSet(new PageRange(0, 1))); saveOptions.setTiffCompression(TiffCompression.CCITT_4); saveOptions.setResolution(160f);
116116
}
@@ -120,7 +120,7 @@ public void getTiffPageRange() throws Exception
120120
public void format1BppIndexed() throws Exception
121121
{
122122
Document doc = new Document("Your Directory Path" + "Rendering.docx");
123-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
123+
ImageSaveOptions saveOptions = new ImageSaveOptions();
124124
{
125125
saveOptions.setPageSet(new PageSet(1));
126126
saveOptions.setImageColorMode(ImageColorMode.BLACK_AND_WHITE);
@@ -132,7 +132,7 @@ public void format1BppIndexed() throws Exception
132132
public void getJpegPageRange() throws Exception
133133
{
134134
Document doc = new Document("Your Directory Path" + "Rendering.docx");
135-
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
135+
ImageSaveOptions options = new ImageSaveOptions();
136136
// Set the "PageSet" to "0" to convert only the first page of a document.
137137
options.setPageSet(new PageSet(0));
138138
// Change the image's brightness and contrast.
@@ -148,7 +148,7 @@ public void getJpegPageRange() throws Exception
148148
public static void pageSavingCallback() throws Exception
149149
{
150150
Document doc = new Document("Your Directory Path" + "Rendering.docx");
151-
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
151+
ImageSaveOptions imageSaveOptions = new ImageSaveOptions();
152152
{
153153
imageSaveOptions.setPageSet(new PageSet(new PageRange(0, doc.getPageCount() - 1)));
154154
imageSaveOptions.setPageSavingCallback(new HandlePageSavingCallback());
@@ -174,7 +174,7 @@ You have learned how to save images from documents using Aspose.Words for Java.
174174
You can change the image format by specifying the desired format in the `ImageSaveOptions`. For example, to save as PNG, use `SaveFormat.PNG` as shown in the code:
175175

176176
```java
177-
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
177+
ImageSaveOptions saveOptions = new ImageSaveOptions();
178178
```
179179

180180
### Can I customize the compression settings for TIFF images?

content/english/java/document-loading-and-saving/using-load-options/_index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ LoadOptions loadOptions = new LoadOptions();
4343
loadOptions.setConvertShapeToOfficeMath(true);
4444

4545
Document doc = new Document("Your Directory Path" + "Office math.docx", loadOptions);
46-
doc.save("Your Directory Path" + "WorkingWithLoadOptions.ConvertShapeToOfficeMath.docx", SaveFormat.DOCX);
46+
doc.save("Your Directory Path" + "WorkingWithLoadOptions.ConvertShapeToOfficeMath.docx");
4747
```
4848

4949
This code demonstrates how to convert shapes to Office Math objects during document loading. The `setConvertShapeToOfficeMath(true)` method enables this conversion.
@@ -136,7 +136,7 @@ public void convertShapeToOfficeMath() throws Exception {
136136
loadOptions.setConvertShapeToOfficeMath(true);
137137
}
138138
Document doc = new Document("Your Directory Path" + "Office math.docx", loadOptions);
139-
doc.save("Your Directory Path" + "WorkingWithLoadOptions.ConvertShapeToOfficeMath.docx", SaveFormat.DOCX);
139+
doc.save("Your Directory Path" + "WorkingWithLoadOptions.ConvertShapeToOfficeMath.docx");
140140
}
141141
@Test
142142
public void setMsWordVersion() throws Exception {

0 commit comments

Comments
 (0)