Search code examples
command-line-interfaceqpdf

Split a PDF file into another two PDF files using qpdf


Is it possible to split a PDF file into two parts or n parts using qpdf tool?

The docs say so but I couldn't find the exact command to do it.

I'm using qpdf version 10.0.1.


Solution

  • Yes, it is very easy:

    Assume infile.pdf has 12 pages (pagecount):

    qpdf.exe --split-pages=n infile.pdf output-%d.pdf
    

    Pseudo code:

    n = Integer(pagecount / number_of_parts)
    

    More details from the original documentation:

    --split-pages=[n]

    Write each group of n pages to a separate output file. If n is not specified, create single pages. Output file names are generated as follows:

    If the string %d appears in the output file name, it is replaced with a range of zero-padded page numbers starting from 1.

    Otherwise, if the output file name ends in .pdf (case insensitive), a zero-padded page range, preceded by a dash, is inserted before the file extension.

    Otherwise, the file name is appended with a zero-padded page range preceded by a dash.

    Page ranges are a single number in the case of single-page groups or two numbers separated by a dash otherwise. For example, if infile.pdf has 12 pages

    qpdf --split-pages infile.pdf %d-out would generate files 01-out through 12-out

    qpdf --split-pages=2 infile.pdf outfile.pdf would generate files outfile-01-02.pdf through outfile-11-12.pdf

    qpdf --split-pages infile.pdf something.else would generate files something.else-01 through something.else-12

    Reference: https://qpdf.readthedocs.io/en/stable/cli.html#option-split-pages