Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract TOC of PDF?

Tags:

php

pdf

xpdf

I am extracting a pdf into images / swf and text with the help of SWFTools and XPDF.. I am running these in a PDF script.

But now I am trying to go one step further and try to get the TOC from the PDF is it possible to extract this information?

like image 446
Chris Avatar asked Mar 12 '10 08:03

Chris


People also ask

Can you scrape data from a PDF?

Docparser is a PDF scraper software that allows you to automatically pull data from recurring PDF documents on scale. Like web-scraping (collecting data by crawling the internet), scraping PDF documents is a powerful method to automatically convert semi-structured text documents into structured data.


1 Answers

I found this with a little bit of searching. It looks rather promising.

PDFMiner: http://www.unixuser.org/~euske/python/pdfminer/index.html

Note: The tool is Python based, but you should be able to use the tool via shell access. Alternatively, you may be able to glean some useful info from the source code itself, as the project is open source.

From the Site:

dumppdf.py

dumppdf.py dumps the internal contents of a PDF file in pseudo-XML format. This program is primarily for debugging purposes, but it's also possible to extract some meaningful contents (such as images).

Examples:

$ dumppdf.py -a foo.pdf (dump all the headers and contents, except stream objects)  $ dumppdf.py -T foo.pdf (dump the table of contents)  $ dumppdf.py -r -i6 foo.pdf > pic.jpeg (extract a JPEG image) 
like image 94
Brian Lacy Avatar answered Sep 23 '22 07:09

Brian Lacy