XUtils

PDF-Writer

High performance library for creating, modiyfing and parsing PDF files in C++ [Apache-2.0] [website](https://www.pdfhummus.com/)


Short tour of the project

There are 8 folders to this project:

  • FreeType, LibAesgm, LibJpeg, LibPng, LibTiff, Zlib: 6 libraries that are dependencies to PDFWriter. They are bundled here for convenience. You don’t have to use them to compile PDFWriter, but rather use what versions you have installed on your setup.
  • PDFWriter: main folder, includes the library implementation
  • PDFWriterTesting: test folder, includes test source code that’s used with cmake testing application - ctest.

Building, Installing and testing the project with CMake

Once you installed pre-reqs, you can now build the project.

Create the project files

To build you project start by creating a project file in a “build” folder off of the cmake configuration, like this:

mkdir build
cd build
cmake ..

options for generating Cmake project files

The project defines some optional flags to allow you to control some aspects of building PDFHummus.

  • PDFHUMMUS_NO_DCT - defines whether to exclude DCT functionality (essentially - not include LibJpeg) from the library. defaults to FALSE. when setting TRUE the library will not require the existance of LibJpeg however will not be able to decode DCT streams from PDF files. (note that this has no baring on the ability to include JPEG images. That ability does not require LibJpeg given the innate ability of PDF files to include DCT encoded streams).
  • PDFHUMMUS_NO_TIFF - defines whether to exclude TIFF functionality (essentially - not include LibTiff) from the library. defaults to FALSE. when setting TRUE the library will not require the existance of LibTiff however will not be able to embed TIFF images.
  • PDFHuMMUS_NO_PNG - defines whether to exclude PNG functionality (essentially - not include LibPng) from the library. defaults to FALSE. when setting TRUE the library will not require the existance of LibPng however will not be able to embed PNG images.
  • USE_BUNDLED - defines whether to use bundled dependencies when building the project or use system libraries. defaults to TRUE. when defined as FALSE, the project configuration will look for installed versions of LibJpeg, Zlib, LibTiff, FreeType, LibAesgm, LibPng and use them instead of the bundled ones (i.e. those contained in the project). Note that for optional dependencies - LibJpeg, LibTiff, LibPng - if not installed the coniguration will succeed but will automatically set the optional building flags (the 3 just described) according to the libraries avialability. As for required dependencies - FreeType, LibAesgm, Zlib - the configuration will fail if those dependencies are not found. see USE_UNBUNDLED_FALLBACK_BUNDLED for an alternative method to deal with dependencies not being found.
  • USE_UNBUNDLED_FALLBACK_BUNDLED - Defines an alternative behavior when using USE_BUNDLED=OFF and a certain dependency is not installed on the system. If set to TRUE then for a dependency that’s not found it will fallback on the bundled version of this dependency. This is essentially attempting to find installed library and if not avialable use a bundled one to ensure that the build will succeed.
  • BUILD_FUZZING_HARNESS - Enable a fuzz testing target for PDFParser. This makes it possible to runn fuzz tests and debug potential vulnarbilities. read more about this in here. By default it’s OFF, set it up with ON.

You can set any of those options when calling the cmake command. For example to use system libraries replaced the earlier sequence with:

cd build
cmake .. -DUSE_BUNDLED=FALSE

Build

Once you got the project file, you can now build the project. If you created an IDE file, you can use the IDE file to build the project. Alternatively you can do so from the command line, again using cmake.

The following builds the project from its root folder:

cmake --build build [--config release]

This will build the project inside the build folder. what’s in brackets is optional and will specify a release onfiguration build. You will be able to look up the result library files per how you normally do when building with the relevant build environment. For example, for windows, the build/PDFWriter/Release folder will have the result PDFWriter file.

Installing

If you want, you can use the install verb of cmake to install a built product (the library files and includes). Use the prefix param to specify where you want the result to be installed to

cmake --install build --prefix ./etc/install [--config release]

This will install all the library files in ./etc/install. You should see an “include” folder and a “lib” folder with include files and library files respectively.

Packaging PDFHummus for installing someplace else

The project contains definitions for cpack, cmake packaging mechanism. It might be useful for when you want to build PDFHummus and then install it someplace else.

The following will create a zip file with all libs and includes:

cd build
cpack .

More building instructions for when you cant use cmake

iOS

I wrote a post about how to compile and use the library for the iPhone and iPad environments. you can read it here.


Articles

  • coming soon...