PageSet

Inheritance: java.lang.Object

public class PageSet

Describes a random set of pages.

To learn more, visit the Programming with Documents documentation article.

Constructors

ConstructorDescription
PageSet(int page)Creates an one-page set based on exact page index.
PageSet(int[] pages)Creates a page set based on exact page indices.
PageSet(PageRange[] ranges)Creates a page set based on ranges.

Methods

MethodDescription
getAll()Gets a set with all the pages of the document in their original order.
getEven()Gets a set with all the even pages of the document in their original order.
getOdd()Gets a set with all the odd pages of the document in their original order.

PageSet(int page)

public PageSet(int page)

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

Remarks:

If a page is encountered that is not in the document, an exception will be thrown during rendering. Integer.MAX_VALUE means the last page in the document.

Parameters:

ParameterTypeDescription
pageintZero-based index of the page.

PageSet(int[] pages)

public PageSet(int[] pages)

Creates a page set based on exact page indices.

Remarks:

If a page is encountered that is not in the document, an exception will be thrown during rendering. Integer.MAX_VALUE means the last page in the document.

Examples:

Shows how to extract pages based on exact page indices.


 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);

 // Add five pages to the document.
 for (int i = 1; i < 6; i++) {
     builder.write("Page " + i);
     builder.insertBreak(BreakType.PAGE_BREAK);
 }

 // Create an "XpsSaveOptions" object, which we can pass to the document's "Save" method
 // to modify how that method converts the document to .XPS.
 XpsSaveOptions xpsOptions = new 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.
 xpsOptions.setPageSet(new PageSet(0, 1, 3));

 doc.save(getArtifactsDir() + "XpsSaveOptions.ExportExactPages.xps", xpsOptions);
 

Parameters:

ParameterTypeDescription
pagesint[]Zero-based indices of pages.

PageSet(PageRange[] ranges)

public PageSet(PageRange[] ranges)

Creates a page set based on 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 ranges.


 Document doc = new Document(getMyDir() + "Images.docx");

 ImageSaveOptions imageOptions = new ImageSaveOptions(SaveFormat.TIFF);
 PageSet pageSet = new PageSet(new PageRange(1, 1), new PageRange(2, 3), new PageRange(1, 3), new PageRange(2, 4), new PageRange(1, 1));

 imageOptions.setPageSet(pageSet);
 doc.save(getArtifactsDir() + "ImageSaveOptions.ExportVariousPageRanges.tiff", imageOptions);
 

Parameters:

ParameterTypeDescription
rangesPageRange[]Array of page ranges.

getAll()

public static PageSet getAll()

Gets a set with all the pages of the document in their original order.

Returns: PageSet - A set with all the pages of the document in their original order.

getEven()

public static PageSet getEven()

Gets a set with all the even pages of the document in their original order.

Remarks:

Even pages have odd indices since page indices are zero-based.

Returns: PageSet - A set with all the even pages of the document in their original order.

getOdd()

public static PageSet getOdd()

Gets a set with all the odd pages of the document in their original order.

Remarks:

Odd pages have even indices since page indices are zero-based.

Returns: PageSet - A set with all the odd pages of the document in their original order.