license: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing,
     software distributed under the License is distributed on an
     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.

layout: documentation title: Command-Line Tools

Command-Line Tools

PDFBox comes with a series of command-line utilities. They are available as standard Java applications.

See the Dependencies page for instructions on how to set your classpath in order to run PDFBox tools as Java applications.

Decrypt

This application will decrypt a PDF document.

NOTE: You must have the owner password to decrypt the document!

Usage: java -jar pdfbox-app-2.y.z.jar Decrypt [OPTIONS] <inputfile> [outputfile]

Command-Line ParameterDescription
-passwordPassword to the PDF or certificate in keystore.
-keyStorePath to keystore that holds certificate to decrypt the document. This is only required if the document is encrypted with a certificate, otherwise only the password is required.
-aliasThe alias to the certificate in the keystore.
inputfileThe PDF file to decrypt.
outputfileThe file to save the decrypted document to. If left blank then it will be the same as the input file.

Encrypt

This application will encrypt a PDF document.

Usage: java -jar pdfbox-app-2.y.z.jar Encrypt [OPTIONS] <password> <inputfile>

Command-Line ParameterDefaultDescription
-OThe owner password to the PDF, ignored if -certFile is specified.
-UThe user password to the PDF, ignored if -certFile is specified.
-certFilePath to X.509 cert file.
-canAssembletrueSet the assemble permission.
-canExtractContenttrueSet the extraction permission.
-canExtractForAccessibilitytrueSet the extraction permission.
-canFillInFormtrueSet the fill in form permission.
-canModifytrueSet the modify permission.
-canModifyAnnotationstrueSet the modify annots permission.
-canPrinttrueSet the print permission.
-canPrintDegradedtrueSet the print degraded permission.
-keyLength40, 128 or 256The number of bits for the encryption key. For 128 and above bits Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files must be installed.
inputfileThe PDF file to encrypt.
outputfileThe file to save the encrypted document to. If left blank then it will be the same as the input file.

ExtractImages

This application will extract all images from the given PDF document.

Usage: java -jar pdfbox-app-2.y.z.jar ExtractImages [OPTIONS] <inputfile>

Command-Line ParameterDefaultDescription
-passwordThe password to the PDF document.
-prefixPDF nameImage prefix to use.
-directJPEGfalseForces the direct extraction of JPEG images regardless of colorspace.

ExtractText

This application will extract all text from the given PDF document.

Usage: java -jar pdfbox-app-2.y.z.jar ExtractText [OPTIONS] <inputfile> [Text file]

Command-Line ParameterDefaultDescription
-alwaysNextfalseProcess next page (if applicable) despite IOException (ignored when -html)
-passwordThe password to the PDF document.
-encodingdefault encodingThe encoding type of the text file, e.g. ISO-8859-1, UTF-8, UTF-16BE.
-consolefalseSend text to console instead of file.
-htmlfalseOutput in HTML format instead of raw text.
-sortfalseSort the text before writing.
-ignoreBeadsfalseDisables the separation by beads.
-debugfalseEnables debug output about the time consumption of every stage.
-rotationMagicfalseAnalyze each page for rotated/skewed text, rotate to 0° and extract separately (slower, and ignored when -html)
-startPage1The first page to extract, one based.
-endPageInteger.MAX_INTThe last page to extract, one based.

OverlayPDF

This application will overlay one document with the content of another document

Usage: java -jar pdfbox-app-2.y.z.jar OverlayPDF <input.pdf> [OPTIONS] <output.pdf>

Command-Line ParameterDefaultDescription
inputfileThe PDF file to be overlayed.
defaultOverlay.pdfDefault overlay file.
-odd oddPageOverlay.pdfOverlay file used for odd pages.
-even evenPageOverlay.pdfOverlay file used for even pages.
-first firstPageOverlay.pdfOverlay file used for the first page.
-last lastPageOverlay.pdfOverlay file used for the last pages.
-page pageNumber specificPageOverlay.pdfoverlay file used for the given page number, may occur more than once.
-positionbackgroundWhere to put the overlay, foreground or background.
outputfileThe resulting pdf file.

Examples:

  • OverlayPDF input.pdf overlay.pdf output.pdf
  • OverlayPDF input.pdf defaultOverlay.pdf -page 10 overlayForPage10.pdf -position foreground output.pdf
  • OverlayPDF input.pdf -odd oddOverlay.pdf -even evenOverlay.pdf output.pdf

PDFDebugger

This application will take an existing PDF document and allows to analyze and inspect the internal structure. It is used as replacement for the PDFReader which was removed in 2.0.0.

Usage: java -jar pdfbox-app-2.y.z.jar PDFDebugger [inputfile]

Command-Line ParameterDefaultDescription
-passwordThe password to the PDF document.
-viewstructureActivates the “view structure” view on startup.
inputfilethe name of an optional PDF file to open.

PDFMerger

This application will take a list of pdf documents and merge them, saving the result in a new document.

Usage: java -jar pdfbox-app-2.y.z.jar PDFMerger <Source PDF files (2 ..n)> <Target PDF file>

PDFSplit

This application will take an existing PDF document and split it into a number of new documents.

Per default the resulting files will be named after the original filenmame with -<nr> appended before the suffix. To override the filename use the outputPrefix option.

Usage: java -jar pdfbox-app-2.y.z.jar PDFSplit [OPTIONS] <PDF file>

Command-Line ParameterDefaultDescription
-passwordThe password to the PDF document.
-splitNumber of pages of every splitted part of the pdf.
-startPageThe page to start at.
-endPageThe page to stop at.
--outputPrefixThe prefix for the generated file name. The resulting name will be in the format <prefix>-<nr>.pdf

Examples:

  • PDFSplit -split 2 sample_with_13_pages.pdf will split the pdf in pieces of 2 pages each except the last which will contain 1 page only.
  • PDFSplit -startPage 5 sample_with_13_pages.pdf will provide a pdf containing all pages of the source pdf starting at page 5
  • PDFSplit -startPage 5 -endPage 10 sample_with_13_pages.pdf will provide a pdf containing all pages from 5 to 10 of the source pdf
  • PDFSplit -split 2 -startPage 5 -endPage 10 sample_with_13_pages.pdf will provide 3 pdfs containing all pages from 5 to 10 of the source pdf 2 pages each

PDFToImage

This application will create an image for every page in the PDF document.

Usage: java -jar pdfbox-app-2.y.z.jar PDFToImage [OPTIONS] <PDF file>

Command-Line ParameterDefaultDescription
-passwordThe password to the PDF document.
-imageTypejpgThe image type to write to. Currently only jpg or png.
-outputPrefixName of PDF documentThe prefix to the image file.
-startPage1The first page to convert, one based.
-endPageInteger.MAX_INTThe last page to convert, one based.
-pageThe only page to extract (1-based).
-dpidetected from screen (or 96 if headless)DPI resolution of exported images.
-colorrgbThe color depth (valid: bilevel, gray, rgb, rgba).
-cropbox <int> <int> <int> <int>The page area to export.
-timePrints timing information to stdout.

PrintPDF

This application will send a pdf document to the printer.

Usage: java -jar pdfbox-app-2.y.z.jar PrintPDF [OPTIONS] <inputfile>

Command-Line ParameterDefaultDescription
-passwordThe password to decrypt the PDF.
-silentPrintPrint the PDF without prompting for a printer.
-printerName <name>Print to specified printer.
-orientation [auto | portrait | landscape]autoPrint using orientation.
-borderPrint with border.
-dpiRender into intermediate image with specific dpi and then print.
inputfileThe PDF file to print.

TextToPDF

This application will create a PDF document from a text file.

Usage: java -jar pdfbox-app-2.y.z.jar TextToPDF [OPTIONS] <outputfile> <textfile>

Command-Line ParameterDefaultDescription
-standardFontHelveticaThe font to use for the text. Either this or -ttf should be specified but not both.
-ttfThe TTF font to use for the text. Either this or -standardFont should be specified but not both.
-fontSize10The size of the font to use.

The following font names can be used for the parameter standardFont:

  • Courier
  • Courier-Bold
  • Courier-Oblique
  • Courier-BoldOblique
  • Helvetica
  • Helvetica-Bold
  • Helvetica-Oblique
  • Helvetica-BoldOblique
  • Symbol
  • Times-Bold
  • Times-Roman
  • Times-Italic
  • Times-BoldItalic
  • ZapfDingbats

WriteDecodedDoc

An application to decompress PDF documents.

Usage: java -jar pdfbox-app-2.y.z.jar WriteDecodedDoc <input-file> <output-file>

Command-Line ParameterDefaultDescription
-passwordThe password to the PDF document.
input-fileThe PDF file to decompress
output-fileThe destination PDF file