Giter VIP home page Giter VIP logo

Comments (2)

MatthiasValvekens avatar MatthiasValvekens commented on June 15, 2024

Hey, I dropped this functionality when I forked (part of) PyPDF2, because I considered it out of scope for pyHanko (at least for now) and didn't want to be on the hook for maintaining it. The reason being that merging pages is very straightforward in most cases, but getting it 100% right is a little tricky.

The reason for the difficulty has to do with page resources. If both pages use a resource with the same name (which is by no means rare), you can't just merge the resource dictionaries together without modification. This can be dealt with by changing resource names, but that requires reencoding the content stream, which requires a parser that can tokenise PDF content streams, etc. Granted, that particular problem can be sidestepped by first converting one of the pages to a form XObject before merging, but that method isn't completely foolproof either if the PDF file is tagged.

Anyway, bottom line is that this is harder than it looks (in general), and it isn't very high up on my priority list because pyHanko wasn't meant to be a general-purpose PDF manipulation library in the first place. That said, I don't want to half-ass a high-level function like this either, so if I ever end up putting in a merge feature, I'm going to take my time to do it the proper way :)

Are you sure that merging pages is the only way forward? If so, using import_page_as_xobject should get you halfway there if you don't care about tags. You can then add that XObject to the other page's resource dictionary and draw it with the Do operator in PDF. I don't have time to put together a fully fleshed-out example right now (and probably won't until the end of the week), but this might serve as a starting point. :)

from pyhanko.

MatthiasValvekens avatar MatthiasValvekens commented on June 15, 2024

Closing this one as wontfix due to lack of activity. Feel free to reopen if there's new information. :)

from pyhanko.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.