Using the Library

Working with XpdfPrint

The XpdfPrint library uses an opaque handle (type PDFHandle) 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 XpdfPrint header file:

#include "XpdfPrint.h"
Using XpdfPrint, you can load PDF files and print them. Typical code looks like this:
PDFHandle pdf; char *title; int err, length; err = pdfLoadFile(&pdf, "c:/test/file.pdf"); if (err != pdfOk) { /* handle the error */ } pdfPrintSetPrinter(pdf, L"printer55"); pdfPrint4(pdf);

Using XpdfPrint in a multithreaded application

In a multithreaded application, the pdfInitLibrary 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 XpdfPrint functions (other than pdfInitLibrary) are thread-safe.

Compiling & linking on Windows

The XpdfPrint library is supplied as a DLL (XpdfPrint.dll) and an import library (XpdfPrint.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 (....\XpdfPrint\include).
  2. Add the import library: in the "Project Settings" dialog, under the "Link" tab, in the "General" category, add the library (....\XpdfPrint\lib\XpdfPrint.lib).
  3. Either add the library directory (....\XpdfPrint\lib) to your executable search path, or copy XpdfPrint.dll into the same directory as your application's executable.

Static library

XpdfPrint includes a static library as well as the dynamic library. To use it, include XpdfPrintStatic.h in place of XpdfPrint.h, and link to XpdfPrintStatic.lib.

Example code

The XpdfPrint library distribution includes three sample programs, scanprinters.c, printPDF.c, and printPDF2.c, located in the examples directory. These programs demonstrate the use of the various XpdfPrint functions.

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