public class MetafileRenderingOptions
Example:
public void handleBinaryRasterWarnings() throws Exception {
Document doc = new Document(getMyDir() + "WMF with image.docx");
MetafileRenderingOptions metafileRenderingOptions = new MetafileRenderingOptions();
metafileRenderingOptions.setEmulateRasterOperations(false);
metafileRenderingOptions.setRenderingMode(MetafileRenderingMode.VECTOR_WITH_FALLBACK);
// If Aspose.Words cannot correctly render some of the metafile records to vector graphics then Aspose.Words renders this metafile to a bitmap
HandleDocumentWarnings callback = new HandleDocumentWarnings();
doc.setWarningCallback(callback);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setMetafileRenderingOptions(metafileRenderingOptions);
doc.save(getArtifactsDir() + "PdfSaveOptions.HandleBinaryRasterWarnings.pdf", saveOptions);
Assert.assertEquals(callback.mWarnings.getCount(), 1);
Assert.assertTrue(callback.mWarnings.get(0).getDescription().contains("R2_XORPEN"));
}
public static class HandleDocumentWarnings implements IWarningCallback {
/**
* Our callback only needs to implement the "Warning" method. This method is called whenever there is a
* potential issue during document processing. The callback can be set to listen for warnings generated during document
* load and/or document save.
*/
public void warning(final WarningInfo info) {
//For now type of warnings about unsupported metafile records changed from DataLoss/UnexpectedContent to MinorFormattingLoss
if (info.getWarningType() == WarningType.MINOR_FORMATTING_LOSS) {
System.out.println("Unsupported operation: " + info.getDescription());
this.mWarnings.warning(info);
}
}
public WarningInfoCollection mWarnings = new WarningInfoCollection();
}
Constructor Summary |
---|
Property Getters/Setters Summary | ||
---|---|---|
int | getEmfPlusDualRenderingMode() | |
void | setEmfPlusDualRenderingMode(intvalue) | |
Gets or sets a value determining how EMF+ Dual metafiles should be rendered. The value of the property is EmfPlusDualRenderingMode integer constant. | ||
boolean | getEmulateRasterOperations() | |
void | setEmulateRasterOperations(booleanvalue) | |
Gets or sets a value determining whether or not the raster operations should be emulated. | ||
int | getRenderingMode() | |
void | setRenderingMode(intvalue) | |
Gets or sets a value determining how metafile images should be rendered. The value of the property is MetafileRenderingMode integer constant. | ||
boolean | getScaleWmfFontsToMetafileSize() | |
void | setScaleWmfFontsToMetafileSize(booleanvalue) | |
Gets or sets a value determining whether or not to scale fonts in WMF metafile according to metafile size on the page. | ||
boolean | getUseEmfEmbeddedToWmf() | |
void | setUseEmfEmbeddedToWmf(booleanvalue) | |
Gets or sets a value determining how WMF metafiles with embedded EMF metafiles should be rendered. |
public int getEmfPlusDualRenderingMode() / public void setEmfPlusDualRenderingMode(int value)
EMF+ Dual metafiles contains both EMF+ and EMF parts. MS Word and GDI+ always renders EMF+ part. Aspose.Words currently doesn't fully supports all EMF+ records and in some cases rendering result of EMF part looks better then rendering result of EMF+ part.
This option is used only when metafile is rendered as vector graphics. When metafile is rendered to bitmap, EMF+ part is always used.
The default value is
Example:
Shows how to adjust EMF (Enhanced Windows Metafile) rendering options when saving to PDF.Document doc = new Document(getMyDir() + "EMF.docx"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getMetafileRenderingOptions().setEmfPlusDualRenderingMode(renderingMode); saveOptions.getMetafileRenderingOptions().setUseEmfEmbeddedToWmf(true); doc.save(getArtifactsDir() + "PdfSaveOptions.RenderMetafile.pdf", saveOptions);
public boolean getEmulateRasterOperations() / public void setEmulateRasterOperations(boolean value)
Specific raster operations could be used in metafiles. They can not be rendered directly to vector graphics. Emulating raster operations requires partial rasterization of the resulting vector graphics which may affect the metafile rendering performance.
When this value is set to true
, Aspose.Words emulates the raster operations. The resulting output maybe
partially rasterized and performance might be slower.
When this value is set to false
, Aspose.Words does not emulate the raster operations. When Aspose.Words
encounters a raster operation in a metafile it fallbacks to rendering the metafile into a bitmap by using the
operating system.
This option is used only when metafile is rendered as vector graphics.
The default value is true
.
Example:
Shows added 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(); metafileRenderingOptions.setEmulateRasterOperations(false); metafileRenderingOptions.setRenderingMode(MetafileRenderingMode.VECTOR_WITH_FALLBACK); // If Aspose.Words cannot correctly render some of the metafile records to vector graphics then Aspose.Words renders this metafile to a bitmap HandleDocumentWarnings callback = new HandleDocumentWarnings(); doc.setWarningCallback(callback); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.setMetafileRenderingOptions(metafileRenderingOptions); doc.save(getArtifactsDir() + "PdfSaveOptions.HandleBinaryRasterWarnings.pdf", saveOptions); Assert.assertEquals(callback.mWarnings.getCount(), 1); Assert.assertTrue(callback.mWarnings.get(0).getDescription().contains("R2_XORPEN")); } public static class HandleDocumentWarnings implements IWarningCallback { /** * Our callback only needs to implement the "Warning" method. This method is called whenever there is a * potential issue during document processing. The callback can be set to listen for warnings generated during document * load and/or document save. */ public void warning(final WarningInfo info) { //For now type of warnings about unsupported metafile records changed from DataLoss/UnexpectedContent to MinorFormattingLoss if (info.getWarningType() == WarningType.MINOR_FORMATTING_LOSS) { System.out.println("Unsupported operation: " + info.getDescription()); this.mWarnings.warning(info); } } public WarningInfoCollection mWarnings = new WarningInfoCollection(); }
public int getRenderingMode() / public void setRenderingMode(int value)
The default value depends on the save format. For images it is
Example:
Shows added 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(); metafileRenderingOptions.setEmulateRasterOperations(false); metafileRenderingOptions.setRenderingMode(MetafileRenderingMode.VECTOR_WITH_FALLBACK); // If Aspose.Words cannot correctly render some of the metafile records to vector graphics then Aspose.Words renders this metafile to a bitmap HandleDocumentWarnings callback = new HandleDocumentWarnings(); doc.setWarningCallback(callback); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.setMetafileRenderingOptions(metafileRenderingOptions); doc.save(getArtifactsDir() + "PdfSaveOptions.HandleBinaryRasterWarnings.pdf", saveOptions); Assert.assertEquals(callback.mWarnings.getCount(), 1); Assert.assertTrue(callback.mWarnings.get(0).getDescription().contains("R2_XORPEN")); } public static class HandleDocumentWarnings implements IWarningCallback { /** * Our callback only needs to implement the "Warning" method. This method is called whenever there is a * potential issue during document processing. The callback can be set to listen for warnings generated during document * load and/or document save. */ public void warning(final WarningInfo info) { //For now type of warnings about unsupported metafile records changed from DataLoss/UnexpectedContent to MinorFormattingLoss if (info.getWarningType() == WarningType.MINOR_FORMATTING_LOSS) { System.out.println("Unsupported operation: " + info.getDescription()); this.mWarnings.warning(info); } } public WarningInfoCollection mWarnings = new WarningInfoCollection(); }
public boolean getScaleWmfFontsToMetafileSize() / public void setScaleWmfFontsToMetafileSize(boolean value)
When WMF metafiles are displayed in MS Word, fonts may be scaled according to actual metafile size on the page.
When this value is set to true
, Aspose.Words emulates font scaling according to metafile size on the page.
When this value is set to false
, Aspose.Words displays the fonts as metafile is rendered to its default size.
This option is used only when metafile is rendered as vector graphics.
The default value is true
.
Example:
Shows how to WMF fonts scaling according to metafile size on the page.Document doc = new Document(getMyDir() + "WMF with text.docx"); // There is a several options for this: // 'True' - Aspose.Words emulates font scaling according to metafile size on the page // 'False' - Aspose.Words displays the fonts as metafile is rendered to its default size // Use 'False' option is used only when metafile is rendered as vector graphics PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getMetafileRenderingOptions().setScaleWmfFontsToMetafileSize(doScaleWmfFonts); doc.save(getArtifactsDir() + "PdfSaveOptions.FontsScaledToMetafileSize.pdf", saveOptions);
public boolean getUseEmfEmbeddedToWmf() / public void setUseEmfEmbeddedToWmf(boolean value)
WMF metafiles could contain embedded EMF data. MS Word in most cases uses embedded EMF data. GDI+ always uses WMF data.
When this value is set to true
, Aspose.Words uses embedded EMF data when rendering.
When this value is set to false
, Aspose.Words uses WMF data when rendering.
This option is used only when metafile is rendered as vector graphics. When metafile is rendered to bitmap, WMF data is always used.
The default value is true
.
Example:
Shows how to adjust EMF (Enhanced Windows Metafile) rendering options when saving to PDF.Document doc = new Document(getMyDir() + "EMF.docx"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.getMetafileRenderingOptions().setEmfPlusDualRenderingMode(renderingMode); saveOptions.getMetafileRenderingOptions().setUseEmfEmbeddedToWmf(true); doc.save(getArtifactsDir() + "PdfSaveOptions.RenderMetafile.pdf", saveOptions);