Integration & Embedding

Command Line PDF Tools and Libraries for IT Teams and Software Developers

The open source CLIs that merge, split, compress, convert and OCR PDFs from a script, and the libraries to reach for when a CLI isn't enough.

Marcus Chen · July 5, 2026

Abstract illustration in orange, purple and cream with a large lowercase d, the cover of a guide to command line PDF tools for developers

The command line PDF tools most teams need are free and open source: qpdf for merging, splitting and encryption, Ghostscript for compression and PDF/A, Poppler for text and images, MuPDF for fast rendering, and Tesseract for OCR. Together they cover most PDF jobs a script or CI pipeline has to do.

What to Look for in a PDF Tool for Scripts and Servers

  • Runs headless: no desktop install, no GUI. It should work in a container on a fresh server.
  • Exit codes you can trust: a failed conversion should fail the job, not write an empty file.
  • Standards: PDF/A for archives and PDF/UA for accessibility, if your sector requires them.
  • License: GPL, AGPL and Apache 2.0 mean different things once the tool ships inside your product. Read the license before it lands in production.

How to Install These Command Line PDF Tools

On Windows, start at each project's own download page.

ToolDebian or UbuntuMac with HomebrewPrograms you then run
qpdfsudo apt install qpdfbrew install qpdfqpdf
Ghostscriptsudo apt install ghostscriptbrew install ghostscriptgs
Popplersudo apt install poppler-utilsbrew install popplerpdftotext, pdftoppm, pdfinfo, pdfunite, pdfseparate, pdftocairo
MuPDFsudo apt install mupdf-toolsbrew install mupdf-toolsmutool
pdftksudo apt install pdftk-javabrew install pdftk-javapdftk
Tesseractsudo apt install tesseract-ocrbrew install tesseracttesseract
OCRmyPDFsudo apt install ocrmypdfbrew install ocrmypdfocrmypdf
LibreOfficesudo apt install libreofficebrew install --cask libreofficesoffice

OCRmyPDF's own guide warns that the Debian and Ubuntu package can lag several major versions behind.

qpdf: Merge, Split, Encrypt and Repair Structure

qpdf changes the structure of a PDF without touching its content, so it's fast and doesn't lose quality. It's the tool for merging (with its --pages option), splitting, rotating, linearizing and removing passwords.

1qpdf --empty --pages a.pdf b.pdf -- merged.pdf      # merge
2qpdf --split-pages report.pdf page-%d.pdf           # one file per page
3qpdf --decrypt --password=secret in.pdf out.pdf     # remove a known password
4qpdf --linearize in.pdf web.pdf                     # fast web view
5qpdf --check in.pdf                                 # report structural problems

Our Unlock PDF tool runs qpdf with its decrypt option. It needs the password and doesn't crack one. What linearizing does for large files is covered in our linearized PDF guide.

Ghostscript: Compress, Convert and Rewrite PDFs

Ghostscript reads a PDF and writes a new one. That's how it compresses: its pdfwrite device downsamples pictures to a target resolution.

1gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -o small.pdf big.pdf

Use it only on a file that isn't password-protected or restricted, since Ghostscript writes an unencrypted copy.

The presets are /screen, /ebook, /printer and /prepress, from smallest to best quality. For one file, there's our Compress PDF tool. The Ghostscript documentation lists every device and option.

Ghostscript can also rebuild damaged files, since it reads whatever it can and writes a new PDF. For one damaged file, there's our Repair PDF tool. Our post on rescuing a CRDOWNLOAD file shows what that rebuild recovered from cut-off downloads.

Poppler Utilities: Text, Images and Page Info

  • pdftotext -layout in.pdf out.txt pulls the text out, keeping the column layout.
  • pdftoppm -png -r 150 in.pdf page renders each page as a PNG at 150 dpi.
  • pdfinfo in.pdf prints page count, page size, encryption and metadata.
  • pdfunite a.pdf b.pdf out.pdf and pdfseparate in.pdf page-%d.pdf merge and split.
  • pdftocairo -svg in.pdf out.svg writes vector SVG.

MuPDF and pdftk: Rendering and Quick Assembly

MuPDF's mutool renders pages and converts PDF to images, text and other formats. mutool draw -o page-%d.png -r 150 in.pdf renders every page, and mutool clean rewrites a file.

PDFtk merges and splits too:

1pdftk report_part1.pdf report_part2.pdf cat output final_report.pdf

Which Merge Command Keeps Bookmarks, Links and Form Fields?

None of the five merge commands we ran kept all three. In November 2026 we merged two 2-page PDFs exported from LibreOffice, each with two heading bookmarks and an internal link, plus one text field we added with pdf-lib. We ran the versions in Debian 13 and read the results back with pdf.js and qpdf.

CommandBookmarks (of 4)Link in the second fileForm fields
pdfunite a.pdf b.pdf out.pdf0Lands on page 2, the wrong fileBoth lost their names and values
qpdf --empty --pages a.pdf b.pdf -- out.pdf0Right pageBoth kept and filled in
qpdf a.pdf --pages . b.pdf -- out.pdf2, the first file'sRight pageBoth kept and filled in
gs -sDEVICE=pdfwrite -o out.pdf a.pdf b.pdf4Right pageGone, the typed values became page text
mutool merge -o out.pdf a.pdf b.pdf4Link removedGone

So use qpdf when forms or links matter, and start from the file whose bookmarks you want to keep. If bookmarks from every file matter more, there are no forms and no file is password-protected or restricted, use Ghostscript, which rewrites the file. Skip pdfunite for anything with internal links.

We didn't run pdftk. The command above is the form PDF Labs gives.

Locked files stop pdfunite: it exited with 255 and wrote nothing, for a file needing a password to open and for one that only restricts editing. qpdf merged the first kind once it had the password:

1qpdf --empty --pages locked.pdf --password=secret b.pdf -- out.pdf

Tesseract and LibreOffice: OCR and Office Conversion

Tesseract recognizes text in images. On scanned PDFs, it's usually run through OCRmyPDF, which renders each page, runs Tesseract and puts an invisible text layer back over the scan: ocrmypdf scan.pdf searchable.pdf.

LibreOffice converts Office files without opening a window: soffice --headless --convert-to pdf report.docx. It handles Word, Excel, PowerPoint and OpenDocument files, and most of our Office converters run on it.

For a one-off file, our OCR PDF tool runs Tesseract for you (English only), and Make PDFs Searchable explains when OCR is worth it.

PDF Libraries When a CLI Isn't Enough

A CLI is the quickest fix for a batch job. When PDFs are generated inside your application, per request, a library fits better.

iText

iText Core is a PDF library for Java and .NET, at version 9 when we read iText's page in November 2026. It creates, edits and signs PDFs, with support for PDF/A.

It's available under AGPL or a commercial license. Sort out the license before procurement does it for you.

The iText website home page, with the heading Generate and Manipulate PDFs Effortlessly, one of the PDF libraries compared with command line PDF tools

pdf-lib

pdf-lib is a JavaScript library that runs in Node.js and in browsers, with no native dependencies. It creates PDFs, adds pages, draws text and images, fills forms, and merges or splits files. It doesn't render pages to images, and it's MIT licensed.

Our Merge PDF tool runs pdf-lib in your browser, so the files never leave your computer. Split PDF builds its parts with pdf-lib on our server.

The pdf-lib project page with its red and white logo and a code sample, a JavaScript library to use next to command line PDF tools

Apache PDFBox

Apache PDFBox is the open source Java library, under the Apache 2.0 license. It extracts text, splits and merges, fills forms and signs. It also includes command line utilities, so it doubles as a CLI on a machine with Java.

The Apache PDFBox download page listing the latest releases and the command line tools package

Hosted APIs and Commercial SDKs

Hosted PDF APIs such as pdfRest's cloud service take a file over HTTP and return the processed result, so you don't run any PDF software yourself. The trade is that every document leaves your network, which rules them out for some data (pdfRest also sells a self-hosted container). Commercial SDKs such as VeryPDF's are another route, if you'd rather buy than assemble.

The pdfRest website home page with the heading Powerful PDF Processing, a hosted alternative to command line PDF tools
The VeryPDF Advanced PDF Tools product page with Free Trial and Buy Now buttons, a commercial alternative to open source command line PDF tools

For how a PDF API fits into an application, read our PDF API guide.

Automating PDF Jobs in CI/CD Pipelines

Put the CLIs in a container image and call them from a pipeline step. Most of the tools above install from the distribution's package manager (qpdf, ghostscript, poppler-utils, mupdf-tools, tesseract-ocr, libreoffice).

  • Keep PDF work as a separate step with clear inputs and outputs, so a failure points at one command.
  • Check exit codes. qpdf documents 0 for clean, 3 for warnings and 2 for errors, and that's what we got: 3 with a usable file on a PDF missing its last 20 bytes, 2 with no output on one missing its last 200.
  • Check the output too. Ghostscript returned 0 on a PDF cut to its first 300 bytes and wrote a blank page, and on a non-PDF it returned 1 but left a file behind. Compare page counts with pdfinfo before and after.
  • Test against the ugly files you really get from clients. A tool that handles clean PDFs can still choke on a malformed one.

Which Command Line PDF Tool or Library to Choose

Feature RequirementRecommended Library / Tool
Fast Web App Generation (Node/JS)PDF-Lib
Digital Signatures and PDF/AiText Core
Zero-Infrastructure MicroservicespdfRest API
Heavy Java Backend Data ExtractionApache PDFBox
Basic Server Script Automationqpdf, Ghostscript and Poppler

Frequently Asked Questions about Command Line PDF Tools

What is the best free command line tool to merge PDFs?

For most files, qpdf with its --pages option, as shown in the qpdf section above. It kept links and form fields in our test, though not bookmarks. Poppler's pdfunite a.pdf b.pdf merged.pdf is shorter, but it sent a link to the wrong page and broke the form fields.

How do I compress a PDF from the command line?

Use Ghostscript's pdfwrite device with a preset, for example -dPDFSETTINGS=/ebook, on a PDF that isn't protected, since pdfwrite writes an unencrypted copy. Pictures get downsampled; text and vector drawings stay sharp.

Can command line tools OCR a scanned PDF?

Yes. OCRmyPDF runs Tesseract on each page and writes a PDF with a text layer, so the scan becomes searchable.

Are these command line PDF tools free for commercial use?

Most are open source, but the licenses differ: Ghostscript and MuPDF are AGPL with commercial licenses available, qpdf and PDFBox are Apache 2.0, and Poppler is GPL. Check the license for how you distribute your product.

Try it on your own file