LinuxでPDFを画像に変換したりテキストを抽出する方法

LinuxでPDFを扱うパッケージにpopplerがあります。
popplerはxPDFを元にして作られています。

popplerのインストール

dnf -y install poppler poppler-utils

インストールすると次のコマンドが使用できるようになります。
pdffonts
pdfimages
pdfinfo
pdftohtml
pdftops
pdftotext

使用方法

pdftotext 【PDFファイル】 【出力先】

テキストの抽出では -raw オプションを付けたほうがうまく抽出できます。

pdftotext -raw hoge.pdf hoge.txt

help

$ pdftotext -h
pdftotext version 20.11.0
Copyright 2005-2020 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011 Glyph & Cog, LLC
Usage: pdftotext [options] <PDF-file> [<text-file>]
  -f <int>             : first page to convert
  -l <int>             : last page to convert
  -r <fp>              : resolution, in DPI (default is 72)
  -x <int>             : x-coordinate of the crop area top left corner
  -y <int>             : y-coordinate of the crop area top left corner
  -W <int>             : width of crop area in pixels (default is 0)
  -H <int>             : height of crop area in pixels (default is 0)
  -layout              : maintain original physical layout
  -fixed <fp>          : assume fixed-pitch (or tabular) text
  -raw                 : keep strings in content stream order
  -nodiag              : discard diagonal text
  -htmlmeta            : generate a simple HTML file, including the meta information
  -enc <string>        : output text encoding name
  -listenc             : list available encodings
  -eol <string>        : output end-of-line convention (unix, dos, or mac)
  -nopgbrk             : don't insert page breaks between pages
  -bbox                : output bounding box for each word and page size to html.  Sets -htmlmeta
  -bbox-layout         : like -bbox but with extra layout bounding box data.  Sets -htmlmeta
  -opw <string>        : owner password (for encrypted files)
  -upw <string>        : user password (for encrypted files)
  -q                   : don't print any messages or errors
  -v                   : print copyright and version info
  -h                   : print usage information
  -help                : print usage information
  --help               : print usage information
  -?                   : print usage information

関連記事

スポンサーリンク

大野式連続鋳造法でケーブルの通信品質が向上した(LANケーブルにも歴史あり)

ホームページ製作・web系アプリ系の製作案件募集中です。

上に戻る