PageSet constructor

PageSet(page)

Creates an one-page set based on exact page index.

def __init__(self, page: int):
    ...
ParameterTypeDescription
pageintZero-based index of the page.

Remarks

If a page is encountered that is not in the document, an exception will be thrown during rendering. int.MaxValue C# constant means the last page in the document.

PageSet(pages)

Creates a page set based on exact page indices.

def __init__(self, pages: List[int]):
    ...
ParameterTypeDescription
pagesList[int]Zero-based indices of pages.

Remarks

If a page is encountered that is not in the document, an exception will be thrown during rendering. int.MaxValue C# constant means the last page in the document.

PageSet(ranges)

Creates a page set based on ranges.

def __init__(self, ranges: List[aspose.words.saving.PageRange]):
    ...
ParameterTypeDescription
rangesList[PageRange]Array of page ranges.

Remarks

If a range is encountered that starts after the last page in the document, an exception will be thrown during rendering. All ranges that end after the last page are truncated to fit in the document.

Examples

Shows how to render one page from a document to a JPEG image.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.writeln('Page 1.')
builder.insert_break(aw.BreakType.PAGE_BREAK)
builder.writeln('Page 2.')
builder.insert_image(file_name=IMAGE_DIR + 'Logo.jpg')
builder.insert_break(aw.BreakType.PAGE_BREAK)
builder.writeln('Page 3.')
# Create an "ImageSaveOptions" object which we can pass to the document's "Save" method
# to modify the way in which that method renders the document into an image.
options = aw.saving.ImageSaveOptions(aw.SaveFormat.JPEG)
# Set the "PageSet" to "1" to select the second page via
# the zero-based index to start rendering the document from.
options.page_set = aw.saving.PageSet(page=1)
# When we save the document to the JPEG format, Aspose.Words only renders one page.
# This image will contain one page starting from page two,
# which will just be the second page of the original document.
doc.save(file_name=ARTIFACTS_DIR + 'ImageSaveOptions.OnePage.jpg', save_options=options)

Shows how to extract pages based on exact page indices.

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
# Add five pages to the document.
i = 1
while i < 6:
    builder.write('Page ' + str(i))
    builder.insert_break(aw.BreakType.PAGE_BREAK)
    i += 1
# Create an "XpsSaveOptions" object, which we can pass to the document's "Save" method
# to modify how that method converts the document to .XPS.
xps_options = aw.saving.XpsSaveOptions()
# Use the "PageSet" property to select a set of the document's pages to save to output XPS.
# In this case, we will choose, via a zero-based index, only three pages: page 1, page 2, and page 4.
xps_options.page_set = aw.saving.PageSet(pages=[0, 1, 3])
doc.save(file_name=ARTIFACTS_DIR + 'XpsSaveOptions.ExportExactPages.xps', save_options=xps_options)

Shows how to extract pages based on exact page ranges.

doc = aw.Document(file_name=MY_DIR + 'Images.docx')
image_options = aw.saving.ImageSaveOptions(aw.SaveFormat.TIFF)
page_set = aw.saving.PageSet(ranges=[aw.saving.PageRange(1, 1), aw.saving.PageRange(2, 3), aw.saving.PageRange(1, 3), aw.saving.PageRange(2, 4), aw.saving.PageRange(1, 1)])
image_options.page_set = page_set
doc.save(file_name=ARTIFACTS_DIR + 'ImageSaveOptions.ExportVariousPageRanges.tiff', save_options=image_options)

See Also