1

How can I extract the page dimensions from a PDF file with a C++ program ?

Is there any lightweight, cross-platform, easy to build/install, library that could help ?

Thanks :)

[EDIT]

I tried to build podofo under windows, but it didn't work. LibHaru and PDFHummus are for rendering pdfs, not parsing their data.

[EDIT & SOLUTION]

I've finally built podofo under windows!

(btw, under Ubuntu, it was just a matter of sudo apt-get install libpodofo0.9.0 libpodofo-dev libpodofo-utils )

It was actually a CMake 2.8.10 bug, switching back to 2.8.3 solved the problem ( thanks )

If anyone is interested, here's how to get started with podofo under windows (I'll demonstrate how to build the debug/shared version):

  1. download the required libraries (freetype, jpeg, openssl, tiff, zlib) and install them (I suggest, copying all the files under LIB_NAME\lib in C:\libraries\lib , same thing for \include )
  2. install CMake 2.8.3
  3. add MinGW\bin and CMake\bin to the PATH
  4. download podofo and uzip it somewhere, let's say in C:\downloads\podofo-0.9.2
  5. create a new directory C:\downloads\podofo-0.9.2\podofo-shared-debug
  6. open the command prompt then type cd C:\downloads\podofo-0.9.2\podofo-shared-debug
  7. run this command to prepare a MinGW makefile for the debug/shared version of podofo

    cmake -G "MinGW Makefiles" .. -DCMAKE_INCLUDE_PATH=C:\libraries\include -DCMAKE_LIBRARY_PATH=C:\libraries\lib -DPODOFO_BUILD_SHARED:BOOL=TRUE -DCMAKE_BUILD_TYPE=DEBUG
    
  8. then just call make

    mingw-make.exe
    
  9. if you're using codeblocks, here's how to install/use podofo:

9.1. copy the following

podofo-0.9.2\podofo --> C:\libraries\podofo-0.9.2\include\podofo
podofo-0.9.2\src --> C:\libraries\podofo-0.9.2\include\src
podofo-0.9.2\podofo-shared-debug\podofo_config.h --> C:\libraries\podofo-0.9.2\include\podofo_config.h

podofo-0.9.2\podofo-shared-debug\src\libpodofo.dll.a --> C:\libraries\podofo-0.9.2\lib-shared-debug\libpodofo.dll.a

podofo-0.9.2\podofo-shared-debug\src\libpodofo.dll --> C:\libraries\podofo-0.9.2\bin-shared-debug\libpodofo.dll

9.2. use -lpodofo in the linker options then add C:\libraries\podofo-0.9.2\include to the compiler's search directories and C:\libraries\podofo-0.9.2\lib-shared-debug to the linker's search directories

Getting back to my initial question, the closest answer to "how to extract the page dimensions from a PDF file with a C++ program (using podofo) ?" is this:

#include <iostream>
#include <podofo/podofo.h>

int main (int argc, char* argv[])
{
    PoDoFo::PdfMemDocument document;
    try
    {
        document.Load("path/to/the/file.pdf");
    }
    catch (PdfError& e )
    {
        // a password is required to read this pdf
        return -1;
    }


    try
    {
        PoDoFo::PdfRect pageSize = document.GetPage(0)->GetPageSize();  // yes, it's "0-based"
        std::cout << "width: " << pageSize.GetWidth() << "\t\theight: " << pageSize.GetHeight() << std::endl;
    }
    catch (PdfError& e )
    {
        // page number error
        return -2;
    }

    return 0;
}
Qamar Suleiman
  • 1,228
  • 2
  • 18
  • 31
maddouri
  • 3,737
  • 5
  • 29
  • 51
  • I tried PoDoFo. I spent the last few hours trying to build it under windows, and it simply won't :( I downloaded all the necessary libs (freetype, jpeg, openssl, tiff, zlib). I used cmake-gui to generate the build files for codeblocks. When I tried to build podofo_static there were some build errors... :/ – maddouri May 08 '13 at 20:09
  • Did you build all the libs yourself? If you post a question about that I might be able to help. – Jesse Good May 08 '13 at 20:15
  • I downloaded the dev files (I have the /include and /lib of each library) – maddouri May 08 '13 at 20:19

0 Answers0