OLD | NEW |
---|---|
(Empty) | |
1 # Getting Started with PDFium | |
2 | |
3 This guide walks through some examples of using the PDFium library. For an | |
4 example of using PDFium see the [Chromium PDF Plugin][chrome-plugin]. | |
5 | |
6 ## Prerequisites | |
7 | |
8 You will need the PDFium library on your computer. You can see the | |
9 [README](/README.md) for instructions on getting and installing PDFium. | |
10 | |
11 *** note | |
12 You must compile PDFium without V8 or XFA support for the examples here to work. | |
Tom Sepez
2016/03/28 20:28:18
nit: without both V8 and XFA support
dsinclair
2016/03/29 01:05:19
Done.
| |
13 See the [V8 Getting Started][pdfium-v8] guide for how to initialize PDFium when | |
14 V8 is compiled into the binary. | |
15 | |
16 V8 can be compiled out by providing `pdf_enable_v8=0 pdf_enable_xfa=0` to | |
Tom Sepez
2016/03/28 20:28:18
nit: move this up to line 13
GYP_DEFINES="pdf_ena
dsinclair
2016/03/29 01:05:18
Done.
| |
17 `build/gyp_pdfium`. | |
18 *** | |
19 | |
20 ## PDFium Headers | |
21 | |
22 PDFium has been broken over several headers. You only need to include the | |
Tom Sepez
2016/03/28 20:28:18
PDFium's API has been broken up over
dsinclair
2016/03/29 01:05:18
Done.
| |
23 headers for functionality you need in your application. The full set of | |
Tom Sepez
2016/03/28 20:28:18
functionality you use in your application.
dsinclair
2016/03/29 01:05:18
Done.
| |
24 headers can be found in the [public/ folder of the repository][pdfium-public]. | |
25 | |
26 In all cases you'll need to include `fpdfview.h` as it defines the needed | |
27 methods for initialization and destruction of the library. | |
28 | |
29 ## Initializing PDFium | |
30 | |
31 The first step to using PDFium is to initialize the library. As well, you'll | |
Tom Sepez
2016/03/28 20:28:18
Having done so, you'll then need to
dsinclair
2016/03/29 01:05:19
Done.
| |
32 need to destroy the library when you're finished. When initializing the | |
33 library you provide the `FPDF_LIBRARY_CONFIG` parameters to | |
34 `FPDF_InitLibraryWithConfig`. | |
35 | |
36 ```c | |
37 #include <fpdfview.h> | |
38 | |
39 int main() { | |
40 FPDF_LIBRARY_CONFIG config; | |
41 config.version = 2; | |
42 config.m_pUserFontPaths = NULL; | |
43 config.m_pIsolate = NULL; | |
44 config.m_v8EmbedderSlot = 0; | |
45 | |
46 FPDF_InitLibraryWithConfig(&config); | |
47 | |
48 FPDF_DestroyLibrary(); | |
49 return 0; | |
50 } | |
51 ``` | |
52 | |
53 Currently the `config.version` must be set to `2`. `m_pUserFontPaths` can be | |
54 used to override the font paths searched by PDFium. If you wish to use your | |
55 own font paths pass a `NULL` terminated list of `const char*` paths to use. | |
56 | |
57 `m_pIsolate` and `m_v8EmbedderSlot` are both used to configure the V8 | |
58 javascript engine. In the first case, you can provide an isolate through | |
59 `m_pIsolate` for PDFium to use to store per-isolate data. Passing `NULL` will | |
60 case PDFium to allocate a new isolate. `m_v8EmbedderSlot` is the embedder data | |
61 slot to use in the v8::Isolate to store PDFium data. The value must be between | |
62 0 and v8::Internals::kNumIsolateDataSlots. Typically, 0 is a good choice. | |
63 | |
64 For more information on using Javascript see the [V8 Getting Started][pdfium-v8] | |
65 guide. | |
66 | |
67 *** aside | |
68 PDFium is built as a set of static libraries. You'll need to specify them all on | |
69 the link line in order to compile. My build line was: | |
70 | |
71 ``` | |
72 PDF_LIBS="-lpdfium -lfpdfapi -lfxge -lfpdfdoc -lfxcrt -lfx_agg \ | |
Tom Sepez
2016/03/28 20:28:18
we really should consolidate our build down into f
dsinclair
2016/03/29 01:05:19
I think we could just do pdfium and pdfium_xfa as
| |
73 -lfxcodec -lfx_lpng -lfx_libopenjpeg -lfx_lcms2 -lfx_freetype -ljpeg \ | |
74 -lfx_zlib -lfdrm -lpdfwindow -lbigint -lformfiller -ljavascript \ | |
75 -lfxedit" | |
76 PDF_DIR=<path/to/pdfium> | |
77 | |
78 clang -I $PDF_DIR/public -o init init.c -L $PDF_DIR/out/Debug -lstdc++ -framewor k AppKit $PDF_LIBS | |
79 ``` | |
80 | |
81 The `-framework AppKit` as needed as I'm building on a Mac. Internally PDFium | |
82 uses C++, which is why `-lstdc++` is required on the link line. | |
83 *** | |
84 | |
85 | |
86 [chrome-plugin]: https://chromium.googlesource.com/chromium/src/+/master/pdf/ | |
87 [pdfium-public]: https://pdfium.googlesource.com/pdfium/+/master/public/ | |
88 [pdfium-v8]: /docs/v8-getting-started.md | |
OLD | NEW |