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 extract pages based on exact page indices.

doc = aw.Document()
builder = aw.DocumentBuilder(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