Skip to content
TheChatArchiveThe Chat Archive
gpt-4.1-2025-04-14· OpenAIHugging Face LMArena Human Preference 140K

best way to compress pdf offline from terminal

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    best way to compress pdf offline from terminal

  2. Assistant

    Compressing a PDF offline from the terminal is a common task, especially on Linux and macOS systems. Here are some of the best methods using popular command-line tools:


    1. Using ghostscript (gs)

    Ghostscript is a powerful tool for PDF processing and is available on most Unix-like systems.

    Install Ghostscript

    • Ubuntu/Debian: sudo apt-get install ghostscript
    • macOS (Homebrew): brew install ghostscript

    Compress PDF Command

    gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
       -dNOPAUSE -dQUIET -dBATCH \
       -sOutputFile=output.pdf input.pdf
    

    PDFSETTINGS options:

    • /screen (lowest quality, smallest size)
    • /ebook (medium quality, good compression)
    • /printer (high quality)
    • /prepress (highest quality)
    • /default (a balance)

    Example:

    gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen \
       -dNOPAUSE -dQUIET -dBATCH \
       -sOutputFile=compressed.pdf original.pdf
    

    2. Using qpdf

    QPDF is another lightweight tool for PDF manipulation.

    Install QPDF

    • Ubuntu/Debian: sudo apt-get install qpdf
    • macOS (Homebrew): brew install qpdf

    Compress PDF Command

    qpdf --linearize input.pdf output.pdf
    

    Note: QPDF is mainly for linearizing and optimizing PDFs, not as aggressive as Ghostscript for compression.


    3. Using pdftk

    PDFTK can also compress PDFs, but not as effectively as Ghostscript.

    Install PDFTK

    • Ubuntu/Debian: sudo apt-get install pdftk
    • macOS (Homebrew): brew install pdftk-java

    Compress PDF Command

    pdftk input.pdf output output.pdf compress
    

    4. Using mutool (from MuPDF)

    MuPDF's mutool can also compress PDFs.

    Install MuPDF

    • Ubuntu/Debian: sudo apt-get install mupdf-tools
    • macOS (Homebrew): brew install mupdf

    Compress PDF Command

    mutool clean -gg -d input.pdf output.pdf
    

    Summary Table

    ToolCommand ExampleBest For
    Ghostscriptgs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile=out.pdf in.pdfBest compression
    QPDFqpdf --linearize in.pdf out.pdfFast, simple, less compression
    PDFTKpdftk in.pdf output out.pdf compressBasic compression
    MuPDFmutool clean -gg -d in.pdf out.pdfGood for cleaning PDFs

    Recommendation

    Ghostscript is generally the best for strong compression and flexibility.
    For most users, this command is the go-to:

    gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook \
       -dNOPAUSE -dQUIET -dBATCH \
       -sOutputFile=compressed.pdf original.pdf
    

    Tip: Always check the output quality to ensure it meets your needs!
    Let me know if you need a script or want to batch-compress multiple PDFs.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.