Using the Library
Working with XpdfRasterizer
The XpdfRasterizer library uses an opaque handle (typePDFHandle
) to represent a PDF file. Multiple PDF files
can be open simultaneously (each with its own handle).
Any program that uses the library must include the XpdfRasterizer header file:
Using XpdfRasterizer in a multithreaded application
In a multithreaded application, thepdfInitLibrary
function must
be called before any other functions are called. Unlike in
single-thread applications where this is optional, the
pdfInitLibrary
call is required in multithreaded
applications. Each PDF handle must be used by only one thread. Given
that constraint, all XpdfRasterizer functions (other than
pdfInitLibrary
) are thread-safe.
Compiling & linking on Windows
The XpdfRasterizer library is supplied as a DLL (XpdfRasterizer.dll
) and an import library
(XpdfRasterizer.lib
).
The following instructions are for Microsoft Visual C++ 6. Similar steps should work for other development environments.
- 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 (
....\XpdfRasterizer\include
). - Add the import library: in the "Project Settings" dialog, under
the "Link" tab, in the "General" category, add the library
(
....\XpdfRasterizer\lib\XpdfRasterizer.lib
). - Either add the library directory
(
....\XpdfRasterizer\lib
) to your executable search path, or copyXpdfRasterizer.dll
into the same directory as your application's executable.
Compiling & linking on Linux
The XpdfRasterizer library is supplied as a shared library (libXpdfRasterizer.so
).
When compiling C or C++ code that uses the XpdfRasterizer library,
you'll need to supply a "-I
" flag pointing to the
directory containing the XpdfRasterizer includes. When linking, you'll
need to supply a "-L
" flag pointing to the directory
containing the XpdfRasterizer library, and a
"-lXpdfRasterizer
" flag to link with the library.
Before running the application, make sure that the XpdfRasterizer
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/ld.so.conf
configuration file.
Compiling & linking on Mac OS X
Using XpdfRasterizer on OS X is very similar to using it on Linux. The shared library has a different extension (libXpdfRasterizer.dylib
), and you'll need to set
the DYLD_LIBRARY_PATH
environment variable.
Static library
XpdfRasterizer includes a static library as well as the dynamic library. To use it, includeXpdfRasterizerStatic.h
in
place of XpdfRasterizer.h
, and link
to XpdfRasterizerStatic.lib
(Windows)
or libXpdfRasterizer.a
(Linux, Mac OS X).
Example code
The XpdfRasterizer library distribution includes a sample program,pdftoimg.c
, located in the examples
directory. This program demonstrates the use of the various
XpdfRasterizer functions. It converts a PDF file to a series of image
files, one per page - monochrome/grayscale/color and image file format
can be chosen by uncommenting lines in the source file.
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.