Analyse of PDF (or EPS?)

  • Thread starter Johan Holst Nielsen
  • Start date
J

Johan Holst Nielsen

Hi,

Is there any Python packages to analyse or get some information out of
an PDF document...

Like where the text are placed - what text are placed - fonts, embedded
PDFs/fonts/images etc.

Please let me know :)

Regards,
Johan
 
P

Peter Hansen

Johan said:
Is there any Python packages to analyse or get some information out of
an PDF document...

Like where the text are placed - what text are placed - fonts, embedded
PDFs/fonts/images etc.

Please let me know :)

I believe the not-for-free version of ReportLab has this sort of capability,
at least in some sense.

-Peter
 
J

Johan Holst Nielsen

Peter said:
I believe the not-for-free version of ReportLab has this sort of capability,
at least in some sense.

Aah, you think about the product "PageCatcher", right? :)

I haven't seen it yet :) I will contact ReportLab for further details,
thanks :)

Please let me know, if other know any alternatives ;) (in case that I
cannot use ReportLab's version)

Regards,
Johan
 
J

Johan Holst Nielsen

Johan said:
Aah, you think about the product "PageCatcher", right? :)

Just found the pricing :( I think USD 25,000 are way out of my budget :(
I have someone have some alternatives :)

Regards,
Johan
 
B

Bengt Richter

Hi,

Is there any Python packages to analyse or get some information out of
an PDF document...

Like where the text are placed - what text are placed - fonts, embedded
PDFs/fonts/images etc.

Please let me know :)
IIRC you can get the full specs of pdf and eps at the adobe site.
Some stuff is easy to get at, some may be compressed and/or encrypted,
and not so easy.

Conforming docs are supposed to be structured so that it is relatively easy
to grab chunks of document and do the kinds of things printing business s/w does,
like rotating and scaling and reordering pages, etc.

There are whole books on pdf and postscript also, which you could browse at a good
tech book store or tech library.

Regards,
Bengt Richter
 
A

Andrew MacIntyre

Is there any Python packages to analyse or get some information out of
an PDF document...

Like where the text are placed - what text are placed - fonts, embedded
PDFs/fonts/images etc.

I believe that Ghostscript can be used to print PDFs on Postscript
printers; you would then need to find tools to analyse Postscript files.
 
D

David Boddie

It depends on the type of images (bitmap vs. vector).
IIRC you can get the full specs of pdf and eps at the adobe site.

The full PDF specification is not exactly short, but it's fairly readable.
Some stuff is easy to get at, some may be compressed and/or encrypted,
and not so easy.

Although the FlateDecode compression format is straightforward with existing
libraries, some of the other compression techniques may be less accessible.
Conforming docs are supposed to be structured so that it is relatively easy
to grab chunks of document and do the kinds of things printing business s/w does,
like rotating and scaling and reordering pages, etc.

I have a Python library which is able to identify a lot of the structure in simple
documents, including basic text extraction, but I've become pretty disillusioned
with it because so much work is required to extract more complex information.

Maybe it's time to stick a license on it and upload it somewhere.

David
 
G

Grzegorz Makarewicz

Johan said:
Hi,

Is there any Python packages to analyse or get some information out of
an PDF document...

Like where the text are placed - what text are placed - fonts, embedded
PDFs/fonts/images etc.

Please let me know :)

Regards,
Johan

http://www.trisoft.com.pl/~mak/wxpdf.zip

My first attempt to decode PDF-s with SWIG-ged xpdf, requires sources of
python and wxPython - binaries for python22 (windows) are included.

mak
 
J

Johan Holst Nielsen

David said:
It depends on the type of images (bitmap vs. vector).

Yes I know - but the vector based images should be extracted just as it
is - bitmap as selfcontained files :=)
The full PDF specification is not exactly short, but it's fairly readable.

Yep... I tried it... but there are no reason to do exactly the same - if
other people already have done that. And time is an issue too ;)
Although the FlateDecode compression format is straightforward with existing
libraries, some of the other compression techniques may be less accessible.

Well, no problem with the compression/encrypting. It is for an internal
application - so people just HAVE to not encrypt or secure the document.
I have a Python library which is able to identify a lot of the structure in simple
documents, including basic text extraction, but I've become pretty disillusioned
with it because so much work is required to extract more complex information.

Maybe it's time to stick a license on it and upload it somewhere.

Well, let me know ;) Maybe I could get an demo or something? That would
be nice :)

Regards,
Johan
 
D

David Boddie

Johan Holst Nielsen said:
David Boddie wrote:

Yep... I tried it... but there are no reason to do exactly the same - if
other people already have done that. And time is an issue too ;)

Time is always an issue. How much of it do you have? ;-)
Well, let me know ;) Maybe I could get an demo or something? That would
be nice :)

You may be disappointed, but here it is:

http://www.boddie.org.uk/david/Projects/Python/pdftools/

The core of the library was written in a hurry over two years ago; later refinements
make it only slightly more robust. It was never really intended for anything other
than exploring the structure of PDF files.

Basic use:

import pdftools

file = "MyFile.pdf"
doc = pdftools.PDFdocument(file)

print "Document uses PDF format version", doc.document_version()

pages = doc.count_pages()
print "Document contains %i pages." % pages

if pages > 123:

page123 = doc.read_page(123)
contents123 = page123.read_contents()

print "The objects found in this page:"
print
print contents123.contents

I've not really dealt with the coordinate system very well. Ideally, it would be
trivial to extract all the device-independent positioning information but,
whenever I start to look at this, I get distracted. :)

Have fun, and don't expect too much,

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top