Skip to content

Improve PdfDocumentBuilder to organize pages in existing PDF #1233

@manfromarce

Description

@manfromarce

PdfDocumentBuilder can already be used to organize pages in an existing PDF but it mostly requires using the AddPage(PdfDocument document, int pageNumber) function and can be complicated depending on the operation:

  • you need to "pre calculate" the changes because it's not possible to edit the page collection afterwards. For example, to move page 3 after page 4 you have to: add pages 1-2, add page 4, add page 3, add all other pages
  • you need to add all pages one by one for minor modifications
  • to extract a page you need to create a new PdfDocumentBuilder and add that page from the original source, it cannot be extracted from a PdfDocumentBuilder that is not saved yet
  • it's not clear if adding a page twice (to duplicate it) produces a valid document
  • it's not clear if the document can be saved in the same location, replacing the original PDF

I would suggest to:

  • document these capabilities in the Wiki
  • allow initializing PdfDocumentBuilder from an existing file/stream or adding an array of pages in one step
  • provide new InsertPage methods to add a blank or existing page at a specific index rather than always at the end
  • provide methods to remove, rearrange and duplicate the set of pages after they are added to the PdfDocumentBuilder, or alternatively make the Pages collection not read-only
  • allow to extract a specific set of pages to another Stream/PdfDocument easily, as it does not involve editing the current document
  • allow to clear the list of pages without creating a new PdfDocumentBuilder

Of course these are just suggestions, there could be other/better ways to implement these features.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions