Skip to content
This repository has been archived by the owner on Aug 2, 2019. It is now read-only.

Building PDFium

Pieter van Ginkel edited this page Sep 28, 2016 · 5 revisions

Google changed their build system (again?), so new instructions.

The Pdfium project has instructions on how to get a build system up and running. These are located on https://pdfium.googlesource.com/pdfium/. To start, follow these steps until you get to gn args option. To build Pdfium as a DLL for PdfiumViewer, we need to use a specific configuration. These instructions expect the repo folder to be at C:\Projects\Pdfium\repo with a sub direction pdfium for the Pdfium source. If you use a different folder, paths in the PdfiumWrapper project will need to be updated.

These instructions describe how to get an x64 and x86 build. This requires a 64-bit machine to complete.

First, we start with a x64 build; the default. Follow the instructions referenced above and run gn args ., and enter the following configuration:

pdf_is_standalone = true
is_component_build = false
is_official_build = true
is_debug = false

This will update the Ninja scripts and will generate a few thousand error messages. Ignore those.

The file public\fpdfview.h needs to be changed. The reason for this is that the Ninja compilation is done with the FPDFSDK_EXPORTS define unset, but we need exports. To fix this, in the header file go to the line #define STDCALL (i.e. the one after the #else for when FPDFSDK_EXPORTS is defined) and change it to:

#define STDCALL __stdcall

This will ensure that name mangling is correct after the DLL is generated that does have the exports.

After the scripts have been generated, a build can be started. To get the correct dependencies, easiest is to build pdfium_test:

ninja pdfium_test

After this build completes, open the PdfiumWrapper project that's part of the PdfiumViewer source code and build the release x64 version. This will generate a pdfium.dll file.

To get the x86 version, follow the steps above, but instead enter the following arguments when running gn args .:

pdf_is_standalone = true
is_component_build = false
is_official_build = true
is_debug = false
target_cpu = "x86"

Then, build the release x86 version of the PdfiumWrapper projct.

The PdfiumWrapper project

The PdfiumWrapper project is there to fix a few issues:

  • We need some code made part of the DLL. These code is used by the .NET library to correctly initialize Pdfium;
  • The Pdfium repository does not contain a build script to build a DLL. The PdfiumWrapper project however does build a DLL.

The PdfiumWrapper, besides being configured to build a DLL, has a number of references into the Pdfium repository. These were obtained from the pdfium_test.ninja file in obj\samples in the Pdfium repository directory. Specifically:

  • The include_dirs parameter is used to define the include directories. These are translated to absolute paths;
  • The build ... link parameter is used to define the linked libraries. All of them except for the ones that pertain to testing are included using absolute paths;
  • The libs parameter is also used to define linked libraries.

Note that the pdfium_test.ninja script differs for x64 and x86 builds.

This setup is quite fragile. Whenever a new source file is added, so a new .obj is generated, the PdfiumWrapper project will have to be updated. So, before you do a compilation, make sure you update the paths as described above.

Clone this wiki locally