pdfjs icon indicating copy to clipboard operation
pdfjs copied to clipboard

Merging two pages into 1 page

Open llacroix opened this issue 3 years ago • 2 comments

I've been debugging a bit and I'm not sure how to proceed to merge 2 pages into a single one. Let say I have a PDF 1 with a cell that fits into a width of a page and 20mm of height. And I have a PDF 2 with the rest of a page with some margin at the top with 20mm. How would I merge that first pdf (header) with the second pdf (body).

I'm not so sure how to get the content of the pages as all the code does is _writeObject that adds the page into the _pages and add all child objects of the page into the new Document. But what I want is to create an empty page and add at the top the first pdf cropped to 20mm height and the other bellow.

llacroix avatar Dec 01 '20 04:12 llacroix

Hi, this sounds like your use-case could be solved by adding a PDF as an "image", like done here https://github.com/rkusa/pdfjs/blob/master/test/pdfs/image/pdf-complex.js

You have to

  • create an Image object from a PDF https://github.com/rkusa/pdfjs/tree/master/docs#new-pdfimagesrc
  • and add it to the document you want to embed it into https://github.com/rkusa/pdfjs/blob/master/docs/fragment.md#imageimg-opts

Does this help?

rkusa avatar Dec 03 '20 14:12 rkusa

@rkusa I'll give it a try but I believe this could work yes.

llacroix avatar Dec 09 '20 03:12 llacroix