将文档保存为固定页面格式
Contents
[
Hide
]
在构建页面布局并计算对象的几何形状及其在页面上的位置后,文档可以以Aspose.Words支持的固定页面格式保存。
将文档保存为固定页面格式时,可以使用所有这些格式通用的呈现选项。 他们允许控制:
- 输出文档中包含的页数和范围(PageIndex, PageCount).
- 逐页文档保存的进度(PageSavingCallback)。
- 用于数字渲染(NumeralFormat)的一组字符。
- 元文件播放器(MetafileRenderingOptions)。 有关详细信息,请参阅 处理Windows元文件 文章。
- 用于重新压缩JPEG图像的质量速率,其值可能略有不同,具体取决于所选的保存格式(JpegQuality)。
- 优化Aspose.Words输出(OptimizeOutput)中的矢量图形。
- 保存为Tiff,Png,Bmp,Jpeg,Emf格式时的图形选项(UseAntiAliasing, UseHighQualityRendering).
- 以灰度(ColorMode)保存文档。
- 在DrawingML形状和回退形状(DmlRenderingMode)的呈现之间切换。
- 在DML效果渲染模式(DmlEffectsRenderingMode)之间切换。
下面的示例演示如何使用Save
方法和呈现选项将文档保存为JPEG格式:
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); |