Tuesday 3 February 2015

Building Pdf2HtmlEx for Windows

Pdf2HtmlEx (https://github.com/coolwanglu/pdf2htmlEX) is a great open source project for accurately rendering PDF files into modern, compact HTML. Getting a Windows build of what is really a Linux orientated open source project is a bit of a challenge however.

If you fancy just downloading a binary, then perhaps head over to this site, where you will find some builds. For me, that wasn't going to be sufficient - if this is going to go into a production environment then I need to be able to build a new version if and when we need to fix bugs or update to the latest build. I wanted to build from source.

Fortunately Marc Sanfaçon has done most of the hard work in working out what other packages have to be built and how to build them under mingw. I set out to follow his instructions and along the way I fixed any gremlins I came across and turned them into a bash script that will perform the whole build unattended from start to finish.

Before you start, make sure you have installed :

  • Mingw from here. Leave the defaults (like installing to c:\mingw) alone in the first page of the installer, then select at least 'mingw-developer-tools', 'mingw32-base',  'mingw32-gcc-g++' and 'msys-base' in the package selection.
  • Python from here. Actually, the final built product doesn't depend on Python, but building libfontforge seems to require it. In the end it was easier just to install Python than spend more time hacking at the build system trying to remove the dependency. You also need to add Python to your PATH.
Now, start an MSYS shell (there's a batch file in c:\MinGW\msys\1.0) and you will have a bash shell in your home directory (C:\MinGw\msys\1.0\home\<username>).

Copy the script below into a .sh file and run it. You'll need an active internet connection for source to be downloaded, but other than that all you need do is wait. Once the process is complete, the Pdf2HtmlEx.exe file (and the dll files and data files it depends on) will be in the 'pdf2htmlEx.Install' subdirectory of your home directory.

I would really have liked to make a statically linked version of the executable, but it didn't seem a simple change to make, so that will have to wait for now (or for someone with a deeper knowledge of CMake, configure, etc).

Anyway, the script is here.