PdfPageCollectionEditor class
Page collection with reference repair.
It is the single owner of the page tree mutation: insert, remove, removeRange, move, reorder and duplicate go through the same index and owner validation and, after each mutation, through the same repair of the structures that point to pages.
final editor = PdfPageCollectionEditor(document);
editor.remove(3);
editor.move(0, 2);
final bytes = await document.save();
What the repair covers
- explicit destinations
[pageRef /XYZ …], direct or in an indirect object; - named destinations in
/Names /Dests(name tree,/Kidsincluded) and in the old catalog/Dests; /Outlines: the destination of each item and, when the page goes away, the item itself — its children move up to the place it held, and/First,/Last,/Prev,/Next,/Parentand/Countare rewritten;- internal links of the pages that stayed:
/Destand/Awith/S /GoTo; /PageLabels: the ranges are recomputed for the new order, with a shifted/St;- the
/Pof the annotations and the/AcroForm /Fieldswidgets that lived on the removed pages; - the catalog
/OpenAction.
Destinations expressed by page number ([3 /Fit]) are renumbered too.
/GoToR and /Launch are not touched: their page number refers to the
remote file.
What the repair does not cover
/StructTreeRoot,/ParentTreeand/StructParents: the logical structure tree keeps describing the content that left;/Threads(articles), an orphan/Popupand actions chained by/Next;- document JavaScript that navigates by page number;
- encrypted documents, which the library does not read yet.
Document loaded from a file
In a loaded document almost the whole graph stays in the original bytes and
is resolved by the parser, not by document.objects. The editor reads
through the PdfObjectStore and, when it needs to change something,
registers the object it read in the document so that it enters the
incremental update. Objects with a stream are not rewritten through that
path — from the read view of the store only the dictionary comes — and that
is reported in warnings.
Constructors
- PdfPageCollectionEditor(PdfDocument document, {PdfBrokenReferencePolicy brokenReferencePolicy = PdfBrokenReferencePolicy.remove})
-
Creates the editor of the page collection of
document.
Properties
- brokenReferencePolicy → PdfBrokenReferencePolicy
-
What to do with a reference to a removed page.
final
- document → PdfDocument
-
Document whose pages are edited.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- length → int
-
Number of pages.
no setter
-
pages
→ List<
PdfPage> -
Pages in document order.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
warnings
→ List<
String> -
Non-fatal warnings collected: deleted destinations, removed bookmarks,
retargeted links, objects that could not be rewritten.
no setter
Methods
-
clearWarnings(
) → void - Forgets the collected warnings.
-
duplicate(
int index, {int? at}) → PdfPage -
Duplicates the page at
index, inserting the copy atat— by default right after the original. -
indexOf(
PdfPage page) → int -
Position of
page, or-1if it does not belong to the collection. -
insert(
int index, PdfPage page) → void -
Inserts
pageat positionindex. -
insertImported(
int index, PdfDocumentParser source, int sourcePageIndex, {PdfMergeOptions? options}) → PdfPage -
Imports page
sourcePageIndexofsourceand inserts it atindex. -
move(
int from, int to) → void -
Moves the page at
fromto positiontoin the final list. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
int index) → PdfPage -
Removes the page at index
indexand returns the removed object. -
removeRange(
int start, int end) → List< PdfPage> -
Removes the pages in
[start, end)—endexclusive, as inList. -
reorder(
List< int> order) → void -
Reorders the collection according to
order, which has to be a complete permutation of the current indices. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
-
operator [](
int index) → PdfPage -
Page at position
index.