PDF to PDF Command line Examples

Use these command-line examples for common PDF to PDF tasks. See the CLI guide for installation, input and output handling, and diagnostics.

You can run the examples below without account setup. The CLI uses demo credentials unless you have configured your own API credentials. Update the input URLs and filenames as needed.

Commands use POSIX-shell syntax, as in Bash or Zsh, and save results in the current directory.

Merging

Supply local PDF files in the order they should appear in the merged document. These commands save the result with --output. See Handle the Result for output choices and failure handling.

Merge PDF files

Merge first.pdf and second.pdf in that order.

pdf2pdf --output merged.pdf \
    first.pdf second.pdf

PDF operations

Add a watermark

Apply watermark.pdf to proposal.pdf and save company_offer.pdf.

pdf2pdf --page-watermark=watermark.pdf \
    --output company_offer.pdf \
    proposal.pdf

Linearize a PDF

Optimize not_linearized.pdf for progressive loading in a browser and save it as linearized.pdf.

pdf2pdf --linearize \
    --output linearized.pdf \
    not_linearized.pdf

Extract pages

Extract page 3 and pages 7 through the end of 13_pages.pdf into output.pdf.

pdf2pdf --action=extract \
    --page-range=3,7- \
    --output output.pdf \
    13_pages.pdf

Delete pages

Remove pages 1–3 and page 10 from 13_pages.pdf and save the remaining pages to output.pdf.

pdf2pdf --action=delete \
    --page-range=1-3,10 \
    --output output.pdf \
    13_pages.pdf

Split a PDF

Split 13_pages.pdf into two documents: pages 1–10 in pages1-10.pdf, and the remaining pages in pages11-end.pdf.

pdf2pdf --action=extract \
    --page-range=1-10 \
    --output pages1-10.pdf \
    13_pages.pdf &&
pdf2pdf --action=extract \
    --page-range=11- \
    --output pages11-end.pdf \
    13_pages.pdf