Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting page dimensions from a PDF with a C++ program
    primarykey
    data
    text
    <p>How can I extract the page dimensions from a PDF file with a C++ program ?</p> <p>Is there any lightweight, cross-platform, easy to build/install, library that could help ?</p> <p>Thanks :)</p> <p>[EDIT]</p> <p>I tried to build podofo under windows, but it didn't work. LibHaru and PDFHummus are for rendering pdfs, not parsing their data.</p> <p><strong>[EDIT &amp; SOLUTION]</strong></p> <p>I've finally built podofo under windows!</p> <p>(btw, under Ubuntu, it was just a matter of <code>sudo apt-get install libpodofo0.9.0 libpodofo-dev libpodofo-utils</code> )</p> <p>It was actually a CMake 2.8.10 bug, switching back to 2.8.3 solved the problem ( <a href="http://www.daniweb.com/software-development/cpp/threads/438435/windres.exe-invalid-option-w-" rel="nofollow">thanks</a> )</p> <p>If anyone is interested, here's how to get started with podofo under windows (I'll demonstrate how to build the debug/shared version):</p> <ol> <li>download the required libraries (freetype, jpeg, openssl, tiff, zlib) and install them (I suggest, copying all the files under <code>LIB_NAME\lib</code> in <code>C:\libraries\lib</code> , same thing for <code>\include</code> )</li> <li>install <a href="http://www.cmake.org/files/v2.8/" rel="nofollow">CMake 2.8.3</a></li> <li>add MinGW\bin and CMake\bin to the <code>PATH</code></li> <li>download <a href="http://podofo.sourceforge.net/download.html#podofo" rel="nofollow">podofo</a> and uzip it somewhere, let's say in <code>C:\downloads\podofo-0.9.2</code></li> <li>create a new directory <code>C:\downloads\podofo-0.9.2\podofo-shared-debug</code></li> <li>open the command prompt then type <code>cd C:\downloads\podofo-0.9.2\podofo-shared-debug</code></li> <li><p>run this command to prepare a MinGW makefile for the debug/shared version of podofo</p> <pre><code>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 </code></pre></li> <li><p>then just call make</p> <pre><code>mingw-make.exe </code></pre></li> <li><p>if you're using codeblocks, here's how to install/use podofo:</p></li> </ol> <p>9.1. copy the following</p> <pre><code>podofo-0.9.2\podofo --&gt; C:\libraries\podofo-0.9.2\include\podofo podofo-0.9.2\src --&gt; C:\libraries\podofo-0.9.2\include\src podofo-0.9.2\podofo-shared-debug\podofo_config.h --&gt; C:\libraries\podofo-0.9.2\include\podofo_config.h podofo-0.9.2\podofo-shared-debug\src\libpodofo.dll.a --&gt; C:\libraries\podofo-0.9.2\lib-shared-debug\libpodofo.dll.a podofo-0.9.2\podofo-shared-debug\src\libpodofo.dll --&gt; C:\libraries\podofo-0.9.2\bin-shared-debug\libpodofo.dll </code></pre> <p>9.2. use <code>-lpodofo</code> in the linker options then add <code>C:\libraries\podofo-0.9.2\include</code> to the compiler's search directories and <code>C:\libraries\podofo-0.9.2\lib-shared-debug</code> to the linker's search directories</p> <p>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:</p> <pre><code>#include &lt;iostream&gt; #include &lt;podofo/podofo.h&gt; int main (int argc, char* argv[]) { PoDoFo::PdfMemDocument document; try { document.Load("path/to/the/file.pdf"); } catch (PdfError&amp; e ) { // a password is required to read this pdf return -1; } try { PoDoFo::PdfRect pageSize = document.GetPage(0)-&gt;GetPageSize(); // yes, it's "0-based" std::cout &lt;&lt; "width: " &lt;&lt; pageSize.GetWidth() &lt;&lt; "\t\theight: " &lt;&lt; pageSize.GetHeight() &lt;&lt; std::endl; } catch (PdfError&amp; e ) { // page number error return -2; } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload