将多页文档转换为图像

Aspose.Wordsfor.NET允许用户将多页文档导出为光栅图像。 这对于生成预览、存档或文档的可视化表示以供不可编辑使用非常有用。

什么格式支持多页导出?

Aspose.Words支持将多页导出为以下栅格图像格式:

  • Jpeg格式
  • Gif
  • 巴布亚新几内亚
  • Bmp
  • 蒂夫
  • WebP

如何将多页文档导出到图像

将多页文档导出到图像的功能是使用MultiPageLayout类实现的–您可以指定保存到图像时应如何组织页面:

  • SinglePage-只保存指定的第一个页面
  • Grid-在网格中排列页面,从左到右和从上到下,同时指定列数
  • Horizontal-在单个输出中水平并排,从左到右排列页面
  • Vertical-在单个输出中,将页面垂直排列在另一个下方
  • TiffFrames-在多帧TIFF图像中将每个页面排列为单独的帧,仅适用于TIFF图像格式

下面的代码示例演示如何将多页DOCX文档保存为具有水平布局的JPEG图像:

Document doc = new Document("Rendering.docx");

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Jpeg);
// Set up Horizontal layout.
options.PageLayout = MultiPageLayout.Horizontal(10);

doc.Save("ImageSaveOptions.HorizontalLayout.jpg", options);

您还可以自定义输出文件页面外观-指定BackColorBorderColorBorderWidth

下面的代码示例演示如何使用网格布局将多页DOCX文档保存为PNG图像:

Document doc = new Document("Rendering.docx");

ImageSaveOptions options = new ImageSaveOptions(SaveFormat.Png);
// Set up a grid layout with:
// - 3 columns per row.
// - 10pts spacing between pages (horizontal and vertical).
options.PageLayout = MultiPageLayout.Grid(3, 10, 10);

// Customize the background and border.
options.PageLayout.BackColor = Color.LightGray;
options.PageLayout.BorderColor = Color.Blue;
options.PageLayout.BorderWidth = 2;

doc.Save("ImageSaveOptions.GridLayout.png", options);