PdfPageCollection Class

The pages of a document, in the order of the page tree (ISO 32000-2, 7.7.3).

public sealed class PdfPageCollection : IEnumerable<PdfPage>, IReadOnlyCollection<PdfPage>, IReadOnlyList<PdfPage>, IEnumerable

Remarks

The page tree of a file is kept: a page is added to the node of the page it is inserted before (or of the last page), and the /Count entries of the nodes above a change are updated. A node that is reached twice, or that is not a dictionary, is skipped. A page that changes of node keeps its attributes: the attributes it inherited (resources, media box, crop box, rotation, 7.7.3.4) are copied to it first.

Implements

Properties

NameDescription
CountGets the number of pages.

Gets the number of pages.

public int Count { get; }

Property value

int

Indexers

NameDescription
this[int]Gets a page.

Gets a page.

public PdfPage this[int index] { get; }

Parameters

index int
The index of the page, from 0.

Property value

PdfPage

Methods

NameDescription
Add(PdfPage)Adds a copy of a page at the end of the document. The page can be a page of another document.
Add(PdfSize)Adds a page at the end of the document.
Duplicate(int)Inserts a copy of a page of the document after it.
GetEnumerator()Returns an enumerator over the pages.
IndexOf(PdfPage)Gets the index of a page.
Insert(int, PdfPage)Inserts a copy of a page. The page can be a page of this document (a duplicate) or of another document (an import, to merge documents).
Insert(int, PdfSize)Inserts a page.
Move(int, int)Moves a page to another position. Its object does not change: the destinations, links and structure elements that refer to it stay valid.
RemoveAt(int)Removes a page from the page tree. Its objects are not written by a full save anymore: the references of the document to the page are removed too. The outline items and the links that go to the page lose their destination (the items and the links stay), the named destinations of the page and the /OpenAction that goes to it are removed, and so are its marked content and its annotations in the structure tree.
System.Collections.IEnumerable.GetEnumerator()

Add overloads

Adds a copy of a page at the end of the document. The page can be a page of another document.

public PdfPage Add(PdfPage page)
Parameters
page PdfPage
The page to copy.
Returns

PdfPage The copy.

Remarks

Adds a page at the end of the document.

public PdfPage Add(PdfSize size)
Parameters
size PdfSize
The size of the page (its media box).
Returns

PdfPage The new page.

Duplicate(int)

PdfPageCollection.cs

Inserts a copy of a page of the document after it.

public PdfPage Duplicate(int index)

Parameters

index int
The index of the page.

Returns

PdfPage The copy, at index + 1.

Remarks

GetEnumerator()

PdfPageCollection.cs

Returns an enumerator over the pages.

public IEnumerator<PdfPage> GetEnumerator()

Returns

IEnumerator<PdfPage> The enumerator.

IndexOf(PdfPage)

PdfPageCollection.cs

Gets the index of a page.

public int IndexOf(PdfPage page)

Parameters

page PdfPage
The page.

Returns

int The index, or -1 when the page is not in the document.

Insert overloads

Insert(int, PdfPage)

PdfPageCollection.cs

Inserts a copy of a page. The page can be a page of this document (a duplicate) or of another document (an import, to merge documents).

public PdfPage Insert(int index, PdfPage page)
Parameters
index int
The index of the copy, from 0 to PdfPageCollection.Count.
page PdfPage
The page to copy.
Returns

PdfPage The copy.

Remarks

The copy has the attributes of the page, the ones it inherited included, its content and its annotations, except the form fields (widgets) and the pop-up windows. It is not tagged: its /StructParents and the structure of its annotations are left out, since the structure tree belongs to the document of the page.

A page of this document shares its content streams and its resources with the copy. A page of another document is copied with the objects it uses, renumbered: the objects shared by several imported pages of a document, such as the fonts, are copied once. The document must stay open until the copy is saved. The destinations of the links go to the copies of their pages: a destination to a page that is not imported yet goes to it when it is, and has no page (null) otherwise; a named destination is replaced by the destination it names.

Insert(int, PdfSize)

PdfPageCollection.cs

Inserts a page.

public PdfPage Insert(int index, PdfSize size)
Parameters
index int
The index of the new page, from 0 to PdfPageCollection.Count.
size PdfSize
The size of the page (its media box).
Returns

PdfPage The new page. It does not inherit the rotation nor the crop box of the node of the page tree it is added to.

Move(int, int)

PdfPageCollection.cs

Moves a page to another position. Its object does not change: the destinations, links and structure elements that refer to it stay valid.

public void Move(int fromIndex, int toIndex)

Parameters

fromIndex int
The index of the page.
toIndex int
The index of the page after the move.

Removes a page from the page tree. Its objects are not written by a full save anymore: the references of the document to the page are removed too. The outline items and the links that go to the page lose their destination (the items and the links stay), the named destinations of the page and the /OpenAction that goes to it are removed, and so are its marked content and its annotations in the structure tree.

public void RemoveAt(int index)

Parameters

index int
The index of the page.

System.Collections.IEnumerable.GetEnumerator()

PdfPageCollection.cs
IEnumerator IEnumerable.GetEnumerator()

No documentation is available.