Command-line API

pdf2txt.py

A command line tool for extracting text and images from PDF and output it to plain text, html, xml or tags.

usage: python tools/pdf2txt.py [-h] [--debug] [--disable-caching]
                               [--page-numbers PAGE_NUMBERS [PAGE_NUMBERS ...]]
                               [--pagenos PAGENOS] [--maxpages MAXPAGES]
                               [--password PASSWORD] [--rotation ROTATION]
                               [--no-laparams] [--detect-vertical]
                               [--char-margin CHAR_MARGIN]
                               [--word-margin WORD_MARGIN]
                               [--line-margin LINE_MARGIN]
                               [--boxes-flow BOXES_FLOW] [--all-texts]
                               [--outfile OUTFILE] [--output_type OUTPUT_TYPE]
                               [--codec CODEC] [--output-dir OUTPUT_DIR]
                               [--layoutmode LAYOUTMODE] [--scale SCALE]
                               [--strip-control]
                               files [files ...]

Positional Arguments

files

One or more paths to PDF files.

Named Arguments

--debug, -d

Use debug logging level.

Default: False

--disable-caching, -C

If caching or resources, such as fonts, should be disabled.

Default: False

Parser

Used during PDF parsing

--page-numbers

A space-seperated list of page numbers to parse.

--pagenos, -p

A comma-separated list of page numbers to parse. Included for legacy applications, use –page-numbers for more idiomatic argument entry.

--maxpages, -m

The maximum number of pages to parse.

Default: 0

--password, -P

The password to use for decrypting PDF file.

Default: “”

--rotation, -R

The number of degrees to rotate the PDF before other types of processing.

Default: 0

Layout analysis

Used during layout analysis.

--no-laparams, -n

If layout analysis parameters should be ignored.

Default: False

--detect-vertical, -V

If vertical text should be considered during layout analysis

Default: False

--char-margin, -M

If two characters are closer together than this margin they are considered to be part of the same word. The margin is specified relative to the width of the character.

Default: 2.0

--word-margin, -W

If two words are are closer together than this margin they are considered to be part of the same line. A space is added in between for readability. The margin is specified relative to the width of the word.

Default: 0.1

--line-margin, -L

If two lines are are close together they are considered to be part of the same paragraph. The margin is specified relative to the height of a line.

Default: 0.5

--boxes-flow, -F

Specifies how much a horizontal and vertical position of a text matters when determining the order of lines. The value should be within the range of -1.0 (only horizontal position matters) to +1.0 (only vertical position matters).

Default: 0.5

--all-texts, -A

If layout analysis should be performed on text in figures.

Default: True

Output

Used during output generation.

--outfile, -o

Path to file where output is written. Or “-” (default) to write to stdout.

Default: “-“

--output_type, -t

Type of output to generate {text,html,xml,tag}.

Default: “text”

--codec, -c

Text encoding to use in output file.

Default: “utf-8”

--output-dir, -O

The output directory to put extracted images in. If not given, images are not extracted.

--layoutmode, -Y

Type of layout to use when generating html {normal,exact,loose}. If normal, each line is positioned separately in the html. If exact, each character is positioned separately in the html. If loose, same result as normal but with an additional newline after each text line. Only used when output_type is html.

Default: “normal”

--scale, -s

The amount of zoom to use when generating html file. Only used when output_type is html.

Default: 1.0

--strip-control, -S

Remove control statement from text. Only used when output_type is xml.

Default: False

dumppdf.py

Extract pdf structure in XML format

usage: python tools/dumppdf.py [-h] [--debug]
                               [--extract-toc | --extract-embedded EXTRACT_EMBEDDED]
                               [--page-numbers PAGE_NUMBERS [PAGE_NUMBERS ...]]
                               [--pagenos PAGENOS] [--objects OBJECTS] [--all]
                               [--password PASSWORD] [--outfile OUTFILE]
                               [--raw-stream | --binary-stream | --text-stream]
                               files [files ...]

Positional Arguments

files

One or more paths to PDF files.

Named Arguments

--debug, -d

Use debug logging level.

Default: False

--extract-toc, -T

Extract structure of outline

Default: False

--extract-embedded, -E

Extract embedded files

Parser

Used during PDF parsing

--page-numbers

A space-seperated list of page numbers to parse.

--pagenos, -p

A comma-separated list of page numbers to parse. Included for legacy applications, use –page-numbers for more idiomatic argument entry.

--objects, -i

Comma separated list of object numbers to extract

--all, -a

If the structure of all objects should be extracted

Default: False

--password, -P

The password to use for decrypting PDF file.

Default: “”

Output

Used during output generation.

--outfile, -o

Path to file where output is written. Or “-” (default) to write to stdout.

Default: “-“

--raw-stream, -r

Write stream objects without encoding

Default: False

--binary-stream, -b

Write stream objects with binary encoding

Default: False

--text-stream, -t

Write stream objects as plain text

Default: False