Compiling Poppler on Windows
Thus, today I will try to guide you on how to make Poppler works on Windows with QT. The goal of this tutorial is to compile the
The things you will need
Ok, let’s begin the journey. Before starting you need to download some libraries
You will need QT, at the time I’m writing the latest version is 4.7.4 (source zip, tar.gz). I will recommend you to download the source because it gave me some problems when I downloaded the binaries. Then you need the freetype, cairo, and zlib. However, those are not that easy to find in Windows. So, you can download them from any site that maintains a build like GTK+ or Inkscape. I got mine from the GTK+ site and used the developer version of them. You can use, however, the version of your choice. And finally the other library we need is openjpeg, and you can download the source code and build it from there.
Now that you have the libraries, you will need the tools to build them. So go and set Visual Studio or a compiler for Windows, and you will also need CMake.
Before getting into Poppler or other libraries, you will need to build QT. I prefer to build it instead of downloading the binaries, because the compiled version didn’t work for me :( . There is a detail instruction set in here. So I will give you the short story.
- First unzip the sources into your hard drive, for here on I will call this path
- Then you need to add the path to the environment variables. Go to My Computer Properties, in the Advanced Tab search for the Environment Variables. Then add to the
PATHvariable the path to the bin folder of your extracted QT files (
- Now open a console from Visual Studio, and then go to the
cd $QT_PATH configure nmake
If you have any problem in this part check the installation page.
Preparing the environment
After you get all the libraries (cairo, freetype, zlib, and openjpeg) you need to unzip them into a folder, I will call it
$TOOLS from here on.
Then, for example, you will have
$TOOLS\cairo-dev_1.10.2-1_win32 if you choose the development version of cairo library. And all the other libraries can be in this folder too. We will use them later when compiling Poppler. In my case I used the dev versions of all the libraries, and in order to make it easier I will refer to them as follows
$CAIRO = $TOOLS\cairo-dev_1.10.2-1_win32
$FREETYPE = $TOOLS\freetype-dev_2.4.2-1_win32
$ZLIB = $TOOLS\zlib-dev_1.2.5-2_win32
$OPENJPEG = $TOOLS\openjpeg_v1_4_sources_r697
Now we will build Openjpeg using CMake. Open CMake GUI and in the source path choose
$OPENJPEG path; for the build binaries you need to create a folder, mine is
$OPENJPEG\build. Then you just need to press
Configure; select your version of Visual Studio and wait for it to end, and then just press it again. It should be no more red rows in the output. If there are, try to solve the problems it mention. After that press
Generate and the project should be in
$OPENJPEG\build or wherever you put it.
ALL_BUILD project and compile it. The binaries will be in
Building Poppler Library
Note: Different target names for Debug and Release.
In case you need to give a postfix to the debug and release libraries, e.g., popplerd.lib for debug and poppler.lib for release, you need to add this line to the CMakeList (after the
set(CMAKE_MODULE_PATH ... )is OK)set(CMAKE_DEBUG_POSTFIX d)
Just change the
dfor the postfix you want to use, maybe
Now that we have all the prerequisites we are ready to build Poppler. Put the sources in a folder, I will call it
$POPPLER, and create a folder for the build like in the openjpeg step, mine it is in
Now open CMake, and point the source-path to
$POPPLER and the build-path to
$POPPLER\build, and press
Configure. Again, select the Visual Studio of your choice and then wait for it to configure. An error message will appear regarding the freetype library, don’t worry we are expecting it. You will see a lot of red rows in the output. Look for
FREETYPE_LIBRARY and point them to:
Configure again and wait. An error will occur again, and we will need to set the cairo and zlib libraries. Look for the next variables and set them accordingly
$OPENJPEG\bulid\bin\Release\openjpeg.lib(this can be Release or Debug depends on you)
Also, you need to change the zlib variables. If you don’t see them, mark the Advance option.
Take special attention to this variables if you have a LaTex related system in you computer because it will look for that binaries. However, if the include libraries are not there Poppler won’t compile.
After you change those variables, you need to disable the options
WITH_GLIB. And then press
Configure again, check for no red rows and then press
Generate. Go to
$POPPLER\build and execute
ALL_BUILD, compile and that should be it for the Poppler library.
Executing the Demo
If you want to execute the demo, and you didn’t add everything to your path you will need some libraries in order to run it. The demo will be located at
Release accordingly to your compiling settings. You will need the following libraries
$QT_PATH\lib(the ‘d’ is needed if you are working with Debug version, if it is Release version loose it)
If you want to port your demo, you will need to add the msvcpX.dll and msvcrX.dll where X is the number of your compiler (also the debug version of those libraries, the ones that includes the ‘d’), you can find those libraries in your system.
I encounter some problems with the demo. The application started, it open the PDFs but no fonts appeared. After struggling a little bit I found that I need the freetype6.dll, I found that library in my installation of Inkscape. However, I’m not sure why the Debug version doesn’t ask for the library. Nevertheless, if you put that library in your Release version the fonts start appearing.
Up to here I was able to build the Poppler library and run the demo inside. I will explore further to see the capabilities of the library and how can I incorporate it into my projects. I hope this help you, so you won’t waste your time trying to do things that, now that I know how to do them, look easy but are not when there is not enough documentation around.
It is hard at the beginning but if you struggle long enough it becomes easier. :mrgreen: