Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Analyse of PDF (or EPS?)

47 views
Skip to first unread message

Johan Holst Nielsen

unread,
Nov 20, 2003, 8:48:52 AM11/20/03
to
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

Peter Hansen

unread,
Nov 20, 2003, 9:20:21 AM11/20/03
to

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

-Peter

Johan Holst Nielsen

unread,
Nov 20, 2003, 10:20:44 AM11/20/03
to
Peter Hansen wrote:

> Johan Holst Nielsen wrote:
>
>>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 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

Johan Holst Nielsen

unread,
Nov 20, 2003, 10:24:31 AM11/20/03
to
Johan Holst Nielsen wrote:

> Peter Hansen wrote:
>
>> Johan Holst Nielsen wrote:
>>
>>> 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 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? :)

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

Regards,
Johan

Bengt Richter

unread,
Nov 20, 2003, 2:01:20 PM11/20/03
to

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

David Boddie

unread,
Nov 20, 2003, 9:04:16 PM11/20/03
to
bo...@oz.net (Bengt Richter) wrote in message news:<bpj320$qui$0...@216.39.172.122>...

> On Thu, 20 Nov 2003 14:48:52 +0100, Johan Holst Nielsen <jo...@weknowthewayout.com> wrote:

> >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.

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

Andrew MacIntyre

unread,
Nov 20, 2003, 5:17:00 PM11/20/03
to pytho...@python.org
On Thu, 20 Nov 2003, Johan Holst Nielsen wrote:

> 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.

--
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: and...@bullseye.apana.org.au (pref) | Snail: PO Box 370
and...@pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia

Grzegorz Makarewicz

unread,
Nov 21, 2003, 3:46:54 AM11/21/03
to pytho...@python.org

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


Johan Holst Nielsen

unread,
Nov 21, 2003, 7:07:08 AM11/21/03
to
Grzegorz Makarewicz wrote:

Hmmm
http://www.trisoft.com.pl/~mak/wxpdf.zip
Not Found
The requested URL /~mak/wxpdf.zip was not found on this server.
:( Did I get the wrong URL :(

Regards,
Johan

Johan Holst Nielsen

unread,
Nov 21, 2003, 7:10:41 AM11/21/03
to
David Boddie wrote:
>>>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.
>
> 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 :=)

>
>>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.

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 ;)

>
>>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.

Well, no problem with the compression/encrypting. It is for an internal
application - so people just HAVE to not encrypt or secure the document.

>>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.

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

Regards,
Johan

Johan Holst Nielsen

unread,
Nov 21, 2003, 7:14:35 AM11/21/03
to
Grzegorz Makarewicz wrote:
> Johan Holst Nielsen wrote:
>> 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 :)
>
> 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.

Not Found


The requested URL /~mak/wxpdf.zip was not found on this server.

:( Can you please try to upload it again?

Regards,
Johan

Grzegorz Makarewicz

unread,
Nov 21, 2003, 8:46:26 AM11/21/03
to pytho...@python.org
Johan Holst Nielsen wrote:
[...]

> Not Found
> The requested URL /~mak/wxpdf.zip was not found on this server.
>

> Can you please try to upload it again?
>

> Johan
>

Sorry for the missing link, this one works:

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

Regards,
Grzegorz Makarewicz


Johan Holst Nielsen

unread,
Nov 21, 2003, 10:31:37 AM11/21/03
to
Grzegorz Makarewicz wrote:
> Johan Holst Nielsen wrote:
> [...]
>
> > Not Found
> > The requested URL /~mak/wxpdf.zip was not found on this server.
> >
> > Can you please try to upload it again?
> >
> > Johan
> >
>
> Sorry for the missing link, this one works:
>
> http://www.trisoft.com.pl/mak/wxpdf.zip

Thanks Grzegorz, I will look at it in next week. If you want an reply
about if I can use - please send a message to me at tcr480 ( a t )
yahoo.dk


Regards,
Johan

David Boddie

unread,
Nov 25, 2003, 3:58:13 PM11/25/03
to
Johan Holst Nielsen <jo...@weknowthewayout.com> wrote in message news:<3fbe00e8$0$95070$edfa...@dread11.news.tele.dk>...
> David Boddie wrote:

> > 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 ;)

Time is always an issue. How much of it do you have? ;-)

> > 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 :)

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

0 new messages