Differences between revisions 4 and 5
Revision 4 as of 2023-01-08 05:28:03
Size: 1667
Comment:
Revision 5 as of 2023-04-11 14:34:05
Size: 1680
Comment:
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
The most up-to-date implementation of `pdfminer` is available though `pip(1)` as `pdfminer.six`. The most up-to-date implementation of `pdfminer` is available though [[Python/Pip|pip(1)]] as `pdfminer.six`.

Python Pdfminer

pdfminer is a third-party module for parsing PDF files.


Installation

The most up-to-date implementation of pdfminer is available though pip(1) as pdfminer.six.


Usage

Simple Usage

from pdfminer.high_level import extract_text
with open(filename, "rb") as f:
    text = extract_text(f)

Document Processing

In this case, using HTML as the destination encoding. To use XML instead, replace "html" with "xml".

from io import StringIO
from pdfminer.high_level import extract_text_to_fp
from pdfminer.layout import LAParams

buffer = StringIO()
with open(filename, "rb") as f:
    extract_text_to_fp(f, buffer, laparams=LAParams(), output_type="html", codec=None)
html = buffer.getvalue()

Page-by-page Processing

In this case, using XML as the destination encoding. To use HTML instead, replace XMLConverter with HTMLConverter.

from io import StringIO
from pdfminer.converter import XMLConverter
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.pdfpage import PDFPage
from pdfminer.layout import LAParams

buffer = StringIO()
manager = PDFResourceManager(caching=False)
converter = XMLConverter(manager, buffer, laparams=LAParams(), codec=None)
interpreter = PDFPageInterpreter(manager, converter)
with open(filename, 'rb') as f:
    for page in PDFPage.get_pages(f, pagenos=None, maxpages=0, password=None, caching=False):
        interpreter.process_page(page)
xml = buffer.getvalue()


CategoryRicottone

Python/Pdfminer (last edited 2023-10-12 17:52:53 by DominicRicottone)