Convert a Document to Multiple Page Files
Leave feedback
On this page
This documentation topic covers the conversion of a single multi-page document into individual page files. The following diagram illustrates the process of converting a multi-page file into separate pages:
flowchart LR
%% Nodes
A["Input Document"]
B["Conversion"]
C["Converted Page 1"]
D["Converted Page 2"]
E["Converted Page N"]
%% Edge connections between nodes
A --> B --> C
B --> D
B --> E
To convert and save a document by page, use the following methods of the Converter class:
convert_by_page(output_path, convert_options): Converts each page of a document to the specified output format and saves them individually to disk.
convert_by_page(file_path, page_number, convert_options): Converts a specific page of a document and saves it to the specified output file path.
convert_by_page(stream, page_number, convert_options): Converts a specific page of a document and saves it to a provided stream.
Supported ConvertOptions Classes
The following ConvertOptions classes can be used with the convert_by_page method:
PdfConvertOptions – Options for converting to PDF format.
ImageConvertOptions – Options for converting to Image formats (e.g., PNG, JPEG).
WordProcessingConvertOptions – Options for converting to Word Processing formats.
SpreadsheetConvertOptions – Options for converting to Spreadsheet formats.
PresentationConvertOptions – Options for converting to Presentation formats.
WebConvertOptions – Options for converting to Web formats (e.g., HTML).
EBookConvertOptions – Options for converting to EBook formats (e.g., EPUB, MOBI).
DiagramConvertOptions – Options for converting to Diagram formats (e.g., VSDX).
PageDescriptionLanguageConvertOptions – Options for converting to Page Description Language formats (e.g., PostScript).
CadConvertOptions – Options for converting to CAD formats (e.g., DWG).
ThreeDConvertOptions – Options for converting to 3D formats.
FinanceConvertOptions – Options for converting to Finance formats (e.g., XBRL).
Example 1: Convert All Pages of a Document and Save Output to a Folder
The following example demonstrates how to convert each slide in a PPTX presentation to a PNG image and save the output images to a specified folder.
The file name template for the output files is converted-page-{page number}.{output file extension}. In this example, the first slide will be saved as converted-page-1.png.
fromgroupdocs.conversionimportConverterfromgroupdocs.conversion.filetypesimportImageFileTypefromgroupdocs.conversion.options.convertimportImageConvertOptionsdefconvert_all_document_pages():# Instantiate Converter with the input document withConverter("./basic-presentation.pptx")asconverter:# Instantiate convert options png_convert_options=ImageConvertOptions()# Define the output format as PNGpng_convert_options.format=ImageFileType.PNG# Convert all pages and save to the output folderconverter.convert_by_page("./converted-pages",png_convert_options)if__name__=="__main__":convert_all_document_pages()
basic-presentation.pptx is the sample file used in this example. Click here to download it.
converted-pages is the output folder path for the converted pages. Click here to download it.
Example 2: Convert a Specific Page and Save Output to a File
The following example shows how to convert a specific slide in a PPTX presentation and save it as a separate file.
fromgroupdocs.conversionimportConverterfromgroupdocs.conversion.filetypesimportImageFileTypefromgroupdocs.conversion.options.convertimportImageConvertOptionsdefconvert_specific_document_page_to_file():# Instantiate Converter with the input document withConverter("./basic-presentation.pptx")asconverter:# Instantiate convert options png_convert_options=ImageConvertOptions()# Define the output format as PNGpng_convert_options.format=ImageFileType.PNG# Set the page number to convert and save it to a filepage_number_to_convert=3converter.convert_by_page("./slide-3.png",page_number_to_convert,png_convert_options)if__name__=="__main__":convert_specific_document_page_to_file()
basic-presentation.pptx is the sample file used in this example. Click here to download it.
slide-3.png is the expected output PNG image. Click here to download it.
Example 3: Convert a Specific Page and Save Output to a Stream
As an alternative, you can specify the stream to save the converted PNG image:
fromgroupdocs.conversionimportConverterfromgroupdocs.conversion.filetypesimportImageFileTypefromgroupdocs.conversion.options.convertimportImageConvertOptionsdefconvert_specific_document_page_to_file():# Instantiate Converter with the input document withConverter("./basic-presentation.pptx")asconverter:# Instantiate convert options png_convert_options=ImageConvertOptions()# Define the output format as PNGpng_convert_options.format=ImageFileType.PNG# Set the page number to convert and save it to a filepage_number_to_convert=5withopen(f"./slide-{page_number_to_convert}.png","w+b")aspage_stream:converter.convert_by_page(page_stream,page_number_to_convert,png_convert_options)if__name__=="__main__":convert_specific_document_page_to_file()
basic-presentation.pptx is the sample file used in this example. Click here to download it.
slide-5.png is the expected output PNG image. Click here to download it.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.