Hummusjs: Insert a page of one PDF into another, Split

Created on 4 Feb 2017  路  3Comments  路  Source: galkahana/HummusJS

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?

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:

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();
}

All 3 comments

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MOuli90 picture MOuli90  路  6Comments

nnnikolay picture nnnikolay  路  7Comments

JensWinter picture JensWinter  路  5Comments

GautierT picture GautierT  路  6Comments

ziram picture ziram  路  3Comments