Code Monkey home page Code Monkey logo

Comments (3)

pietermarsman avatar pietermarsman commented on May 22, 2024 1

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.

goulu avatar goulu commented on May 22, 2024

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.

pietermarsman avatar pietermarsman commented on May 22, 2024

I'm closing this because I think this question is answered. Feel free to reopen.

from pdfminer.six.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.