Convert a Multi-page Document to an Image

Aspose.Words for Python via .NET allows users to export multi-page documents to raster images. This can be useful for generating previews, archives, or visual representations of documents for non-editable use.

What Formats Support Multi-page Export?

Aspose.Words supports multi-page export to the following raster image formats:

  • Jpeg
  • Gif
  • Png
  • Bmp
  • Tiff
  • WebP

How to Export a Multi-page Document to an Image

The feature of exporting a multi-page document to an image is implemented using the MultiPageLayout class – you can specify how the pages should be organized when saving to an image:

  • single_page – save only the first of the specified pages
  • grid – arrange the pages in a grid, left-to-right and top-to-bottom, while specifying the number of columns
  • horizontal – arrange the pages horizontally side-by-side, left-to-right, in a single output
  • vertical – arrange the pages vertically one below the other in a single output
  • tiff_frames – arrange each page as a separate frame in a multi-frame TIFF image, applies only to TIFF image formats

The following code example shows how to save a multi-page DOCX document as JPEG image with Horizontal layout:

doc = aw.Document(file_name='Rendering.docx')

options = aw.saving.ImageSaveOptions(aw.SaveFormat.JPEG)
# Set up Horizontal layout.
options.page_layout = MultiPageLayout.Horizontal(10);

doc.save(file_name='ImageSaveOptions.GridLayout.jpg', save_options=options)

You can also customize the output file page appearance – specify back_color, border_color, and border_width.

The following code example shows how to save a multi-page DOCX document as PNG image with Grid layout:

doc = aw.Document(file_name='Rendering.docx')

options = aw.saving.ImageSaveOptions(aw.SaveFormat.PNG)
# Set up a grid layout with:
# - 3 columns per row.
# - 10pts spacing between pages (horizontal and vertical).
options.page_layout = aw.saving.MultiPageLayout.grid(3, 10, 10)

# Customize the background and border.
options.page_layout.back_color = aspose.pydrawing.Color.light_gray
options.page_layout.border_color = aspose.pydrawing.Color.blue
options.page_layout.border_width = 2

doc.save(file_name='ImageSaveOptions.GridLayout.jpg', save_options=options)