Comments (3)
Yes you can, you have to write your own PDFLayoutAnalyzer
. For example, to print all the bounding boxes of characters use the following:
from collections.abc import Iterable
from pdfminer.converter import PDFLayoutAnalyzer
from pdfminer.layout import LTChar
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.pdfpage import PDFPage
class CustomConverter(PDFLayoutAnalyzer):
def receive_layout(self, ltpage):
stack = [ltpage]
while len(stack) > 0:
item = stack.pop()
if isinstance(item, LTChar):
print('"%s"' % item.get_text(), item.bbox)
if isinstance(item, Iterable):
stack.extend(list(iter(item)))
rsrcmgr = PDFResourceManager()
device = CustomConverter(rsrcmgr)
interpreter = PDFPageInterpreter(rsrcmgr, device)
with open('/users/pieter/downloads/fontsizes.pdf', 'rb') as fin:
for page in PDFPage.get_pages(fin):
interpreter.process_page(page)
device.close()
Note that by using laparams=None
in the PDFLayoutAnalyzer
(the default value) the layout analysis is turned of. You can also overwrite the PDFLayoutAnalyzer.end_page()
method to explicity remove the call to .analyze()
methods.
from pdfminer.six.
It should be pretty easy since pdfminer gives access to all entities in a pdf file. pdf2txt and other tools are just examples of what can be done, but you can do much more by overriding the PDFDevice class to handle bboxes positions, and possibly PDFPageInterpreter if needed
you may have a look at my Drawing.read_pdf method in https://github.com/goulu/Goulib/blob/master/Goulib/drawing.py (from line 1106) where I do something like that to read vector graphics (but not yet texts...)
from pdfminer.six.
I'm closing this because I think this question is answered. Feel free to reopen.
from pdfminer.six.
Related Issues (20)
- Bug: pdfminer.six fails to read certain japanese fonts and returns cid value HOT 3
- Check licenses in cicd
- Switch to pyproject.toml
- I want to take bold text from a .pdf file and i have a code that works perfectly wow but in one kind of pdf it did't work can anyone help me with that HOT 1
- Incorrect character extraction, CID string returned HOT 2
- TypeError: 'int' object is not iterable HOT 1
- Support zipped jpegs
- Detection of ligatures - fi problem
- Unused `rsrcmgr` field on `PDFDevice`
- interpreter.process_page crashes on certain pdfs
- 𝜒 extraction issue
- "PDFDocument is not initialized" when startxref is invalid
- Out-of-order coordinates HOT 4
- pdfminer cause python3 process coredump.... HOT 1
- UnicodeEncodeError when piping/Tee-Object on Windows
- Parse Image on the fly
- Issue with extract_pages Function in pdfminer.six
- DEPRECATION: pdfminer-six -VERSION-
- How to add fonts
- ModuleNotFoundError: No module named 'pdfminer'
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfminer.six.