PdfEx.Editor (pdf_ex v0.1.0)

Copy Markdown View Source

Structural page operations: delete, insert, reorder.

Pure functions: each operation returns a new %Document{} whose dirty_objects carries only page-tree deltas; export is PdfEx.Serializer.serialize/2.

Reads overlay dirty_objects (pending edits win), so operations compose: edit, then edit the edited document again. Ancestor /Count is maintained on every operation.

Summary

Functions

Deletes the 1-based index-th page, freeing its object losslessly (:free) and decrementing ancestor /Count.

Inserts the existing page object page_ref before 1-based position at, wiring /Parent and incrementing ancestor /Count.

Reorders pages by a permutation of 1..page_count.

Functions

delete_page(doc, index)

@spec delete_page(PdfEx.Document.t(), pos_integer()) ::
  {:ok, PdfEx.Document.t()} | {:error, PdfEx.Error.t()}

Deletes the 1-based index-th page, freeing its object losslessly (:free) and decrementing ancestor /Count.

insert_page(doc, at, page_ref)

@spec insert_page(PdfEx.Document.t(), pos_integer(), PdfEx.Document.ref_key()) ::
  {:ok, PdfEx.Document.t()} | {:error, PdfEx.Error.t()}

Inserts the existing page object page_ref before 1-based position at, wiring /Parent and incrementing ancestor /Count.

reorder_pages(doc, permutation)

@spec reorder_pages(PdfEx.Document.t(), [pos_integer()]) ::
  {:ok, PdfEx.Document.t()} | {:error, PdfEx.Error.t()}

Reorders pages by a permutation of 1..page_count.

Flat trees (all pages direct kids of the root /Pages node) get a minimal rewrite of the root /Kids only. Nested trees are flattened under the root: intermediate /Pages nodes are freed and every page's /Parent is rewired. Attributes a page inherited from a freed intermediate node are materialized onto the page so nothing is lost.