PDF File Parsing - Page Setup Retrieval (and Manipulation)

I was wondering if anyone knows of a method using VB.Net that means that a large library (1000's of PDF files) of PDF files can be opened and parsed prgrammatically to extract the current Page Settings (primarily the Paper/Page Size) ??

We have a large number of files that have been generated out of CAD software and sometimes they have been reformatted to A4 paper size, and sometimes not (sometimes printing to paper 65" square!!). When these latter files are sent to the printer (an HP Printer in this case) the printer does not cope at all well with the paper-size and just errors the job and blocks the print queue.

What I would like to do is to programmatically run through the entire library and extract the page size and generate an excel spreadsheet (this last bit is easy once I have the details from the PDF!) that gives the document name and the page size setting.

Ideally I would like to be able to manipulate the page size to be A4 also, but this last step is not critical.

Any help/suggestions would be appreciated.

Steve MarshallIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Robberbaron (robr)Commented:
I have used PDFSharp library to create and join PDF's.


when you open a PDFDocument, get Page 0 (most of your cad output is likely single page), then you can return the [age size and check it against an enumeration or just the known pages sizes A0-A3, B1-B3

most examples are C# but does work in VB as well.
'Open the file
Dim inputDocument as PdfDocument = PdfReader.Open(filename, PdfDocumentOpenMode.ReadOnly);
dim  page as PdfPage = inputDocument.Pages(0)
dim ht as integer = page.Height
dim wdth as integer = page.Width 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve MarshallIT ManagerAuthor Commented:
Thanks Robberbaron. I will give this a try and report back.

Steve MarshallIT ManagerAuthor Commented:
This has solved the initial dilemma. I have now generated a CSV of all PDF files that have one or other dimension (caters with page orientation as well) that exceeds A4. JUst need to work out the next step now, and PDFSharp may wee be able to deal with this as well.

Only issue is the popup message about a non-parseable Acrobat 6 iRef .... whatever that is!

Robberbaron (robr)Commented:
see http://forum.pdfsharp.net/viewtopic.php?f=2&t=693  for a known issue & a workaround...

i borrowed a method that uses a different PDF class (iTextSharp) to create bypass method in c#.
you need to find the old open-source version of iTextSharp.

check the bottom of the thread.
Steve MarshallIT ManagerAuthor Commented:
Thanks Robberbaron. Will look into this. My ultimate aim is to have a function available within my application that pre-checks any PDF before printing to ensure that the page settings are suitable and to then auto-scale if necessary before printing.

Thanks again,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.