pypdf icon indicating copy to clipboard operation
pypdf copied to clipboard

Clone Objects

Open pubpub-zz opened this issue 1 year ago • 1 comments

Explanation

I've noted some (many?) issues dealing that PyPDF2 is missing capability to clone objects (and all items below) for example this would allow to insert the same page multiple time but modifying it

Code Example

the proposed interface would be (for all type of objects) object.clone(pdf_dest,force_duplicate=False) -> duplicated_object pdf_dest would be a PdfWriter or PdfMerger by default already duplicated indirect object will be kept unique but setting force_duplicate to true will force duplication

Any Feedbacks?

pubpub-zz avatar Aug 01 '22 21:08 pubpub-zz

Sounds good!

I couldn't pin-point specific issues that were caused by this missing feature, but I also have the impression it would be helpful in some cases.

I'm uncertain what a good interface would be. Would the proposed interface mean we could take an object from a PdfReader and clone it to a PdfWriter? What would happen to (indirect) objects referenced within the cloned object? Do we maybe need a deep parameter (where False would mean a shallow copy of only the cloned object, and deep would mean a recursive approach)?

MartinThoma avatar Aug 06 '22 06:08 MartinThoma

cloning has been introduced.

pubpub-zz avatar Feb 05 '23 15:02 pubpub-zz