There are amazing examples of merging together two PDFs. How does one insert a 1-page PDF inside a second PDF right after the first page and/or how can I split a PDF into two separate PDFs at specific page ranges?
Hi,
I responded about adding pages between pages in #61 (here provided to give you the full thought process). my recommendation is to create a new PDF and import the pages to it from both PDFs in the order that you want, appending on after the other.
As for splitting a PDF, here is some code splitting one PDF to multiple PDFs, one per page, you can figure out the ranges part:
pdfReader = hummus.createReader('main.pdf')
for(var i=0;i<pdfReader.getPagesCount();++i){
pdfWriter = hummus.createWriter('output' + i + '.pdf')
pdfWriter.createPDFCopyingContext(pdfReader).appendPDFPageFromPDF(i);
pdfWriter.end();
}
Hi, thanks for your example above. I am seeing an issue with file sizes. All the files are the same file size as the original file.
Example:
I have 3MB PDF document, which contains 10 pages.
After I split it into multiple PDFs, each PDF is the same size as the original.
Is this expected?
@yuriyvaskevich I just run this code and its working not as you described. All files are different sizes
Most helpful comment
Hi,
I responded about adding pages between pages in #61 (here provided to give you the full thought process). my recommendation is to create a new PDF and import the pages to it from both PDFs in the order that you want, appending on after the other.
As for splitting a PDF, here is some code splitting one PDF to multiple PDFs, one per page, you can figure out the ranges part: