public abstract class FixedPageSaveOptions extends SaveOptions
To learn more, visit the Specify Save Options documentation article.
Examples:
Shows how to render one page from a document to a JPEG image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 3.");
// Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
// to modify the way in which that method renders the document into an image.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
// Set the "PageSet" to "1" to select the second page via
// the zero-based index to start rendering the document from.
options.setPageSet(new PageSet(1));
// When we save the document to the JPEG format, Aspose.Words only renders one page.
// This image will contain one page starting from page two,
// which will just be the second page of the original document.
doc.save(getArtifactsDir() + "ImageSaveOptions.OnePage.jpg", options);
Shows how to render every page of a document to a separate TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 3.");
// Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
// to modify the way in which that method renders the document into an image.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.TIFF);
for (int i = 0; i < doc.getPageCount(); i++) {
// Set the "PageSet" property to the number of the first page from
// which to start rendering the document from.
options.setPageSet(new PageSet(i));
// Export page at 2325x5325 pixels and 600 dpi.
options.setResolution(600f);
options.setImageSize(new Dimension(2325, 5325));
doc.save(getArtifactsDir() + MessageFormat.format("ImageSaveOptions.PageByPage.{0}.tiff", i + 1), options);
}
| Modifier | Constructor and Description |
|---|---|
protected |
FixedPageSaveOptions()
Initializes a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
protected static void |
assertValidIdPrefix(java.lang.String prefix) |
boolean |
equals(java.lang.Object obj)
Determines whether the specified object is equal in value to the current object.
|
int |
getColorMode()
Gets a value determining how colors are rendered.
|
int |
getJpegQuality()
Gets a value determining the quality of the JPEG images inside Html document.
|
MetafileRenderingOptions |
getMetafileRenderingOptions()
Allows to specify metafile rendering options.
|
int |
getNumeralFormat()
Gets
NumeralFormat used for rendering of numerals. |
boolean |
getOptimizeOutput()
Flag indicates whether it is required to optimize output.
|
IPageSavingCallback |
getPageSavingCallback()
Allows to control how separate pages are saved when a document is exported to fixed page format.
|
PageSet |
getPageSet()
Gets the pages to render.
|
protected static boolean |
isValidIdPrefix(java.lang.String prefix) |
void |
setColorMode(int value)
Sets a value determining how colors are rendered.
|
void |
setJpegQuality(int value)
Sets a value determining the quality of the JPEG images inside Html document.
|
void |
setMetafileRenderingOptions(MetafileRenderingOptions value)
Allows to specify metafile rendering options.
|
void |
setNumeralFormat(int value)
Sets
NumeralFormat used for rendering of numerals. |
void |
setOptimizeOutput(boolean value)
Flag indicates whether it is required to optimize output.
|
void |
setPageSavingCallback(IPageSavingCallback value)
Allows to control how separate pages are saved when a document is exported to fixed page format.
|
void |
setPageSet(PageSet value)
Sets the pages to render.
|
createSaveOptions, createSaveOptions, getAllowEmbeddingPostScriptFonts, getCustomTimeZoneInfo, getDefaultTemplate, getDml3DEffectsRenderingMode, getDmlEffectsRenderingMode, getDmlRenderingMode, getExportGeneratorName, getImlRenderingMode, getMemoryOptimization, getPrettyFormat, getProgressCallback, getSaveFormat, getTempFolder, getUpdateAmbiguousTextFont, getUpdateCreatedTimeProperty, getUpdateFields, getUpdateLastPrintedProperty, getUpdateLastSavedTimeProperty, getUseAntiAliasing, getUseHighQualityRendering, setAllowEmbeddingPostScriptFonts, setCustomTimeZoneInfo, setDefaultTemplate, setDml3DEffectsRenderingMode, setDmlEffectsRenderingMode, setDmlRenderingMode, setExportGeneratorName, setImlRenderingMode, setMemoryOptimization, setPrettyFormat, setProgressCallback, setSaveFormat, setTempFolder, setUpdateAmbiguousTextFont, setUpdateCreatedTimeProperty, setUpdateFields, setUpdateLastPrintedProperty, setUpdateLastSavedTimeProperty, setUseAntiAliasing, setUseHighQualityRenderingprotected FixedPageSaveOptions()
public PageSet getPageSet()
Examples:
Shows how to extract pages based on exact page indices.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add five pages to the document.
for (int i = 1; i < 6; i++) {
builder.write("Page " + i);
builder.insertBreak(BreakType.PAGE_BREAK);
}
// Create an "XpsSaveOptions" object, which we can pass to the document's "Save" method
// to modify how that method converts the document to .XPS.
XpsSaveOptions xpsOptions = new XpsSaveOptions();
// Use the "PageSet" property to select a set of the document's pages to save to output XPS.
// In this case, we will choose, via a zero-based index, only three pages: page 1, page 2, and page 4.
xpsOptions.setPageSet(new PageSet(0, 1, 3));
doc.save(getArtifactsDir() + "XpsSaveOptions.ExportExactPages.xps", xpsOptions);
Shows how to convert only some of the pages in a document to PDF.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 3.");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
PdfSaveOptions options = new PdfSaveOptions();
// Set the "PageIndex" to "1" to render a portion of the document starting from the second page.
options.setPageSet(new PageSet(1));
// This document will contain one page starting from page two, which will only contain the second page.
doc.save(new FileOutputStream(getArtifactsDir() + "PdfSaveOptions.OnePage.pdf"), options);
Shows how to export Odd pages from the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
for (int i = 0; i < 5; i++) {
builder.writeln(MessageFormat.format("Page {0} ({1})", i + 1, (i % 2 == 0 ? "odd" : "even")));
if (i < 4)
builder.insertBreak(BreakType.PAGE_BREAK);
}
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
PdfSaveOptions options = new PdfSaveOptions();
// Below are three PageSet properties that we can use to filter out a set of pages from
// our document to save in an output PDF document based on the parity of their page numbers.
// 1 - Save only the even-numbered pages:
options.setPageSet(PageSet.getEven());
doc.save(getArtifactsDir() + "PdfSaveOptions.ExportPageSet.Even.pdf", options);
// 2 - Save only the odd-numbered pages:
options.setPageSet(PageSet.getOdd());
doc.save(getArtifactsDir() + "PdfSaveOptions.ExportPageSet.Odd.pdf", options);
// 3 - Save every page:
options.setPageSet(PageSet.getAll());
doc.save(getArtifactsDir() + "PdfSaveOptions.ExportPageSet.All.pdf", options);
public void setPageSet(PageSet value)
Examples:
Shows how to extract pages based on exact page indices.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add five pages to the document.
for (int i = 1; i < 6; i++) {
builder.write("Page " + i);
builder.insertBreak(BreakType.PAGE_BREAK);
}
// Create an "XpsSaveOptions" object, which we can pass to the document's "Save" method
// to modify how that method converts the document to .XPS.
XpsSaveOptions xpsOptions = new XpsSaveOptions();
// Use the "PageSet" property to select a set of the document's pages to save to output XPS.
// In this case, we will choose, via a zero-based index, only three pages: page 1, page 2, and page 4.
xpsOptions.setPageSet(new PageSet(0, 1, 3));
doc.save(getArtifactsDir() + "XpsSaveOptions.ExportExactPages.xps", xpsOptions);
Shows how to convert only some of the pages in a document to PDF.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 3.");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
PdfSaveOptions options = new PdfSaveOptions();
// Set the "PageIndex" to "1" to render a portion of the document starting from the second page.
options.setPageSet(new PageSet(1));
// This document will contain one page starting from page two, which will only contain the second page.
doc.save(new FileOutputStream(getArtifactsDir() + "PdfSaveOptions.OnePage.pdf"), options);
Shows how to export Odd pages from the document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
for (int i = 0; i < 5; i++) {
builder.writeln(MessageFormat.format("Page {0} ({1})", i + 1, (i % 2 == 0 ? "odd" : "even")));
if (i < 4)
builder.insertBreak(BreakType.PAGE_BREAK);
}
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
PdfSaveOptions options = new PdfSaveOptions();
// Below are three PageSet properties that we can use to filter out a set of pages from
// our document to save in an output PDF document based on the parity of their page numbers.
// 1 - Save only the even-numbered pages:
options.setPageSet(PageSet.getEven());
doc.save(getArtifactsDir() + "PdfSaveOptions.ExportPageSet.Even.pdf", options);
// 2 - Save only the odd-numbered pages:
options.setPageSet(PageSet.getOdd());
doc.save(getArtifactsDir() + "PdfSaveOptions.ExportPageSet.Odd.pdf", options);
// 3 - Save every page:
options.setPageSet(PageSet.getAll());
doc.save(getArtifactsDir() + "PdfSaveOptions.ExportPageSet.All.pdf", options);
value - The pages to render.public IPageSavingCallback getPageSavingCallback()
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 3.");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();
// We will save each page in this document to a separate HTML file in the local file system.
// Set a callback that allows us to name each output HTML document.
htmlFixedSaveOptions.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
/// <summary>
/// Saves all pages to a file and directory specified within.
/// </summary>
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// Below are two ways of specifying where Aspose.Words will save each page of the document.
// 1 - Set a filename for the output page file:
args.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
IPageSavingCallback value.public void setPageSavingCallback(IPageSavingCallback value)
Examples:
Shows how to use a callback to save a document to HTML page by page.
public void pageFileNames() throws Exception {
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("Page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 2.");
builder.insertImage(getImageDir() + "Logo.jpg");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page 3.");
// Create an "HtmlFixedSaveOptions" object, which we can pass to the document's "Save" method
// to modify how we convert the document to HTML.
HtmlFixedSaveOptions htmlFixedSaveOptions = new HtmlFixedSaveOptions();
// We will save each page in this document to a separate HTML file in the local file system.
// Set a callback that allows us to name each output HTML document.
htmlFixedSaveOptions.setPageSavingCallback(new CustomFileNamePageSavingCallback());
doc.save(getArtifactsDir() + "SavingCallback.PageFileNames.html", htmlFixedSaveOptions);
String[] filePaths = DocumentHelper.directoryGetFiles(getArtifactsDir(), "SavingCallback.PageFileNames.Page_*").toArray(new String[0]);
Assert.assertEquals(3, filePaths.length);
}
/// <summary>
/// Saves all pages to a file and directory specified within.
/// </summary>
private static class CustomFileNamePageSavingCallback implements IPageSavingCallback {
public void pageSaving(PageSavingArgs args) throws Exception {
String outFileName = MessageFormat.format("{0}SavingCallback.PageFileNames.Page_{1}.html", getArtifactsDir(), args.getPageIndex());
// Below are two ways of specifying where Aspose.Words will save each page of the document.
// 1 - Set a filename for the output page file:
args.setPageFileName(outFileName);
// 2 - Create a custom stream for the output page file:
try (FileOutputStream outputStream = new FileOutputStream(outFileName)) {
args.setPageStream(outputStream);
}
Assert.assertFalse(args.getKeepPageStreamOpen());
}
}
value - The corresponding IPageSavingCallback value.public int getNumeralFormat()
NumeralFormat used for rendering of numerals. European numerals are used by default.
Remarks:
If the value of this property is changed and page layout is already built then Document.updatePageLayout() is invoked automatically to update any changes.
Examples:
Shows how to set the numeral format used when saving to PDF.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setLocaleId(1025);
builder.writeln("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
PdfSaveOptions options = new PdfSaveOptions();
// Set the "NumeralFormat" property to "NumeralFormat.ArabicIndic" to
// use glyphs from the U+0660 to U+0669 range as numbers.
// Set the "NumeralFormat" property to "NumeralFormat.Context" to
// look up the locale to determine what number of glyphs to use.
// Set the "NumeralFormat" property to "NumeralFormat.EasternArabicIndic" to
// use glyphs from the U+06F0 to U+06F9 range as numbers.
// Set the "NumeralFormat" property to "NumeralFormat.European" to use european numerals.
// Set the "NumeralFormat" property to "NumeralFormat.System" to determine the symbol set from regional settings.
options.setNumeralFormat(numeralFormat);
doc.save(getArtifactsDir() + "PdfSaveOptions.SetNumeralFormat.pdf", options);
NumeralFormat used for rendering of numerals. The returned value is one of NumeralFormat constants.public void setNumeralFormat(int value)
NumeralFormat used for rendering of numerals. European numerals are used by default.
Remarks:
If the value of this property is changed and page layout is already built then Document.updatePageLayout() is invoked automatically to update any changes.
Examples:
Shows how to set the numeral format used when saving to PDF.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setLocaleId(1025);
builder.writeln("1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
PdfSaveOptions options = new PdfSaveOptions();
// Set the "NumeralFormat" property to "NumeralFormat.ArabicIndic" to
// use glyphs from the U+0660 to U+0669 range as numbers.
// Set the "NumeralFormat" property to "NumeralFormat.Context" to
// look up the locale to determine what number of glyphs to use.
// Set the "NumeralFormat" property to "NumeralFormat.EasternArabicIndic" to
// use glyphs from the U+06F0 to U+06F9 range as numbers.
// Set the "NumeralFormat" property to "NumeralFormat.European" to use european numerals.
// Set the "NumeralFormat" property to "NumeralFormat.System" to determine the symbol set from regional settings.
options.setNumeralFormat(numeralFormat);
doc.save(getArtifactsDir() + "PdfSaveOptions.SetNumeralFormat.pdf", options);
value - NumeralFormat used for rendering of numerals. The value must be one of NumeralFormat constants.public MetafileRenderingOptions getMetafileRenderingOptions()
Examples:
Shows added a fallback to bitmap rendering and changing type of warnings about unsupported metafile records.
public void handleBinaryRasterWarnings() throws Exception {
Document doc = new Document(getMyDir() + "WMF with image.docx");
MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions();
// Set the "EmulateRasterOperations" property to "false" to fall back to bitmap when
// it encounters a metafile, which will require raster operations to render in the output PDF.
metafileRenderingOptions.setEmulateRasterOperations(false);
// Set the "RenderingMode" property to "VectorWithFallback" to try to render every metafile using vector graphics.
metafileRenderingOptions.setRenderingMode(MetafileRenderingMode.VECTOR_WITH_FALLBACK);
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF and applies the configuration
// in our MetafileRenderingOptions object to the saving operation.
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setMetafileRenderingOptions(metafileRenderingOptions);
HandleDocumentWarnings callback = new HandleDocumentWarnings();
doc.setWarningCallback(callback);
doc.save(getArtifactsDir() + "PdfSaveOptions.HandleBinaryRasterWarnings.pdf", saveOptions);
Assert.assertEquals(1, callback.mWarnings.getCount());
Assert.assertEquals("'R2_XORPEN' binary raster operation is not supported.",
callback.mWarnings.get(0).getDescription());
}
/// <summary>
/// Prints and collects formatting loss-related warnings that occur upon saving a document.
/// </summary>
public static class HandleDocumentWarnings implements IWarningCallback {
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.MINOR_FORMATTING_LOSS) {
System.out.println("Unsupported operation: " + info.getDescription());
this.mWarnings.warning(info);
}
}
public WarningInfoCollection mWarnings = new WarningInfoCollection();
}
MetafileRenderingOptions value.public void setMetafileRenderingOptions(MetafileRenderingOptions value)
Examples:
Shows added a fallback to bitmap rendering and changing type of warnings about unsupported metafile records.
public void handleBinaryRasterWarnings() throws Exception {
Document doc = new Document(getMyDir() + "WMF with image.docx");
MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions();
// Set the "EmulateRasterOperations" property to "false" to fall back to bitmap when
// it encounters a metafile, which will require raster operations to render in the output PDF.
metafileRenderingOptions.setEmulateRasterOperations(false);
// Set the "RenderingMode" property to "VectorWithFallback" to try to render every metafile using vector graphics.
metafileRenderingOptions.setRenderingMode(MetafileRenderingMode.VECTOR_WITH_FALLBACK);
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF and applies the configuration
// in our MetafileRenderingOptions object to the saving operation.
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setMetafileRenderingOptions(metafileRenderingOptions);
HandleDocumentWarnings callback = new HandleDocumentWarnings();
doc.setWarningCallback(callback);
doc.save(getArtifactsDir() + "PdfSaveOptions.HandleBinaryRasterWarnings.pdf", saveOptions);
Assert.assertEquals(1, callback.mWarnings.getCount());
Assert.assertEquals("'R2_XORPEN' binary raster operation is not supported.",
callback.mWarnings.get(0).getDescription());
}
/// <summary>
/// Prints and collects formatting loss-related warnings that occur upon saving a document.
/// </summary>
public static class HandleDocumentWarnings implements IWarningCallback {
public void warning(WarningInfo info) {
if (info.getWarningType() == WarningType.MINOR_FORMATTING_LOSS) {
System.out.println("Unsupported operation: " + info.getDescription());
this.mWarnings.warning(info);
}
}
public WarningInfoCollection mWarnings = new WarningInfoCollection();
}
value - The corresponding MetafileRenderingOptions value.public int getJpegQuality()
Remarks:
Has effect only when a document contains JPEG images.
Use this property to get or set the quality of the images inside a document when saving in fixed page format. The value may vary from 0 to 100 where 0 means worst quality but maximum compression and 100 means best quality but minimum compression.
The default value is 95.
Examples:
Shows how to configure compression while saving a document as a JPEG.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(getImageDir() + "Logo.jpg");
// Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
// to modify the way in which that method renders the document into an image.
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.JPEG);
// Set the "JpegQuality" property to "10" to use stronger compression when rendering the document.
// This will reduce the file size of the document, but the image will display more prominent compression artifacts.
imageOptions.setJpegQuality(10);
doc.save(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighCompression.jpg", imageOptions);
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighCompression.jpg").length() <= 20000);
// Set the "JpegQuality" property to "100" to use weaker compression when rending the document.
// This will improve the quality of the image at the cost of an increased file size.
imageOptions.setJpegQuality(100);
doc.save(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighQuality.jpg", imageOptions);
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighQuality.jpg").length() < 60000);
public void setJpegQuality(int value)
Remarks:
Has effect only when a document contains JPEG images.
Use this property to get or set the quality of the images inside a document when saving in fixed page format. The value may vary from 0 to 100 where 0 means worst quality but maximum compression and 100 means best quality but minimum compression.
The default value is 95.
Examples:
Shows how to configure compression while saving a document as a JPEG.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(getImageDir() + "Logo.jpg");
// Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
// to modify the way in which that method renders the document into an image.
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.JPEG);
// Set the "JpegQuality" property to "10" to use stronger compression when rendering the document.
// This will reduce the file size of the document, but the image will display more prominent compression artifacts.
imageOptions.setJpegQuality(10);
doc.save(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighCompression.jpg", imageOptions);
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighCompression.jpg").length() <= 20000);
// Set the "JpegQuality" property to "100" to use weaker compression when rending the document.
// This will improve the quality of the image at the cost of an increased file size.
imageOptions.setJpegQuality(100);
doc.save(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighQuality.jpg", imageOptions);
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.JpegQuality.HighQuality.jpg").length() < 60000);
value - A value determining the quality of the JPEG images inside Html document.public int getColorMode()
Remarks:
The default value is ColorMode.NORMAL.
Examples:
Shows how to change image color with saving options property.
Document doc = new Document(getMyDir() + "Images.docx");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
// Set the "ColorMode" property to "Grayscale" to render all images from the document in black and white.
// The size of the output document may be larger with this setting.
// Set the "ColorMode" property to "Normal" to render all images in color.
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
{
pdfSaveOptions.setColorMode(colorMode);
}
doc.save(getArtifactsDir() + "PdfSaveOptions.ColorRendering.pdf", pdfSaveOptions);
ColorMode constants.public void setColorMode(int value)
Remarks:
The default value is ColorMode.NORMAL.
Examples:
Shows how to change image color with saving options property.
Document doc = new Document(getMyDir() + "Images.docx");
// Create a "PdfSaveOptions" object that we can pass to the document's "Save" method
// to modify how that method converts the document to .PDF.
// Set the "ColorMode" property to "Grayscale" to render all images from the document in black and white.
// The size of the output document may be larger with this setting.
// Set the "ColorMode" property to "Normal" to render all images in color.
PdfSaveOptions pdfSaveOptions = new PdfSaveOptions();
{
pdfSaveOptions.setColorMode(colorMode);
}
doc.save(getArtifactsDir() + "PdfSaveOptions.ColorRendering.pdf", pdfSaveOptions);
value - A value determining how colors are rendered. The value must be one of ColorMode constants.public boolean getOptimizeOutput()
true. Default is false.
Examples:
Shows how to simplify a document when saving it to HTML by removing various redundant objects.
Document doc = new Document(getMyDir() + "Rendering.docx");
HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
{
saveOptions.setOptimizeOutput(optimizeOutput);
}
doc.save(getArtifactsDir() + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html", saveOptions);
// The size of the optimized version of the document is almost a third of the size of the unoptimized document.
if (optimizeOutput)
Assert.assertEquals(60385.0,
new File(getArtifactsDir() + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html").length(), 200.0);
else
Assert.assertEquals(191000.0,
new File(getArtifactsDir() + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html").length(), 200.0);
Shows how to optimize document objects while saving to xps.
Document doc = new Document(getMyDir() + "Unoptimized document.docx");
// Create an "XpsSaveOptions" object to pass to the document's "Save" method
// to modify how that method converts the document to .XPS.
XpsSaveOptions saveOptions = new XpsSaveOptions();
// Set the "OptimizeOutput" property to "true" to take measures such as removing nested or empty canvases
// and concatenating adjacent runs with identical formatting to optimize the output document's content.
// This may affect the appearance of the document.
// Set the "OptimizeOutput" property to "false" to save the document normally.
saveOptions.setOptimizeOutput(optimizeOutput);
doc.save(getArtifactsDir() + "XpsSaveOptions.OptimizeOutput.xps", saveOptions);
boolean value.public void setOptimizeOutput(boolean value)
true. Default is false.
Examples:
Shows how to simplify a document when saving it to HTML by removing various redundant objects.
Document doc = new Document(getMyDir() + "Rendering.docx");
HtmlFixedSaveOptions saveOptions = new HtmlFixedSaveOptions();
{
saveOptions.setOptimizeOutput(optimizeOutput);
}
doc.save(getArtifactsDir() + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html", saveOptions);
// The size of the optimized version of the document is almost a third of the size of the unoptimized document.
if (optimizeOutput)
Assert.assertEquals(60385.0,
new File(getArtifactsDir() + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html").length(), 200.0);
else
Assert.assertEquals(191000.0,
new File(getArtifactsDir() + "HtmlFixedSaveOptions.OptimizeGraphicsOutput.html").length(), 200.0);
Shows how to optimize document objects while saving to xps.
Document doc = new Document(getMyDir() + "Unoptimized document.docx");
// Create an "XpsSaveOptions" object to pass to the document's "Save" method
// to modify how that method converts the document to .XPS.
XpsSaveOptions saveOptions = new XpsSaveOptions();
// Set the "OptimizeOutput" property to "true" to take measures such as removing nested or empty canvases
// and concatenating adjacent runs with identical formatting to optimize the output document's content.
// This may affect the appearance of the document.
// Set the "OptimizeOutput" property to "false" to save the document normally.
saveOptions.setOptimizeOutput(optimizeOutput);
doc.save(getArtifactsDir() + "XpsSaveOptions.OptimizeOutput.xps", saveOptions);
value - The corresponding boolean value.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectprotected static void assertValidIdPrefix(java.lang.String prefix)
protected static boolean isValidIdPrefix(java.lang.String prefix)