Using the Library

Working with XpdfSplice

The XpdfSplice library uses opaque handles to represent input PDF files (type XpdfSpliceInputHandle) and output PDF files (type XpdfSpliceOutputHandle). Multiple input files and multiple output files can be open simultaneously, each with its own handle.

Any program that uses the library must include the XpdfSplice header file:

#include "XpdfSplice.h"
Using XpdfSplice, you can load input PDF files and copy specific pages into output PDF files. Typical code looks like this:
XpdfSpliceInputHandle in1, in2; XpdfSpliceOutputHandle out1, out2; if (!(in1 = xpdfSpliceOpenInput("input1.pdf"))) { // ... handle error ... } if (!(in2 = xpdfSpliceOpenInput("input2.pdf"))) { // ... handle error ... } if (!(out1 = xpdfSpliceOpenOutput("output1.pdf", 1.6))) { // ... handle error ... } if (!(out2 = xpdfSpliceOpenOutput("output2.pdf", 1.6))) { // ... handle error ... } // copy page 1 from both input documents to the first output document xpdfSpliceAddPage(in1, 1, out1); xpdfSpliceAddPage(in2, 1, out1); // copy page 2 from both input documents to the second output document xpdfSpliceAddPage(in1, 2, out2); xpdfSpliceAddPage(in2, 2, out2); xpdfSpliceCloseInput(in1); xpdfSpliceCloseInput(in2); xpdfSpliceCloseOutput(out1); xpdfSpliceCloseOutput(out2);

Using XpdfSplice in a multithreaded application

In a multithreaded application, the xpdfSpliceInit function must be called before any other functions are called. Unlike in single-thread applications where this is optional, the xpdfSpliceInit call is required in multithreaded applications. Each PDF handle (XpdfSpliceInputHandle or XpdfSpliceOutputHandle) must be used by only one thread. Given that constraint, all XpdfSplice functions (other than xpdfSpliceInit) are thread-safe.

Compiling & linking on Windows

The XpdfSplice library is supplied as a DLL (XpdfSplice.dll) and an import library (XpdfSplice.lib).

The following instructions are for Microsoft Visual C++ 6. Similar steps should work for other development environments.

  1. Add the include file directory: in the "Project Settings" dialog, under the "C/C++" tab, in the "Preprocessor" category, add the library include file directory (....\XpdfSplice\include).
  2. Add the import library: in the "Project Settings" dialog, under the "Link" tab, in the "General" category, add the library (....\XpdfSplice\lib\XpdfSplice.lib).
  3. Either add the library directory (....\XpdfSplice\lib) to your executable search path, or copy XpdfSplice.dll into the same directory as your application's executable.

Compiling & linking on Linux

The XpdfSplice library is supplied as a shared library (

When compiling C or C++ code that uses the XpdfSplice library, you'll need to supply a "-I" flag pointing to the directory containing the XpdfSplice includes. When linking, you'll need to supply a "-L" flag pointing to the directory containing the XpdfSplice library, and a "-lXpdfSplice" flag to link with the library.

gcc -c -I/usr/local/XpdfSplice/include application.c gcc -o application application.o \ -L/usr/local/XpdfSplice/lib -lXpdfSplice
Look at the Makefile in the example code for a complete demonstration.

Before running the application, make sure that the XpdfSplice library directory is on the library search path. This this can be done either by setting the LD_LIBRARY_PATH environment variable or by editing the system-wide /etc/ configuration file.

Compiling & linking on Mac OS X

Using XpdfSplice on OS X is very similar to using it on Linux. The shared library has a different extension (libXpdfSplice.dylib), and you'll need to set the DYLD_LIBRARY_PATH environment variable.

Static library

XpdfSplice includes a static library as well as the dynamic library. To use it, include XpdfSpliceStatic.h in place of XpdfSplice.h, and link to XpdfSpliceStatic.lib (Windows) or libXpdfSplice.a (Linux, Mac OS X).

Example code

The XpdfSplice library distribution includes a sample program, pdfmerge.c, located in the examples directory. This programs demonstrate the use of the various XpdfSplice functions.

To build on Linux, edit the included Makefile and set the XPDFLIBDIR, XPDFINCDIR, and LIB variables according to the instructions inside the Makefile. Then run "make".

To build on Windows, create a Visual C++ project, as described above.