Saving a Document to Fixed-page Format
Contents
[
Hide
]
After the page layout is built and the geometry of objects and their position on the page are calculated, the document can be saved in a fixed-page format supported by Aspose.Words.
When saving documents to fixed-page formats, the rendering options common to all of these formats can be used. They allow to control:
- The number and range of pages contained in the output document (PageIndex, PageCount).
- Progress of page-by-page document saving (PageSavingCallback).
- A set of characters that are used to numbers rendering (NumeralFormat).
- A metafile player (MetafileRenderingOptions). For more details, see the Handling Windows Metafiles article.
- A quality rate for recompressing JPEG images, the value of which may differ slightly, depending on the selected save format (JpegQuality).
- Optimization of vector graphics in Aspose.Words output (OptimizeOutput).
- Graphics options when saving to Tiff, Png, Bmp, Jpeg, Emf formats (UseAntiAliasing, UseHighQualityRendering).
- Saving the document in grayscale (ColorMode).
- Switching between the rendering of DrawingML shapes and fallback shapes (DmlRenderingMode).
- Switching between DML effects rendering modes (DmlEffectsRenderingMode).
The example below demonstrates how to save a document to JPEG format using the Save
method and rendering options:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
// Open the document. | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Rendering.doc"); | |
// Save as a JPEG image file with default options | |
System::String outputPathDefault = outputDataDir + u"Rendering.JpegDefaultOptions.jpg"; | |
doc->Save(outputPathDefault); | |
// Save document to stream as a JPEG with default options | |
System::SharedPtr<MemoryStream> docStream = new MemoryStream(); | |
doc->Save(docStream, SaveFormat::Jpeg); | |
// Rewind the stream position back to the beginning, ready for use | |
docStream->Seek(0, SeekOrigin::Begin); | |
// Save document to a JPEG image with specified options. | |
// Render the third page only and set the JPEG quality to 80% | |
// In this case we need to pass the desired SaveFormat to the ImageSaveOptions constructor | |
// to signal what type of image to save as. | |
System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>(SaveFormat::Tiff); | |
auto pageRange = System::MakeObject<PageRange>(0, 1); | |
options->set_PageSet(System::MakeObject<PageSet>(System::MakeArray<System::SharedPtr<PageRange>>({ pageRange }))); | |
options->set_JpegQuality(80); | |
System::String outputPath = outputDataDir + u"Rendering.JpegCustomOptions.jpg"; | |
doc->Save(outputPath, options); |