`
fudehai001
  • 浏览: 498812 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

PDFMiner

阅读更多

 

PDFMiner

Python PDF parser and analyzer

Homepage Recent Changes

<!-- hhmts start --> Last Modified: Sun Jul 12 00:36:44 JST 2009 <!-- hhmts end -->


What's It?

PDFMiner is a suite of programs that help extracting and analyzing text data of PDF documents. Unlike other PDF-related tools, it allows to obtain the exact location of texts in a page, as well as other extra information such as font information or ruled lines. It includes a PDF converter that can transform PDF files into other text formats (such as HTML). It has an extensible PDF parser that can be used for other purposes instead of text analysis.

Features:

  • Written entirely in Python. (version 2.4 or newer required)
  • PDF-1.7 specification support. (well, almost)
  • Non-ASCII languages and vertical writing scripts support.
  • Various font types (Type1, TrueType, Type3, and CID) support.
  • Basic encryption (RC4) support.
  • PDF to HTML conversion (with a sample converter web app).
  • Outline (TOC) extraction.
  • Tagged contents extraction.
  • Infer text running by using clustering technique.

Download:
http://www.unixuser.org/~euske/python/pdfminer/pdfminer-dist-20090711.tar.gz (1.8Mbytes)

Discussion: (for questions and comments, post here)
http://groups.google.com/group/pdfminer-users/

View the source:
http://code.google.com/p/pdfminerr/source/browse/trunk/pdfminer

Online Demonstration: (pdf -> html conversion webapp)
http://pdf2html.tabesugi.net:8080/


How to Install

  1. Install Python 2.4 or newer.
  2. Download the PDFMiner source .
  3. Extract it.
  4. Run setup.py to install:
    # python setup.py install
    
    
    
  5. Do the following test:
    $ pdf2txt.py samples/simple1.pdf
    
    
    
    
    Hello
    
    World
    
     Hello  World
    
  6. Done!

 

For non-ASCII languages

In order to handle non-ASCII languages (e.g. Japanese), you need to install an additional data called CMap , which is distributed from Adobe.

Here is how:

  1. Get a CMap archive file from http://www.unixuser.org/~euske/pub/CMap.tar.bz2
  2. Expand the archive and put the CMap directory under the directory where pdfminer is installed. (Normally this should be something like /usr/lib/python2.5/site-packages .) For example:
    $ cd /usr/lib/python2.5/site-packages
    
    
    $ tar jxf CMap.tar.bz2
    
    
    
  3. Do the following. (this is optional, but highly recommended)
    $ python -m pdfminer.cmap
    
    
    
    This may take several minutes.


How to Use

PDFMiner comes with two handy tools: pdf2txt.py and dumppdf.py .

pdf2txt.py

pdf2txt.py extracts text contents from a PDF file. It extracts all the texts that are to be rendered programmatically, It cannot recognize texts drawn as images that would require optical character recognition. It also extracts the corresponding locations, font names, font sizes, writing direction (horizontal or vertical) for each text portion. You need to provide a password for protected PDF documents when its access is restricted. You cannot extract any text from a PDF document which does not have extraction permission.

For non-ASCII languages, you can specify the output encoding (such as UTF-8).

Note: Not all characters in a PDF can be safely converted to Unicode.

Examples:

$ pdf2txt.py samples/naacl06-shinyama.pdf -o output.html


(extract text as an HTML file whose filename is output.html)

$ pdf2txt.py -c GBK samples/jo.pdf -o output.html


(extract a Chinese HTML file in vertical writing, CMap is required)

$ pdf2txt.py -P mypassword secret.pdf -o output.txt


(extract a text from an encrypted PDF file)

Options:

-o filename
Specifies the output file name. By default, it prints the extracted contents to stdout in text format.

 

-p pageno[,pageno,...]
Specifies the comma-separated list of the page numbers to be extracted. Page numbers are starting from one. By default, it extracts texts from all the pages.

 

-c codec
Specifies the output codec for non-ASCII texts.

 

-t type
Specifies the output format. The following formats are currently supported.
  • html : HTML format. (Default)
  • text : TEXT format.
  • sgml : SGML format.
  • tag : "Tagged PDF" format. A tagged PDF has its own contents annotated with HTML-like tags. pdf2txt tries to extract its content streams rather than inferring its text locations. Tags used here are defined in the PDF specification (See §10.7 "Tagged PDF ").

 

-M char_margin
-L line_margin
-W word_margin
These are the parameters used for layout analysis. In an actual PDF file, texts might be split into several chunks in the middle of its running, depending on the authoring software. Therefore, text extraction needs to splice text chunks. In the figure below, two text chunks whose distance is closer than the char_margin (shown as M ) is considered continuous and get grouped into one. Also, two lines whose distance is closer than the line_margin (L ) is grouped as a text box, which is a rectangular area that contains a "cluster" of texts. Furthermore, it may be required to insert blank characters (spaces) as necessary if the distance between two words is greater than the word_margin (W ), as a blank between words might not be represented as a space, but indicated by the positioning of each word.

Each value is specified not as an actual length, but as a proportion of the length to the size of each character in question. The default values are M = 1.0, L = 0.3, and W = 0.2, respectively.

M
Q u i c k b r o w n   f o x
W L
j u m p s ...

 

-s scale
Specifies the output scale. Can be used in HTML format only.

 

-m maxpages
Specifies the maximum number of pages to extract. By default, it extracts all the pages in a document.

 

-P password
Provides the user password to access PDF contents.

 

-C CMap directory
Specifies the path of CMap directory. CMap is needed when extracting non-ASCII texts (especially in Asian languages). The CMap location can be also specified with CMAP_PATH environment variable.

 

-d
Increases the debug level.

dumppdf.py

dumppdf.py dumps the internal contents of a PDF file in pseudo-XML format. This program is primarily for debugging purpose, but it's also possible to extract some meaningful contents (such as images).

Examples:

$ dumppdf.py -a foo.pdf


(dump all the headers and contents, except stream objects)

$ dumppdf.py -T foo.pdf


(dump the table of contents)

$ dumppdf.py -r -i6 foo.pdf > pic.jpeg


(extract a JPEG image)

Options:

-a
Instructs to dump all the objects. By default, it only prints the document trailer (like a header).

 

-i objno,objno, ...
Specifies PDF object IDs to display. Comma-separated IDs, or multiple -i options are accepted.

 

-p pageno,pageno, ...
Specifies the page number to be extracted. Comma-separated page numbers, or multiple -p options are accepted. Note that page numbers start from one, not zero.

 

-r (raw)
-b (binary)
-t (text)
Specifies the output format of stream contents. Because the contents of stream objects can be very large, they are omitted when none of the options above is specified.

With -r option, the "raw" stream contents are dumped without decompression. With -b option, the decompressed contents are dumped as a binary blob. With -t option, the decompressed contents are dumped in a text format, similar to repr() manner. When -r or -b option is given, no stream header is displayed for the ease of saving it to a file.

 

-T
Shows the table of contents.

 

-P password
Provides the user password to access PDF contents.

 

-d
Increases the debug level.


Changes

  • 2009/07/11: Improvement in layout analysis. Thanks to Lubos Pintes.
  • 2009/05/17: Bugfixes, massive code restructuring, and simple graphic element support added. setup.py is supported.
  • 2009/03/30: Text output mode added.
  • 2009/03/25: Encoding problems fixed. Word splitting option added.
  • 2009/02/28: Robust handling of corrupted PDFs. Thanks to Troy Bollinger.
  • 2009/02/01: Various bugfixes. Thanks to Hiroshi Manabe.
  • 2009/01/17: Handling a trailer correctly that contains both /XrefStm and /Prev entries.
  • 2009/01/10: Handling Type3 font metrics correctly.
  • 2008/12/28: Better handling of word spacing. Thanks to Christian Nentwich.
  • 2008/09/06: A sample pdf2html webapp added.
  • 2008/08/30: ASCII85 encoding filter support.
  • 2008/07/27: Tagged contents extraction support.
  • 2008/07/10: Outline (TOC) extraction support.
  • 2008/06/29: HTML output added. Reorganized the directory structure.
  • 2008/04/29: Bugfix for Win32. Thanks to Chris Clark.
  • 2008/04/27: Basic encryption and LZW decoding support added.
  • 2008/01/07: Several bugfixes. Thanks to Nick Fabry for his contribution.
  • 2007/12/31: Initial release.
  • 2004/12/24: Start writing the code out of boredom...


Related Projects


Terms and Conditions

Copyright (c) 2004-2009 Yusuke Shinyama <yusuke at cs dot nyu dot edu>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Yusuke Shinyama
分享到:
评论

相关推荐

    pdfminer.six-master.zip

    PDFminer.six是一个强大的Python库,专为处理PDF文档而设计。它允许开发者从PDF文件中提取各种信息,包括文本、图像、元数据等。在Python3环境下,这个库是PDF解析和信息提取的重要工具。"pdfminer.six-master.zip...

    PyPI 官网下载 | pdfminer-20100213.tar.gz

    **PyPI 官网下载 | pdfminer-20100213.tar.gz** PDFMiner 是一个用 Python 编写的 PDF 文档解析库,主要用于提取文本和元数据,以便进行进一步分析或处理。这个资源是 pdfminer 的 20100213 版本,它可以从 Python ...

    pdfminer3k-1.2.4.tar.rar

    PDFminer3k是一个Python库,专门用于从PDF文档中提取结构化信息,如文本、元数据、图像等。这个库的版本是1.2.4,以“pdfminer3k-1.2.4.tar.gz”的形式提供,并且已经打包在了一个rar文件中。这个压缩包还包含了...

    python基于pdfminer库提取pdf文字代码实例

    在本篇文章中,将详细探讨如何利用Python语言借助pdfminer库来提取PDF文件中的文字内容。pdfminer是一个功能强大的库,能够对PDF文件进行深入分析,并从中提取出文本信息。我们将通过具体的代码实例来展示如何使用...

    pdfminer-20191125.tar.gz

    PDFMiner是一个强大的Python库,专门用于从PDF文档中提取各种信息,如文本、元数据、页面布局等。它的核心功能在于将PDF文件解析为结构化的文本,这在自动化办公环境中非常有用,可以帮助用户实现对PDF文档的高效...

    编译好的python3可以使用的pdfminer,可以处理中文,直接setup安装

    PDFMiner是一个强大的Python库,专门用于从PDF文档中提取结构化信息,如文本、元数据、页面布局等。在给定的标题和描述中提到的"编译好的python3可以使用的pdfminer"指的是这个库已经适配了Python 3,并且已经编译...

    PDFMiner3K安装包 tar.gz

    PDFMiner3K安装包 tar.gz PDFMiner3K安装包 tar.gzPDFMiner3K安装包 tar.gzPDFMiner3K安装包 tar.gz PDFMiner3K安装包 tar.gz PDFMiner3K安装包 tar.gz PDFMiner3K安装包 tar.gz PDFMiner3K安装包 tar.gz

    pdfminer3k pdf 解析 python3

    用户在线、本地解析PDF的pdfminer3k官网包。使用方式见本博客:http://blog.csdn.net/y515789/article/details/77446835 --就着注释看代码,是一件美差。

    pdfminer-master.zip

    PDFMiner 是一个 Python 的 PDF 解析器,可以从 PDF 文档中提取信息。与其他 PDF 相关的工具不同,它侧重的是获取和分析文本数据。PDFMiner 允许获取某一页中文本的准确位置和一些诸如字体、行数的信息。它包括一个 ...

    pdfminer-docs

    PDFMiner是一个专门用于从PDF文档中提取信息的工具,与其它的PDF处理工具不同,它主要关注于获取和分析文本数据。使用PDFMiner可以精确地获取页面中文本的位置以及字体和行等信息。PDFMiner包含一个能够将PDF文件...

    pdfminer3-2018.12.3.0.tar

    pdfminer3-2018.12.3.0.tar, pdf

    pdfminer-pdf-txt

    PDFMiner是一个Python库,专门用于提取PDF文档中的文本和元数据。这个工具不仅能够将PDF文件转换为纯文本格式,还可以提供详细的布局信息,如页面大小、段落、链接等。在处理PDF文档时,它能保持原始文本的结构和...

    pdfminer.six:pdfminer的社区维护分支-我们了解PDF

    pdfminer.six 我们了解PDF Pdfminer.six是原始PDFMiner的社区维护的分支。 它是从PDF文档中提取信息的工具。 它着重于获取和分析文本数据。 Pdfminer.six直接从PDF的源代码中提取页面中的文本。 它也可以用来获取...

    Python-PDFMiner一个用于从PDF文档中抽取信息的工具

    PDFMiner是一个强大的Python库,专门设计用于从PDF(Portable Document Format)文档中提取各种信息。这个工具提供了详细的页面布局分析,能够抽取文本、图像、元数据等,并且支持多种输出格式,如文本、XML、HTML等...

    《python数据处理》pdf文件解析模块:pdfminer和pdfplumber

    1. 导入所需的模块:`from pdfminer.pdfparser import PDFParser`, `from pdfminer.pdfdocument import PDFDocument`, `from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter`, `from pdfminer....

    urllib模块和pymysql模块的使用、pdfminer3k读取PDF文档

    安装后,可以使用`pdfminer.converter`、`pdfminer.layout`和`pdfminer.image`等模块来处理PDF。以下是一个简单的例子,展示如何提取PDF文档中的文本: ```python from pdfminer.pdfparser import PDFParser from ...

    【Python源码】PDFMiner:一个用于从 PDF 文档中抽取信息的工具

    PDFMiner:一个用于从 PDF 文档中抽取信息的工具。 【功能】 纯 Python(3.6 或更高版本)。 支持 PDF-1.7。(嗯,差不多) 获取文本的确切位置以及其他布局信息(字体等)。 执行自动布局分析。 可以将 PDF 转换为...

    Python使用PDFMiner解析PDF代码实例

    ### Python使用PDFMiner解析PDF代码实例详解 #### 一、引言 在进行网络爬虫项目时,可能会遇到目标网站仅提供PDF格式文件而非HTML页面的情况。这种情况下,传统的爬虫工具如Scrapy就无法直接抓取内容,需要采用专门...

    python使用pdfminer解析pdf文件的方法示例

    安装PDFMiner非常简单,如果你的Python环境已经配置了pip,只需运行`pip install pdfminer`命令即可完成安装。 在使用PDFMiner解析PDF文件时,有几个核心的类需要了解: 1. **PDFParser**:这是从PDF文件中读取...

    python 使用pdfminer3k 读取PDF文档的例子

    1、安装 pdfminer3k 通过pip安装: pip install pdfminer3k 下载安装:在网页 https://pypi.org/project/pdfminer3k/1.3.1/#files 进行下载,解压。然后cmd命令进入到当前文件夹: 可以直接在资源管理器的路径栏直接...

Global site tag (gtag.js) - Google Analytics