Combining multiple PDFs from media objects - possible?

Stumped on this one for a little bit, despite looking through examples and forum. Hoping it is in front of my face, and just missing it.

I am creating pdf’s using PDFRenderer - works great, so simple. I can use this to open some data files, do some analysis on the data in the files, and create a pdf report for each file I reviewed with some nice graphs of the data. But I have not been able to figure out a way to combine the media objects that are coming from PDFRenderer into one pdf. So for now, I can get one pdf for each file I review.

Would PyPDF2 help?

1 Like

Thank for the suggestion! I have been trying that but was having trouble figuring the process to go from media objects to pdf but if that sounds like the best approach I will keep at it. A little more background: A data file is sent to the server, it gets analyzed, generates a media object using PDFRenderer, that gets sent back to the client and the download command is used and the pdf is now available on the client… I am trying to provide a Print All function, to do this analysis with multiple files, but then create a single PDF that has the multiple pdf reports combined. So my struggle is trying to figure out how to “append” media objects?

As I understand it, with PYPDF2, you don’t append media objects. That’s taking a few too many mental shortcuts. There’s structure in them thar objects!

  • Each object represents a PDF file.
  • Each file wraps a series of pages.
  • PYPDF2 gives you a way to
    • extract pages and
    • build a new PDF from them.

The trick, then, is in finding a way to convert media objects into the file-like objects that PYPDF2 understands, for input, and back again, for storage or transmittal.

For converting media objects into binary file-like objects (e.g., for input to PYPDF2):

For converting binary-file-like objects (e.g., from PYPDF2) into media objects:

Thanks for the guidance. All good now.