Using the Library
Working with XpdfViewerThe XpdfViewer library uses an opaque handle (type
PDFViewerHandle) to represent a viewer object. An application can use multiple XpdfViewer objects (multiple
PDFViewerHandles), each attached to a different window.
Any program that uses the library must include the XpdfViewer header file:
Key bindingsThe XpdfViewer library automatically handles a few simple key bindings (when the viewer's window has the keyboard focus):
- the arrow keys scroll the document (16 pixels per click) in all four directions
- the Page Up key scrolls the document up by one screenful, i.e., the current height of the window, which may be less than a whole PDF page
- the Page Down key and space key both scroll down by one screenful
Using XpdfViewer in a multithreaded applicationIn a multithreaded application, the
pdfInitLibraryfunction must be called before any other functions are called. Unlike in single-thread applications where this is optional, the
pdfInitLibrarycall is required in multithreaded applications. Each PDF viewer handle must be used by only one thread. Given that constraint, all XpdfViewer functions (other than
pdfInitLibrary) are thread-safe.
Compiling & linking on WindowsThe XpdfViewer library is supplied as a DLL (
XpdfViewer.dll) and an import library (
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 (
- Add the import library: in the "Project Settings" dialog, under
the "Link" tab, in the "General" category, add the library
- Either add the library directory (
....\XpdfViewer\lib) to your executable search path, or copy
XpdfViewer.dllinto the same directory as your application's executable.
Static libraryXpdfViewer includes a static library as well as the dynamic library. To use it, include
XpdfViewerStatic.hin place of
XpdfViewer.h, and link to
Example codeThe XpdfViewer library distribution includes two sample programs,
highlight, located in the
examplesdirectory. These programs demonstrate the use of the various XpdfViewer functions. To build them on Windows, follow the instructions above.
viewer program (
attaching an XpdfViewer to a window. It provides a minimal user
interface which can load a PDF file (
test.pdf) in the
current directory, move to the next and previous pages, extract text
from the current selection, and print.
highlight program (
use of XpdfViewer's highlighted region feature. It allows the user to
highlight a set of regions and then extract them all to one text file.