public class ImageSaveOptions extends FixedPageSaveOptions implements java.lang.Cloneable
To learn more, visit the Specify Save Options documentation article.
Examples:
Shows how to specify a resolution while rendering a document to PNG.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setName("Times New Roman");
builder.getFont().setSize(24.0);
builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
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 options = new ImageSaveOptions(SaveFormat.PNG);
// Set the "Resolution" property to "72" to render the document in 72dpi.
options.setResolution(72f);
doc.save(getArtifactsDir() + "ImageSaveOptions.Resolution.72dpi.png", options);
// Set the "Resolution" property to "300" to render the document in 300dpi.
options.setResolution(300f);
doc.save(getArtifactsDir() + "ImageSaveOptions.Resolution.300dpi.png", options);
Renders a page of a Word document into an image with transparent or colored background.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setName("Times New Roman");
builder.getFont().setSize(24.0);
builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
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 imgOptions = new ImageSaveOptions(SaveFormat.PNG);
// Set the "PaperColor" property to a transparent color to apply a transparent
// background to the document while rendering it to an image.
imgOptions.setPaperColor(new Color(1f, 0f, 0f, .5f));
doc.save(getArtifactsDir() + "ImageSaveOptions.PaperColor.Transparent.png", imgOptions);
// Set the "PaperColor" property to an opaque color to apply that color
// as the background of the document as we render it to an image.
imgOptions.setPaperColor(Color.cyan);
doc.save(getArtifactsDir() + "ImageSaveOptions.PaperColor.LightCoral.png", imgOptions);
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);
| Constructor and Description |
|---|
ImageSaveOptions(int saveFormat)
Initializes a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
ImageSaveOptions |
deepClone()
Creates a deep clone of this object.
|
GraphicsQualityOptions |
getGraphicsQualityOptions()
Allows to specify rendering mode and quality for the
Graphics2D object. |
float |
getHorizontalResolution()
Gets the horizontal resolution for the generated images, in dots per inch.
|
float |
getImageBrightness()
Gets the brightness for the generated images.
|
int |
getImageColorMode()
Gets the color mode for the generated images.
|
float |
getImageContrast()
Gets the contrast for the generated images.
|
java.awt.Dimension |
getImageSize()
Gets the size of a generated image in pixels.
|
int |
getJpegQuality()
Gets a value determining the quality of the generated JPEG images.
|
MetafileRenderingOptions |
getMetafileRenderingOptions()
Allows to specify how metafiles are treated in the rendered output.
|
MultiPageLayout |
getPageLayout()
Gets the layout used when rendering multiple pages into a single output.
|
PageSet |
getPageSet()
Gets the pages to render.
|
java.awt.Color |
getPaperColor()
Gets the background (paper) color for the generated images.
|
int |
getPixelFormat()
Gets the pixel format for the generated images.
|
int |
getSaveFormat()
Specifies the format in which the rendered document pages or shapes will be saved if this save options object is used.
|
float |
getScale()
Gets the zoom factor for the generated images.
|
byte |
getThresholdForFloydSteinbergDithering()
Gets the threshold that determines the value of the binarization error in the Floyd-Steinberg method.
|
int |
getTiffBinarizationMethod()
Gets method used while converting images to 1 bpp format when
getSaveFormat() / setSaveFormat(int) is SaveFormat.TIFF and getTiffCompression() / setTiffCompression(int) is equal to TiffCompression.CCITT_3 or TiffCompression.CCITT_4. |
int |
getTiffCompression()
Gets the type of compression to apply when saving generated images to the TIFF format.
|
boolean |
getUseGdiEmfRenderer()
Gets a value determining whether to use GDI+ or Aspose.Words metafile renderer when saving to EMF.
|
float |
getVerticalResolution()
Gets the vertical resolution for the generated images, in dots per inch.
|
protected java.lang.Object |
memberwiseClone() |
void |
setGraphicsQualityOptions(GraphicsQualityOptions value)
Allows to specify rendering mode and quality for the
Graphics2D object. |
void |
setHorizontalResolution(float value)
Sets the horizontal resolution for the generated images, in dots per inch.
|
void |
setImageBrightness(float value)
Sets the brightness for the generated images.
|
void |
setImageColorMode(int value)
Sets the color mode for the generated images.
|
void |
setImageContrast(float value)
Sets the contrast for the generated images.
|
void |
setImageSize(java.awt.Dimension value)
Sets the size of a generated image in pixels.
|
void |
setJpegQuality(int value)
Sets a value determining the quality of the generated JPEG images.
|
void |
setPageLayout(MultiPageLayout value)
Sets the layout used when rendering multiple pages into a single output.
|
void |
setPageSet(PageSet value)
Sets the pages to render.
|
void |
setPaperColor(java.awt.Color value)
Sets the background (paper) color for the generated images.
|
void |
setPixelFormat(int value)
Sets the pixel format for the generated images.
|
void |
setResolution(float value)
Sets both horizontal and vertical resolution for the generated images, in dots per inch.
|
void |
setSaveFormat(int value)
Specifies the format in which the rendered document pages or shapes will be saved if this save options object is used.
|
void |
setScale(float value)
Sets the zoom factor for the generated images.
|
void |
setThresholdForFloydSteinbergDithering(byte value)
Sets the threshold that determines the value of the binarization error in the Floyd-Steinberg method.
|
void |
setTiffBinarizationMethod(int value)
Sets method used while converting images to 1 bpp format when
getSaveFormat() / setSaveFormat(int) is SaveFormat.TIFF and getTiffCompression() / setTiffCompression(int) is equal to TiffCompression.CCITT_3 or TiffCompression.CCITT_4. |
void |
setTiffCompression(int value)
Sets the type of compression to apply when saving generated images to the TIFF format.
|
void |
setUseGdiEmfRenderer(boolean value)
Sets a value determining whether to use GDI+ or Aspose.Words metafile renderer when saving to EMF.
|
void |
setVerticalResolution(float value)
Sets the vertical resolution for the generated images, in dots per inch.
|
assertValidIdPrefix, equals, getColorMode, getNumeralFormat, getOptimizeOutput, getPageSavingCallback, isValidIdPrefix, setColorMode, setMetafileRenderingOptions, setNumeralFormat, setOptimizeOutput, setPageSavingCallbackcreateSaveOptions, createSaveOptions, getAllowEmbeddingPostScriptFonts, getCustomTimeZoneInfo, getDefaultTemplate, getDml3DEffectsRenderingMode, getDmlEffectsRenderingMode, getDmlRenderingMode, getExportGeneratorName, getImlRenderingMode, getMemoryOptimization, getPrettyFormat, getProgressCallback, getTempFolder, getUpdateAmbiguousTextFont, getUpdateCreatedTimeProperty, getUpdateFields, getUpdateLastPrintedProperty, getUpdateLastSavedTimeProperty, getUseAntiAliasing, getUseHighQualityRendering, setAllowEmbeddingPostScriptFonts, setCustomTimeZoneInfo, setDefaultTemplate, setDml3DEffectsRenderingMode, setDmlEffectsRenderingMode, setDmlRenderingMode, setExportGeneratorName, setImlRenderingMode, setMemoryOptimization, setPrettyFormat, setProgressCallback, setTempFolder, setUpdateAmbiguousTextFont, setUpdateCreatedTimeProperty, setUpdateFields, setUpdateLastPrintedProperty, setUpdateLastSavedTimeProperty, setUseAntiAliasing, setUseHighQualityRenderingpublic ImageSaveOptions(int saveFormat)
public int getSaveFormat()
SaveFormat.TIFF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.JPEG or vector SaveFormat.EMF, SaveFormat.EPS, SaveFormat.WEB_P, SaveFormat.SVG.
Remarks:
The number of other options depends on the selected format.
Also, it is possible to save to SVG both via ImageSaveOptions and via SvgSaveOptions.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
getSaveFormat in class SaveOptionsint value. The returned value is one of SaveFormat constants.public void setSaveFormat(int value)
SaveFormat.TIFF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.JPEG or vector SaveFormat.EMF, SaveFormat.EPS, SaveFormat.WEB_P, SaveFormat.SVG.
Remarks:
The number of other options depends on the selected format.
Also, it is possible to save to SVG both via ImageSaveOptions and via SvgSaveOptions.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
setSaveFormat in class SaveOptionsvalue - The corresponding int value. The value must be one of SaveFormat constants.public PageSet getPageSet()
Remarks:
This property has effect only when rendering document pages. This property is ignored when rendering shapes to images.
Examples:
Shows how to extract pages based on exact page ranges.
Document doc = new Document(getMyDir() + "Images.docx");
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.TIFF);
PageSet pageSet = new PageSet(new PageRange(1, 1), new PageRange(2, 3), new PageRange(1, 3), new PageRange(2, 4), new PageRange(1, 1));
imageOptions.setPageSet(pageSet);
doc.save(getArtifactsDir() + "ImageSaveOptions.ExportVariousPageRanges.tiff", imageOptions);
Shows how to specify which page in a document to render as an image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world! This is page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("This is page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("This is page 3.");
Assert.assertEquals(3, doc.getPageCount());
// When we save the document as an image, Aspose.Words only renders the first page by default.
// We can pass a SaveOptions object to specify a different page to render.
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.GIF);
// Render every page of the document to a separate image file.
for (int i = 1; i <= doc.getPageCount(); i++) {
saveOptions.setPageSet(new PageSet(1));
doc.save(getArtifactsDir() + MessageFormat.format("ImageSaveOptions.PageIndex.Page {0}.gif", i), saveOptions);
}
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);
}
getPageSet in class FixedPageSaveOptionspublic void setPageSet(PageSet value)
Remarks:
This property has effect only when rendering document pages. This property is ignored when rendering shapes to images.
Examples:
Shows how to extract pages based on exact page ranges.
Document doc = new Document(getMyDir() + "Images.docx");
ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.TIFF);
PageSet pageSet = new PageSet(new PageRange(1, 1), new PageRange(2, 3), new PageRange(1, 3), new PageRange(2, 4), new PageRange(1, 1));
imageOptions.setPageSet(pageSet);
doc.save(getArtifactsDir() + "ImageSaveOptions.ExportVariousPageRanges.tiff", imageOptions);
Shows how to specify which page in a document to render as an image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world! This is page 1.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("This is page 2.");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("This is page 3.");
Assert.assertEquals(3, doc.getPageCount());
// When we save the document as an image, Aspose.Words only renders the first page by default.
// We can pass a SaveOptions object to specify a different page to render.
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.GIF);
// Render every page of the document to a separate image file.
for (int i = 1; i <= doc.getPageCount(); i++) {
saveOptions.setPageSet(new PageSet(1));
doc.save(getArtifactsDir() + MessageFormat.format("ImageSaveOptions.PageIndex.Page {0}.gif", i), saveOptions);
}
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);
}
setPageSet in class FixedPageSaveOptionsvalue - The pages to render.public java.awt.Color getPaperColor()
The default value is java.awt.Color#getWhite().
Remarks:
When rendering pages of a document that specifies its own background color, then the document background color will override the color specified by this property.
Examples:
Renders a page of a Word document into an image with transparent or colored background.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setName("Times New Roman");
builder.getFont().setSize(24.0);
builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
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 imgOptions = new ImageSaveOptions(SaveFormat.PNG);
// Set the "PaperColor" property to a transparent color to apply a transparent
// background to the document while rendering it to an image.
imgOptions.setPaperColor(new Color(1f, 0f, 0f, .5f));
doc.save(getArtifactsDir() + "ImageSaveOptions.PaperColor.Transparent.png", imgOptions);
// Set the "PaperColor" property to an opaque color to apply that color
// as the background of the document as we render it to an image.
imgOptions.setPaperColor(Color.cyan);
doc.save(getArtifactsDir() + "ImageSaveOptions.PaperColor.LightCoral.png", imgOptions);
public void setPaperColor(java.awt.Color value)
The default value is java.awt.Color#getWhite().
Remarks:
When rendering pages of a document that specifies its own background color, then the document background color will override the color specified by this property.
Examples:
Renders a page of a Word document into an image with transparent or colored background.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setName("Times New Roman");
builder.getFont().setSize(24.0);
builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
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 imgOptions = new ImageSaveOptions(SaveFormat.PNG);
// Set the "PaperColor" property to a transparent color to apply a transparent
// background to the document while rendering it to an image.
imgOptions.setPaperColor(new Color(1f, 0f, 0f, .5f));
doc.save(getArtifactsDir() + "ImageSaveOptions.PaperColor.Transparent.png", imgOptions);
// Set the "PaperColor" property to an opaque color to apply that color
// as the background of the document as we render it to an image.
imgOptions.setPaperColor(Color.cyan);
doc.save(getArtifactsDir() + "ImageSaveOptions.PaperColor.LightCoral.png", imgOptions);
value - The background (paper) color for the generated images.public int getPixelFormat()
Remarks:
This property has effect only when saving to raster image formats.
The default value is ImagePixelFormat.FORMAT_32_BPP_ARGB.
Pixel format of the output image may differ from the set value because of work of GDI+.
Examples:
Shows how to select a bit-per-pixel rate with which to render a document to an image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
Assert.assertTrue(new File(getImageDir() + "Logo.jpg").length() < 21000);
// When we save the document as an image, we can pass a SaveOptions object to
// select a pixel format for the image that the saving operation will generate.
// Various bit per pixel rates will affect the quality and file size of the generated image.
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPixelFormat(imagePixelFormat);
// We can clone ImageSaveOptions instances.
Assert.assertNotEquals(imageSaveOptions, imageSaveOptions.deepClone());
doc.save(getArtifactsDir() + "ImageSaveOptions.PixelFormat.png", imageSaveOptions);
ImagePixelFormat constants.public void setPixelFormat(int value)
Remarks:
This property has effect only when saving to raster image formats.
The default value is ImagePixelFormat.FORMAT_32_BPP_ARGB.
Pixel format of the output image may differ from the set value because of work of GDI+.
Examples:
Shows how to select a bit-per-pixel rate with which to render a document to an image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
Assert.assertTrue(new File(getImageDir() + "Logo.jpg").length() < 21000);
// When we save the document as an image, we can pass a SaveOptions object to
// select a pixel format for the image that the saving operation will generate.
// Various bit per pixel rates will affect the quality and file size of the generated image.
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPixelFormat(imagePixelFormat);
// We can clone ImageSaveOptions instances.
Assert.assertNotEquals(imageSaveOptions, imageSaveOptions.deepClone());
doc.save(getArtifactsDir() + "ImageSaveOptions.PixelFormat.png", imageSaveOptions);
value - The pixel format for the generated images. The value must be one of ImagePixelFormat constants.public float getHorizontalResolution()
Remarks:
This property has effect only when saving to raster image formats and affects the output size in pixels.
The default value is 96.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
public void setHorizontalResolution(float value)
Remarks:
This property has effect only when saving to raster image formats and affects the output size in pixels.
The default value is 96.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
value - The horizontal resolution for the generated images, in dots per inch.public float getVerticalResolution()
Remarks:
This property has effect only when saving to raster image formats and affects the output size in pixels.
The default value is 96.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
public void setVerticalResolution(float value)
Remarks:
This property has effect only when saving to raster image formats and affects the output size in pixels.
The default value is 96.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
value - The vertical resolution for the generated images, in dots per inch.public void setResolution(float value)
Remarks:
This property has effect only when saving to raster image formats.
Examples:
Shows how to specify a resolution while rendering a document to PNG.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getFont().setName("Times New Roman");
builder.getFont().setSize(24.0);
builder.writeln("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
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 options = new ImageSaveOptions(SaveFormat.PNG);
// Set the "Resolution" property to "72" to render the document in 72dpi.
options.setResolution(72f);
doc.save(getArtifactsDir() + "ImageSaveOptions.Resolution.72dpi.png", options);
// Set the "Resolution" property to "300" to render the document in 300dpi.
options.setResolution(300f);
doc.save(getArtifactsDir() + "ImageSaveOptions.Resolution.300dpi.png", options);
value - Both horizontal and vertical resolution for the generated images, in dots per inch.public java.awt.Dimension getImageSize()
Remarks:
This property has effect only when saving to raster image formats.
The default value is (0 x 0), which means that the size of the generated image will be calculated according to the size of the image in points, the specified resolution and scale.
Examples:
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);
}
public void setImageSize(java.awt.Dimension value)
Remarks:
This property has effect only when saving to raster image formats.
The default value is (0 x 0), which means that the size of the generated image will be calculated according to the size of the image in points, the specified resolution and scale.
Examples:
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);
}
value - The size of a generated image in pixels.public int getJpegQuality()
Remarks:
Has effect only when saving to JPEG.
Use this property to get or set the quality of generated images when saving in JPEG 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);
getJpegQuality in class FixedPageSaveOptionspublic void setJpegQuality(int value)
Remarks:
Has effect only when saving to JPEG.
Use this property to get or set the quality of generated images when saving in JPEG 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);
setJpegQuality in class FixedPageSaveOptionsvalue - A value determining the quality of the generated JPEG images.public int getTiffCompression()
Remarks:
Has effect only when saving to TIFF.
The default value is TiffCompression.CCITT_4.
Examples:
Shows how to select the compression scheme to apply to a document that we convert into a TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(getImageDir() + "Tagged Image File Format.tiff");
// 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);
// Set the "TiffCompression" property to "TiffCompression.None" to apply no compression while saving,
// which may result in a very large output file.
// Set the "TiffCompression" property to "TiffCompression.Rle" to apply RLE compression
// Set the "TiffCompression" property to "TiffCompression.Lzw" to apply LZW compression.
// Set the "TiffCompression" property to "TiffCompression.Ccitt3" to apply CCITT3 compression.
// Set the "TiffCompression" property to "TiffCompression.Ccitt4" to apply CCITT4 compression.
options.setTiffCompression(tiffCompression);
doc.save(getArtifactsDir() + "ImageSaveOptions.TiffImageCompression.tiff", options);
TiffCompression constants.public void setTiffCompression(int value)
Remarks:
Has effect only when saving to TIFF.
The default value is TiffCompression.CCITT_4.
Examples:
Shows how to select the compression scheme to apply to a document that we convert into a TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(getImageDir() + "Tagged Image File Format.tiff");
// 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);
// Set the "TiffCompression" property to "TiffCompression.None" to apply no compression while saving,
// which may result in a very large output file.
// Set the "TiffCompression" property to "TiffCompression.Rle" to apply RLE compression
// Set the "TiffCompression" property to "TiffCompression.Lzw" to apply LZW compression.
// Set the "TiffCompression" property to "TiffCompression.Ccitt3" to apply CCITT3 compression.
// Set the "TiffCompression" property to "TiffCompression.Ccitt4" to apply CCITT4 compression.
options.setTiffCompression(tiffCompression);
doc.save(getArtifactsDir() + "ImageSaveOptions.TiffImageCompression.tiff", options);
value - The type of compression to apply when saving generated images to the TIFF format. The value must be one of TiffCompression constants.public int getImageColorMode()
Remarks:
This property has effect only when saving to raster image formats.
The default value is ImageColorMode.NONE.
Examples:
Shows how to set a color mode when rendering documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
Assert.assertTrue(new File(getImageDir() + "Logo.jpg").length() < 20200);
// When we save the document as an image, we can pass a SaveOptions object to
// select a color mode for the image that the saving operation will generate.
// If we set the "ImageColorMode" property to "ImageColorMode.BlackAndWhite",
// the saving operation will apply grayscale color reduction while rendering the document.
// If we set the "ImageColorMode" property to "ImageColorMode.Grayscale",
// the saving operation will render the document into a monochrome image.
// If we set the "ImageColorMode" property to "None", the saving operation will apply the default method
// and preserve all the document's colors in the output image.
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setImageColorMode(imageColorMode);
doc.save(getArtifactsDir() + "ImageSaveOptions.ColorMode.png", imageSaveOptions);
ImageColorMode constants.public void setImageColorMode(int value)
Remarks:
This property has effect only when saving to raster image formats.
The default value is ImageColorMode.NONE.
Examples:
Shows how to set a color mode when rendering documents.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
Assert.assertTrue(new File(getImageDir() + "Logo.jpg").length() < 20200);
// When we save the document as an image, we can pass a SaveOptions object to
// select a color mode for the image that the saving operation will generate.
// If we set the "ImageColorMode" property to "ImageColorMode.BlackAndWhite",
// the saving operation will apply grayscale color reduction while rendering the document.
// If we set the "ImageColorMode" property to "ImageColorMode.Grayscale",
// the saving operation will render the document into a monochrome image.
// If we set the "ImageColorMode" property to "None", the saving operation will apply the default method
// and preserve all the document's colors in the output image.
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setImageColorMode(imageColorMode);
doc.save(getArtifactsDir() + "ImageSaveOptions.ColorMode.png", imageSaveOptions);
value - The color mode for the generated images. The value must be one of ImageColorMode constants.public MultiPageLayout getPageLayout()
Remarks:
Use one of the factory methods of MultiPageLayout to configure this property.
For SaveFormat.TIFF the default value is MultiPageLayout.tiffFrames(). For other formats the default value is MultiPageLayout.singlePage().
This property has effect only when saving to the following formats: SaveFormat.JPEG, SaveFormat.GIF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.TIFF, SaveFormat.WEB_P
Examples:
Shows how to save the document into JPG image with multi-page layout settings.
Document doc = new Document(getMyDir() + "Rendering.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
// Set up a grid layout with:
// - 3 columns per row.
// - 10pts spacing between pages (horizontal and vertical).
options.setPageLayout(MultiPageLayout.grid(3, 10f, 10f));
// Alternative layouts:
// options.PageLayout = MultiPageLayout.Horizontal(10);
// options.PageLayout = MultiPageLayout.Vertical(10);
// Customize the background and border.
options.getPageLayout().setBackColor(Color.lightGray);
options.getPageLayout().setBorderColor(Color.BLUE);
options.getPageLayout().setBorderWidth(2f);
doc.save(getArtifactsDir() + "ImageSaveOptions.GridLayout.jpg", options);
public void setPageLayout(MultiPageLayout value)
Remarks:
Use one of the factory methods of MultiPageLayout to configure this property.
For SaveFormat.TIFF the default value is MultiPageLayout.tiffFrames(). For other formats the default value is MultiPageLayout.singlePage().
This property has effect only when saving to the following formats: SaveFormat.JPEG, SaveFormat.GIF, SaveFormat.PNG, SaveFormat.BMP, SaveFormat.TIFF, SaveFormat.WEB_P
Examples:
Shows how to save the document into JPG image with multi-page layout settings.
Document doc = new Document(getMyDir() + "Rendering.docx");
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.JPEG);
// Set up a grid layout with:
// - 3 columns per row.
// - 10pts spacing between pages (horizontal and vertical).
options.setPageLayout(MultiPageLayout.grid(3, 10f, 10f));
// Alternative layouts:
// options.PageLayout = MultiPageLayout.Horizontal(10);
// options.PageLayout = MultiPageLayout.Vertical(10);
// Customize the background and border.
options.getPageLayout().setBackColor(Color.lightGray);
options.getPageLayout().setBorderColor(Color.BLUE);
options.getPageLayout().setBorderWidth(2f);
doc.save(getArtifactsDir() + "ImageSaveOptions.GridLayout.jpg", options);
value - The layout used when rendering multiple pages into a single output.public float getImageBrightness()
Remarks:
This property has effect only when saving to raster image formats.
The default value is 0.5. The value must be in the range between 0 and 1.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
public void setImageBrightness(float value)
Remarks:
This property has effect only when saving to raster image formats.
The default value is 0.5. The value must be in the range between 0 and 1.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
value - The brightness for the generated images.public float getImageContrast()
Remarks:
This property has effect only when saving to raster image formats.
The default value is 0.5. The value must be in the range between 0 and 1.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
public void setImageContrast(float value)
Remarks:
This property has effect only when saving to raster image formats.
The default value is 0.5. The value must be in the range between 0 and 1.
Examples:
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
value - The contrast for the generated images.public float getScale()
Remarks:
The default value is 1.0. The value must be greater than 0.
Examples:
Shows how to render an Office Math object into an image file in the local file system.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath math = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// Create an "ImageSaveOptions" object to pass to the node renderer's "Save" method to modify
// how it renders the OfficeMath node into an image.
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
// Set the "Scale" property to 5 to render the object to five times its original size.
saveOptions.setScale(5f);
math.getMathRenderer().save(getArtifactsDir() + "Shape.RenderOfficeMath.png", saveOptions);
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
public void setScale(float value)
Remarks:
The default value is 1.0. The value must be greater than 0.
Examples:
Shows how to render an Office Math object into an image file in the local file system.
Document doc = new Document(getMyDir() + "Office math.docx");
OfficeMath math = (OfficeMath) doc.getChild(NodeType.OFFICE_MATH, 0, true);
// Create an "ImageSaveOptions" object to pass to the node renderer's "Save" method to modify
// how it renders the OfficeMath node into an image.
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.PNG);
// Set the "Scale" property to 5 to render the object to five times its original size.
saveOptions.setScale(5f);
math.getMathRenderer().save(getArtifactsDir() + "Shape.RenderOfficeMath.png", saveOptions);
Shows how to edit the image while Aspose.Words converts a document to one.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an image, we can pass a SaveOptions object to
// edit the image while the saving operation renders it.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
{
// We can adjust these properties to change the image's brightness and contrast.
// Both are on a 0-1 scale and are at 0.5 by default.
options.setImageBrightness(0.3f);
options.setImageContrast(0.7f);
// We can adjust horizontal and vertical resolution with these properties.
// This will affect the dimensions of the image.
// The default value for these properties is 96.0, for a resolution of 96dpi.
options.setHorizontalResolution(72f);
options.setVerticalResolution(72f);
// We can scale the image using this property. The default value is 1.0, for scaling of 100%.
// We can use this property to negate any changes in image dimensions that changing the resolution would cause.
options.setScale(96f / 72f);
}
doc.save(getArtifactsDir() + "ImageSaveOptions.EditImage.png", options);
value - The zoom factor for the generated images.public MetafileRenderingOptions getMetafileRenderingOptions()
Remarks:
When MetafileRenderingMode.VECTOR is specified, Aspose.Words renders metafile to vector graphics using its own metafile rendering engine first and then renders vector graphics to the image.
When MetafileRenderingMode.BITMAP is specified, Aspose.Words renders metafile directly to the image using the GDI+ metafile rendering engine.
GDI+ metafile rendering engine works faster, supports almost all metafile features but on low resolutions may produce inconsistent result when compared to the rest of vector graphics (especially for text) on the page. Aspose.Words metafile rendering engine will produce more consistent result even on low resolutions but works slower and may inaccurately render complex metafiles.
The default value for MetafileRenderingMode is MetafileRenderingMode.BITMAP.
Examples:
Shows how to set the rendering mode when saving documents with Windows Metafile images to other image formats.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertImage(getImageDir() + "Windows MetaFile.wmf");
// When we save the document as an image, we can pass a SaveOptions object to
// determine how the saving operation will process Windows Metafiles in the document.
// If we set the "RenderingMode" property to "MetafileRenderingMode.Vector",
// or "MetafileRenderingMode.VectorWithFallback", we will render all metafiles as vector graphics.
// If we set the "RenderingMode" property to "MetafileRenderingMode.Bitmap", we will render all metafiles as bitmaps.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.PNG);
options.getMetafileRenderingOptions().setRenderingMode(metafileRenderingMode);
// Aspose.Words uses GDI+ for raster operations emulation, when value is set to true.
options.getMetafileRenderingOptions().setUseGdiRasterOperationsEmulation(true);
doc.save(getArtifactsDir() + "ImageSaveOptions.WindowsMetaFile.png", options);
getMetafileRenderingOptions in class FixedPageSaveOptionsMetafileRenderingOptions value.public int getTiffBinarizationMethod()
getSaveFormat() / setSaveFormat(int) is SaveFormat.TIFF and getTiffCompression() / setTiffCompression(int) is equal to TiffCompression.CCITT_3 or TiffCompression.CCITT_4.
Remarks:
The default value is ImageBinarizationMethod.THRESHOLD.
Examples:
Shows how to set the TIFF binarization error threshold when using the Floyd-Steinberg method to render a TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as a TIFF, we can pass a SaveOptions object to
// adjust the dithering that Aspose.Words will apply when rendering this image.
// The default value of the "ThresholdForFloydSteinbergDithering" property is 128.
// Higher values tend to produce darker images.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.TIFF);
options.setTiffCompression(TiffCompression.CCITT_3);
options.setTiffBinarizationMethod(ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING);
options.setThresholdForFloydSteinbergDithering((byte) 240);
doc.save(getArtifactsDir() + "ImageSaveOptions.FloydSteinbergDithering.tiff", options);
getSaveFormat() / setSaveFormat(int) is SaveFormat.TIFF and getTiffCompression() / setTiffCompression(int) is equal to TiffCompression.CCITT_3 or TiffCompression.CCITT_4. The returned value is one of ImageBinarizationMethod constants.public void setTiffBinarizationMethod(int value)
getSaveFormat() / setSaveFormat(int) is SaveFormat.TIFF and getTiffCompression() / setTiffCompression(int) is equal to TiffCompression.CCITT_3 or TiffCompression.CCITT_4.
Remarks:
The default value is ImageBinarizationMethod.THRESHOLD.
Examples:
Shows how to set the TIFF binarization error threshold when using the Floyd-Steinberg method to render a TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as a TIFF, we can pass a SaveOptions object to
// adjust the dithering that Aspose.Words will apply when rendering this image.
// The default value of the "ThresholdForFloydSteinbergDithering" property is 128.
// Higher values tend to produce darker images.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.TIFF);
options.setTiffCompression(TiffCompression.CCITT_3);
options.setTiffBinarizationMethod(ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING);
options.setThresholdForFloydSteinbergDithering((byte) 240);
doc.save(getArtifactsDir() + "ImageSaveOptions.FloydSteinbergDithering.tiff", options);
value - Method used while converting images to 1 bpp format when getSaveFormat() / setSaveFormat(int) is SaveFormat.TIFF and getTiffCompression() / setTiffCompression(int) is equal to TiffCompression.CCITT_3 or TiffCompression.CCITT_4. The value must be one of ImageBinarizationMethod constants.public byte getThresholdForFloydSteinbergDithering()
ImageBinarizationMethod is ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING.
Remarks:
The default value is 128.
Examples:
Shows how to set the TIFF binarization error threshold when using the Floyd-Steinberg method to render a TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as a TIFF, we can pass a SaveOptions object to
// adjust the dithering that Aspose.Words will apply when rendering this image.
// The default value of the "ThresholdForFloydSteinbergDithering" property is 128.
// Higher values tend to produce darker images.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.TIFF);
options.setTiffCompression(TiffCompression.CCITT_3);
options.setTiffBinarizationMethod(ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING);
options.setThresholdForFloydSteinbergDithering((byte) 240);
doc.save(getArtifactsDir() + "ImageSaveOptions.FloydSteinbergDithering.tiff", options);
public void setThresholdForFloydSteinbergDithering(byte value)
ImageBinarizationMethod is ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING.
Remarks:
The default value is 128.
Examples:
Shows how to set the TIFF binarization error threshold when using the Floyd-Steinberg method to render a TIFF image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as a TIFF, we can pass a SaveOptions object to
// adjust the dithering that Aspose.Words will apply when rendering this image.
// The default value of the "ThresholdForFloydSteinbergDithering" property is 128.
// Higher values tend to produce darker images.
ImageSaveOptions options = new ImageSaveOptions(SaveFormat.TIFF);
options.setTiffCompression(TiffCompression.CCITT_3);
options.setTiffBinarizationMethod(ImageBinarizationMethod.FLOYD_STEINBERG_DITHERING);
options.setThresholdForFloydSteinbergDithering((byte) 240);
doc.save(getArtifactsDir() + "ImageSaveOptions.FloydSteinbergDithering.tiff", options);
value - The threshold that determines the value of the binarization error in the Floyd-Steinberg method.public GraphicsQualityOptions getGraphicsQualityOptions()
Graphics2D object.
Remarks:
Use this property to override the Graphics settings provided by Aspose.Words engine by default.
It will take effect only when a document is being saved to an image-like format.
Examples:
Shows how to set render quality options while converting documents to image formats.
Document doc = new Document(getMyDir() + "Rendering.docx");
GraphicsQualityOptions qualityOptions = new GraphicsQualityOptions();
qualityOptions.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // SmoothingMode
qualityOptions.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // TextRenderingHint
qualityOptions.getRenderingHints().put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); // CompositingMode
qualityOptions.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // CompositingQuality
qualityOptions.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // InterpolationMode
qualityOptions.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); // StringFormat
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.JPEG);
saveOptions.setGraphicsQualityOptions(qualityOptions);
doc.save(getArtifactsDir() + "ImageSaveOptions.GraphicsQuality.jpg", saveOptions);
GraphicsQualityOptions value.public void setGraphicsQualityOptions(GraphicsQualityOptions value)
Graphics2D object.
Remarks:
Use this property to override the Graphics settings provided by Aspose.Words engine by default.
It will take effect only when a document is being saved to an image-like format.
Examples:
Shows how to set render quality options while converting documents to image formats.
Document doc = new Document(getMyDir() + "Rendering.docx");
GraphicsQualityOptions qualityOptions = new GraphicsQualityOptions();
qualityOptions.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // SmoothingMode
qualityOptions.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); // TextRenderingHint
qualityOptions.getRenderingHints().put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); // CompositingMode
qualityOptions.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); // CompositingQuality
qualityOptions.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); // InterpolationMode
qualityOptions.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); // StringFormat
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.JPEG);
saveOptions.setGraphicsQualityOptions(qualityOptions);
doc.save(getArtifactsDir() + "ImageSaveOptions.GraphicsQuality.jpg", saveOptions);
value - The corresponding GraphicsQualityOptions value.public boolean getUseGdiEmfRenderer()
Remarks:
If set to true GDI+ metafile renderer is used. I.e. content is written to GDI+ graphics object and saved to metafile.
If set to false Aspose.Words metafile renderer is used. I.e. content is written directly to the metafile format with Aspose.Words.
Has effect only when saving to EMF.
GDI+ saving works only on .NET.
The default value is true.
Examples:
Shows how to choose a renderer when converting a document to .emf.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an EMF image, we can pass a SaveOptions object to select a renderer for the image.
// If we set the "UseGdiEmfRenderer" flag to "true", Aspose.Words will use the GDI+ renderer.
// If we set the "UseGdiEmfRenderer" flag to "false", Aspose.Words will use its own metafile renderer.
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.EMF);
saveOptions.setUseGdiEmfRenderer(useGdiEmfRenderer);
doc.save(getArtifactsDir() + "ImageSaveOptions.Renderer.emf", saveOptions);
// The GDI+ renderer usually creates larger files.
if (useGdiEmfRenderer)
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.Renderer.emf").length() < 300000);
else
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.Renderer.emf").length() <= 30000);
public void setUseGdiEmfRenderer(boolean value)
Remarks:
If set to true GDI+ metafile renderer is used. I.e. content is written to GDI+ graphics object and saved to metafile.
If set to false Aspose.Words metafile renderer is used. I.e. content is written directly to the metafile format with Aspose.Words.
Has effect only when saving to EMF.
GDI+ saving works only on .NET.
The default value is true.
Examples:
Shows how to choose a renderer when converting a document to .emf.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
// When we save the document as an EMF image, we can pass a SaveOptions object to select a renderer for the image.
// If we set the "UseGdiEmfRenderer" flag to "true", Aspose.Words will use the GDI+ renderer.
// If we set the "UseGdiEmfRenderer" flag to "false", Aspose.Words will use its own metafile renderer.
ImageSaveOptions saveOptions = new ImageSaveOptions(SaveFormat.EMF);
saveOptions.setUseGdiEmfRenderer(useGdiEmfRenderer);
doc.save(getArtifactsDir() + "ImageSaveOptions.Renderer.emf", saveOptions);
// The GDI+ renderer usually creates larger files.
if (useGdiEmfRenderer)
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.Renderer.emf").length() < 300000);
else
Assert.assertTrue(new File(getArtifactsDir() + "ImageSaveOptions.Renderer.emf").length() <= 30000);
value - A value determining whether to use GDI+ or Aspose.Words metafile renderer when saving to EMF.public ImageSaveOptions deepClone()
Examples:
Shows how to select a bit-per-pixel rate with which to render a document to an image.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().setStyle(doc.getStyles().get("Heading 1"));
builder.writeln("Hello world!");
builder.insertImage(getImageDir() + "Logo.jpg");
Assert.assertTrue(new File(getImageDir() + "Logo.jpg").length() < 21000);
// When we save the document as an image, we can pass a SaveOptions object to
// select a pixel format for the image that the saving operation will generate.
// Various bit per pixel rates will affect the quality and file size of the generated image.
ImageSaveOptions imageSaveOptions = new ImageSaveOptions(SaveFormat.PNG);
imageSaveOptions.setPixelFormat(imagePixelFormat);
// We can clone ImageSaveOptions instances.
Assert.assertNotEquals(imageSaveOptions, imageSaveOptions.deepClone());
doc.save(getArtifactsDir() + "ImageSaveOptions.PixelFormat.png", imageSaveOptions);
protected java.lang.Object memberwiseClone()