pdftotext 命令详解

| 选择喜欢的代码风格  

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

pdftotext 命令安装:


-bash/zsh: pdftotext: command not found

#Windows (WSL2)
sudo apt-get update sudo apt-get install poppler-utils

#Debian
apt-get install poppler-utils

#Ubuntu
apt-get install poppler-utils

#Alpine
apk add poppler

#Arch Linux
pacman -S poppler

#Kali Linux
apt-get install poppler-utils

#CentOS
yum install poppler-utils

#Fedora
dnf install poppler-utils

#OS X
brew install poppler

#Raspbian
apt-get install poppler-utils

#Dockerfile
dockerfile.run/pdftotext

#Docker
docker run cmd.cat/pdftotext pdftotext

pdftotext 命令补充说明:


pdftotext 是便携式文档格式 (PDF) 到文本转换器(目前版本 4.04)

pdftotext 命令语法:


pdftotext [options] [PDF-file [text-file]]

pdftotext 命令选项:


Many of the following options can be set with configuration file commands. These are listed in square brackets with the description of the corresponding command line option.
−f number

Specifies the first page to convert.

−l number

Specifies the last page to convert.

−layout

Maintain (as best as possible) the original physical layout of the text. The default is to ´undo’ physical layout (columns, hyphenation, etc.) and output the text in reading order. If the −fixed option is given, character spacing within each line will be determined by the specified character pitch.

−simple

Similar to −layout, but optimized for simple one-column pages. This mode will do a better job of maintaining horizontal spacing, but it will only work properly with a single column of text.

−simple2

Similar to −simple, but handles slightly rotated text (e.g., OCR output) better. Only works for pages with a single column of text.

−table

Table mode is similar to physical layout mode, but optimized for tabular data, with the goal of keeping rows and columns aligned (at the expense of inserting extra whitespace). If the −fixed option is given, character spacing within each line will be determined by the specified character pitch.

−lineprinter

Line printer mode uses a strict fixed-character-pitch and -height layout. That is, the page is broken into a grid, and characters are placed into that grid. If the grid spacing is too small for the actual characters, the result is extra whitespace. If the grid spacing is too large, the result is missing whitespace. The grid spacing can be specified using the −fixed and −linespacing options. If one or both are not given on the command line, pdftotext will attempt to compute appropriate value(s).

−raw

Keep the text in content stream order. Depending on how the PDF file was generated, this may or may not be useful.

−fixed number

Specify the character pitch (character width), in points, for physical layout, table, or line printer mode. This is ignored in all other modes.

−linespacing number

Specify the line spacing, in points, for line printer mode. This is ignored in all other modes.

−clip

Text which is hidden because of clipping is removed before doing layout, and then added back in. This can be helpful for tables where clipped (invisible) text would overlap the next column.

−nodiag

Diagonal text, i.e., text that is not close to one of the 0, 90, 180, or 270 degree axes, is discarded. This is useful to skip watermarks drawn on top of body text, etc.

−enc encoding-name

Sets the encoding to use for text output. The encoding−name must be defined with the unicodeMap command (see xpdfrc(5)). The encoding name is case-sensitive. This defaults to "Latin1" (which is a built-in encoding). [config file: textEncoding]

−eol unix | dos | mac

Sets the end-of-line convention to use for text output. [config file: textEOL]

−nopgbrk

Don’t insert a page breaks (form feed character) at the end of each page. [config file: textPageBreaks]

−bom

Insert a Unicode byte order marker (BOM) at the start of the text output.

−marginl number

Specifies the left margin, in points. Text in the left margin (i.e., within that many points of the left edge of the page) is discarded. The default value is zero.

−marginr number

Specifies the right margin, in points. Text in the right margin (i.e., within that many points of the right edge of the page) is discarded. The default value is zero.

−margint number

Specifies the top margin, in points. Text in the top margin (i.e., within that many points of the top edge of the page) is discarded. The default value is zero.

−marginb number

Specifies the bottom margin, in points. Text in the bottom margin (i.e., within that many points of the bottom edge of the page) is discarded. The default value is zero.

−opw password

Specify the owner password for the PDF file. Providing this will bypass all security restrictions.

−upw password

Specify the user password for the PDF file.

−verbose

Print a status message (to stdout) before processing each page. [config file: printStatusInfo]

−q

Don’t print any messages or errors. [config file: errQuiet]

−cfg config-file

Read config-file in place of ~/.xpdfrc or the system-wide config file.

−listencodings

List all available text output encodings, then exit.

−v

Print copyright and version information, then exit.

−h

Print usage information, then exit. (−help and −−help are equivalent.)

pdftotext 命令实例:


pdftotext 将 filename.pdf 转换为纯文本并将其打印到标准输出:

pdftotext filename.pdf -

pdftotext 将 filename.pdf 转换为纯文本并将其保存为 `filename.txt`:

pdftotext filename.pdf

pdftotext 将 filename.pdf 转换为纯文本并保留布局:

pdftotext -layout filename.pdf

pdftotext 将 input.pdf 转换为纯文本并将其保存为 output.txt

pdftotext input.pdf output.txt

pdftotext 将 input.pdf 的第 234 页转换为纯文本并将它们保存为 output.txt

pdftotext -f 2 -l 4 input.pdf output.txt

pdftotext 扩展阅读:




pdftotext 命令评论