• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The PDFium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 // This is the main header file for embedders of PDFium. It provides APIs to
8 // initialize the library, load documents, and render pages, amongst other
9 // things.
10 //
11 // NOTE: None of the PDFium APIs are thread-safe. They expect to be called
12 // from a single thread. Barring that, embedders are required to ensure (via
13 // a mutex or similar) that only a single PDFium call can be made at a time.
14 //
15 // NOTE: External docs refer to this file as "fpdfview.h", so do not rename
16 // despite lack of consistency with other public files.
17 
18 #ifndef PUBLIC_FPDFVIEW_H_
19 #define PUBLIC_FPDFVIEW_H_
20 
21 // clang-format off
22 
23 #include <stddef.h>
24 
25 #if defined(_WIN32) && !defined(__WINDOWS__)
26 #include <windows.h>
27 #endif
28 
29 #ifdef PDF_ENABLE_XFA
30 // PDF_USE_XFA is set in confirmation that this version of PDFium can support
31 // XFA forms as requested by the PDF_ENABLE_XFA setting.
32 #define PDF_USE_XFA
33 #endif  // PDF_ENABLE_XFA
34 
35 // PDF object types
36 #define FPDF_OBJECT_UNKNOWN 0
37 #define FPDF_OBJECT_BOOLEAN 1
38 #define FPDF_OBJECT_NUMBER 2
39 #define FPDF_OBJECT_STRING 3
40 #define FPDF_OBJECT_NAME 4
41 #define FPDF_OBJECT_ARRAY 5
42 #define FPDF_OBJECT_DICTIONARY 6
43 #define FPDF_OBJECT_STREAM 7
44 #define FPDF_OBJECT_NULLOBJ 8
45 #define FPDF_OBJECT_REFERENCE 9
46 
47 // PDF text rendering modes
48 typedef enum {
49   FPDF_TEXTRENDERMODE_UNKNOWN = -1,
50   FPDF_TEXTRENDERMODE_FILL = 0,
51   FPDF_TEXTRENDERMODE_STROKE = 1,
52   FPDF_TEXTRENDERMODE_FILL_STROKE = 2,
53   FPDF_TEXTRENDERMODE_INVISIBLE = 3,
54   FPDF_TEXTRENDERMODE_FILL_CLIP = 4,
55   FPDF_TEXTRENDERMODE_STROKE_CLIP = 5,
56   FPDF_TEXTRENDERMODE_FILL_STROKE_CLIP = 6,
57   FPDF_TEXTRENDERMODE_CLIP = 7,
58   FPDF_TEXTRENDERMODE_LAST = FPDF_TEXTRENDERMODE_CLIP,
59 } FPDF_TEXT_RENDERMODE;
60 
61 // PDF types - use incomplete types (never completed) to force API type safety.
62 typedef struct fpdf_action_t__* FPDF_ACTION;
63 typedef struct fpdf_annotation_t__* FPDF_ANNOTATION;
64 typedef struct fpdf_attachment_t__* FPDF_ATTACHMENT;
65 typedef struct fpdf_avail_t__* FPDF_AVAIL;
66 typedef struct fpdf_bitmap_t__* FPDF_BITMAP;
67 typedef struct fpdf_bookmark_t__* FPDF_BOOKMARK;
68 typedef struct fpdf_clippath_t__* FPDF_CLIPPATH;
69 typedef struct fpdf_dest_t__* FPDF_DEST;
70 typedef struct fpdf_document_t__* FPDF_DOCUMENT;
71 typedef struct fpdf_font_t__* FPDF_FONT;
72 typedef struct fpdf_form_handle_t__* FPDF_FORMHANDLE;
73 typedef const struct fpdf_glyphpath_t__* FPDF_GLYPHPATH;
74 typedef struct fpdf_javascript_action_t* FPDF_JAVASCRIPT_ACTION;
75 typedef struct fpdf_link_t__* FPDF_LINK;
76 typedef struct fpdf_page_t__* FPDF_PAGE;
77 typedef struct fpdf_pagelink_t__* FPDF_PAGELINK;
78 typedef struct fpdf_pageobject_t__* FPDF_PAGEOBJECT;  // (text, path, etc.)
79 typedef struct fpdf_pageobjectmark_t__* FPDF_PAGEOBJECTMARK;
80 typedef const struct fpdf_pagerange_t__* FPDF_PAGERANGE;
81 typedef const struct fpdf_pathsegment_t* FPDF_PATHSEGMENT;
82 typedef struct fpdf_schhandle_t__* FPDF_SCHHANDLE;
83 typedef const struct fpdf_signature_t__* FPDF_SIGNATURE;
84 typedef void* FPDF_SKIA_CANVAS;  // Passed into Skia as an SkCanvas.
85 typedef struct fpdf_structelement_t__* FPDF_STRUCTELEMENT;
86 typedef const struct fpdf_structelement_attr_t__* FPDF_STRUCTELEMENT_ATTR;
87 typedef const struct fpdf_structelement_attr_value_t__*
88 FPDF_STRUCTELEMENT_ATTR_VALUE;
89 typedef struct fpdf_structtree_t__* FPDF_STRUCTTREE;
90 typedef struct fpdf_textpage_t__* FPDF_TEXTPAGE;
91 typedef struct fpdf_widget_t__* FPDF_WIDGET;
92 typedef struct fpdf_xobject_t__* FPDF_XOBJECT;
93 
94 // Basic data types
95 typedef int FPDF_BOOL;
96 typedef int FPDF_RESULT;
97 typedef unsigned long FPDF_DWORD;
98 typedef float FS_FLOAT;
99 
100 // Duplex types
101 typedef enum _FPDF_DUPLEXTYPE_ {
102   DuplexUndefined = 0,
103   Simplex,
104   DuplexFlipShortEdge,
105   DuplexFlipLongEdge
106 } FPDF_DUPLEXTYPE;
107 
108 // String types
109 typedef unsigned short FPDF_WCHAR;
110 
111 // The public PDFium API uses three types of strings: byte string, wide string
112 // (UTF-16LE encoded), and platform dependent string.
113 
114 // Public PDFium API type for byte strings.
115 typedef const char* FPDF_BYTESTRING;
116 
117 // The public PDFium API always uses UTF-16LE encoded wide strings, each
118 // character uses 2 bytes (except surrogation), with the low byte first.
119 typedef const FPDF_WCHAR* FPDF_WIDESTRING;
120 
121 // Structure for persisting a string beyond the duration of a callback.
122 // Note: although represented as a char*, string may be interpreted as
123 // a UTF-16LE formated string. Used only by XFA callbacks.
124 typedef struct FPDF_BSTR_ {
125   char* str;  // String buffer, manipulate only with FPDF_BStr_* methods.
126   int len;    // Length of the string, in bytes.
127 } FPDF_BSTR;
128 
129 // For Windows programmers: In most cases it's OK to treat FPDF_WIDESTRING as a
130 // Windows unicode string, however, special care needs to be taken if you
131 // expect to process Unicode larger than 0xffff.
132 //
133 // For Linux/Unix programmers: most compiler/library environments use 4 bytes
134 // for a Unicode character, and you have to convert between FPDF_WIDESTRING and
135 // system wide string by yourself.
136 typedef const char* FPDF_STRING;
137 
138 // Matrix for transformation, in the form [a b c d e f], equivalent to:
139 // | a  b  0 |
140 // | c  d  0 |
141 // | e  f  1 |
142 //
143 // Translation is performed with [1 0 0 1 tx ty].
144 // Scaling is performed with [sx 0 0 sy 0 0].
145 // See PDF Reference 1.7, 4.2.2 Common Transformations for more.
146 typedef struct _FS_MATRIX_ {
147   float a;
148   float b;
149   float c;
150   float d;
151   float e;
152   float f;
153 } FS_MATRIX;
154 
155 // Rectangle area(float) in device or page coordinate system.
156 typedef struct _FS_RECTF_ {
157   // The x-coordinate of the left-top corner.
158   float left;
159   // The y-coordinate of the left-top corner.
160   float top;
161   // The x-coordinate of the right-bottom corner.
162   float right;
163   // The y-coordinate of the right-bottom corner.
164   float bottom;
165 } * FS_LPRECTF, FS_RECTF;
166 
167 // Const Pointer to FS_RECTF structure.
168 typedef const FS_RECTF* FS_LPCRECTF;
169 
170 // Rectangle size. Coordinate system agnostic.
171 typedef struct FS_SIZEF_ {
172   float width;
173   float height;
174 } * FS_LPSIZEF, FS_SIZEF;
175 
176 // Const Pointer to FS_SIZEF structure.
177 typedef const FS_SIZEF* FS_LPCSIZEF;
178 
179 // 2D Point. Coordinate system agnostic.
180 typedef struct FS_POINTF_ {
181   float x;
182   float y;
183 } * FS_LPPOINTF, FS_POINTF;
184 
185 // Const Pointer to FS_POINTF structure.
186 typedef const FS_POINTF* FS_LPCPOINTF;
187 
188 typedef struct _FS_QUADPOINTSF {
189   FS_FLOAT x1;
190   FS_FLOAT y1;
191   FS_FLOAT x2;
192   FS_FLOAT y2;
193   FS_FLOAT x3;
194   FS_FLOAT y3;
195   FS_FLOAT x4;
196   FS_FLOAT y4;
197 } FS_QUADPOINTSF;
198 
199 // Annotation enums.
200 typedef int FPDF_ANNOTATION_SUBTYPE;
201 typedef int FPDF_ANNOT_APPEARANCEMODE;
202 
203 // Dictionary value types.
204 typedef int FPDF_OBJECT_TYPE;
205 
206 #if defined(COMPONENT_BUILD)
207 // FPDF_EXPORT should be consistent with |export| in the pdfium_fuzzer
208 // template in testing/fuzzers/BUILD.gn.
209 #if defined(WIN32)
210 #if defined(FPDF_IMPLEMENTATION)
211 #define FPDF_EXPORT __declspec(dllexport)
212 #else
213 #define FPDF_EXPORT __declspec(dllimport)
214 #endif  // defined(FPDF_IMPLEMENTATION)
215 #else
216 #if defined(FPDF_IMPLEMENTATION)
217 #define FPDF_EXPORT __attribute__((visibility("default")))
218 #else
219 #define FPDF_EXPORT
220 #endif  // defined(FPDF_IMPLEMENTATION)
221 #endif  // defined(WIN32)
222 #else
223 #define FPDF_EXPORT
224 #endif  // defined(COMPONENT_BUILD)
225 
226 #if defined(WIN32) && defined(FPDFSDK_EXPORTS)
227 #define FPDF_CALLCONV __stdcall
228 #else
229 #define FPDF_CALLCONV
230 #endif
231 
232 // Exported Functions
233 #ifdef __cplusplus
234 extern "C" {
235 #endif
236 
237 // PDF renderer types - Experimental.
238 // Selection of 2D graphics library to use for rendering to FPDF_BITMAPs.
239 typedef enum {
240   // Anti-Grain Geometry - https://sourceforge.net/projects/agg/
241   FPDF_RENDERERTYPE_AGG = 0,
242   // Skia - https://skia.org/
243   FPDF_RENDERERTYPE_SKIA = 1,
244 } FPDF_RENDERER_TYPE;
245 
246 // Process-wide options for initializing the library.
247 typedef struct FPDF_LIBRARY_CONFIG_ {
248   // Version number of the interface. Currently must be 2.
249   // Support for version 1 will be deprecated in the future.
250   int version;
251 
252   // Array of paths to scan in place of the defaults when using built-in
253   // FXGE font loading code. The array is terminated by a NULL pointer.
254   // The Array may be NULL itself to use the default paths. May be ignored
255   // entirely depending upon the platform.
256   const char** m_pUserFontPaths;
257 
258   // Version 2.
259 
260   // Pointer to the v8::Isolate to use, or NULL to force PDFium to create one.
261   void* m_pIsolate;
262 
263   // The embedder data slot to use in the v8::Isolate to store PDFium's
264   // per-isolate data. The value needs to be in the range
265   // [0, |v8::Internals::kNumIsolateDataLots|). Note that 0 is fine for most
266   // embedders.
267   unsigned int m_v8EmbedderSlot;
268 
269   // Version 3 - Experimental.
270 
271   // Pointer to the V8::Platform to use.
272   void* m_pPlatform;
273 
274   // Version 4 - Experimental.
275 
276   // Explicit specification of core renderer to use. |m_RendererType| must be
277   // a valid value for |FPDF_LIBRARY_CONFIG| versions of this level or higher,
278   // or else the initialization will fail with an immediate crash.
279   // Note that use of a specified |FPDF_RENDERER_TYPE| value for which the
280   // corresponding render library is not included in the build will similarly
281   // fail with an immediate crash.
282   FPDF_RENDERER_TYPE m_RendererType;
283 } FPDF_LIBRARY_CONFIG;
284 
285 // Function: FPDF_InitLibraryWithConfig
286 //          Initialize the PDFium library and allocate global resources for it.
287 // Parameters:
288 //          config - configuration information as above.
289 // Return value:
290 //          None.
291 // Comments:
292 //          You have to call this function before you can call any PDF
293 //          processing functions.
294 FPDF_EXPORT void FPDF_CALLCONV
295 FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* config);
296 
297 // Function: FPDF_InitLibrary
298 //          Initialize the PDFium library (alternative form).
299 // Parameters:
300 //          None
301 // Return value:
302 //          None.
303 // Comments:
304 //          Convenience function to call FPDF_InitLibraryWithConfig() with a
305 //          default configuration for backwards compatibility purposes. New
306 //          code should call FPDF_InitLibraryWithConfig() instead. This will
307 //          be deprecated in the future.
308 FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibrary();
309 
310 // Function: FPDF_DestroyLibrary
311 //          Release global resources allocated to the PDFium library by
312 //          FPDF_InitLibrary() or FPDF_InitLibraryWithConfig().
313 // Parameters:
314 //          None.
315 // Return value:
316 //          None.
317 // Comments:
318 //          After this function is called, you must not call any PDF
319 //          processing functions.
320 //
321 //          Calling this function does not automatically close other
322 //          objects. It is recommended to close other objects before
323 //          closing the library with this function.
324 FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary();
325 
326 // Policy for accessing the local machine time.
327 #define FPDF_POLICY_MACHINETIME_ACCESS 0
328 
329 // Function: FPDF_SetSandBoxPolicy
330 //          Set the policy for the sandbox environment.
331 // Parameters:
332 //          policy -   The specified policy for setting, for example:
333 //                     FPDF_POLICY_MACHINETIME_ACCESS.
334 //          enable -   True to enable, false to disable the policy.
335 // Return value:
336 //          None.
337 FPDF_EXPORT void FPDF_CALLCONV FPDF_SetSandBoxPolicy(FPDF_DWORD policy,
338                                                      FPDF_BOOL enable);
339 
340 #if defined(_WIN32)
341 // Experimental API.
342 // Function: FPDF_SetPrintMode
343 //          Set printing mode when printing on Windows.
344 // Parameters:
345 //          mode - FPDF_PRINTMODE_EMF to output EMF (default)
346 //                 FPDF_PRINTMODE_TEXTONLY to output text only (for charstream
347 //                 devices)
348 //                 FPDF_PRINTMODE_POSTSCRIPT2 to output level 2 PostScript into
349 //                 EMF as a series of GDI comments.
350 //                 FPDF_PRINTMODE_POSTSCRIPT3 to output level 3 PostScript into
351 //                 EMF as a series of GDI comments.
352 //                 FPDF_PRINTMODE_POSTSCRIPT2_PASSTHROUGH to output level 2
353 //                 PostScript via ExtEscape() in PASSTHROUGH mode.
354 //                 FPDF_PRINTMODE_POSTSCRIPT3_PASSTHROUGH to output level 3
355 //                 PostScript via ExtEscape() in PASSTHROUGH mode.
356 //                 FPDF_PRINTMODE_EMF_IMAGE_MASKS to output EMF, with more
357 //                 efficient processing of documents containing image masks.
358 //                 FPDF_PRINTMODE_POSTSCRIPT3_TYPE42 to output level 3
359 //                 PostScript with embedded Type 42 fonts, when applicable, into
360 //                 EMF as a series of GDI comments.
361 //                 FPDF_PRINTMODE_POSTSCRIPT3_TYPE42_PASSTHROUGH to output level
362 //                 3 PostScript with embedded Type 42 fonts, when applicable,
363 //                 via ExtEscape() in PASSTHROUGH mode.
364 // Return value:
365 //          True if successful, false if unsuccessful (typically invalid input).
366 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_SetPrintMode(int mode);
367 #endif  // defined(_WIN32)
368 
369 // Function: FPDF_LoadDocument
370 //          Open and load a PDF document.
371 // Parameters:
372 //          file_path -  Path to the PDF file (including extension).
373 //          password  -  A string used as the password for the PDF file.
374 //                       If no password is needed, empty or NULL can be used.
375 //                       See comments below regarding the encoding.
376 // Return value:
377 //          A handle to the loaded document, or NULL on failure.
378 // Comments:
379 //          Loaded document can be closed by FPDF_CloseDocument().
380 //          If this function fails, you can use FPDF_GetLastError() to retrieve
381 //          the reason why it failed.
382 //
383 //          The encoding for |file_path| is UTF-8.
384 //
385 //          The encoding for |password| can be either UTF-8 or Latin-1. PDFs,
386 //          depending on the security handler revision, will only accept one or
387 //          the other encoding. If |password|'s encoding and the PDF's expected
388 //          encoding do not match, FPDF_LoadDocument() will automatically
389 //          convert |password| to the other encoding.
390 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
391 FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password);
392 
393 // Function: FPDF_LoadMemDocument
394 //          Open and load a PDF document from memory.
395 // Parameters:
396 //          data_buf    -   Pointer to a buffer containing the PDF document.
397 //          size        -   Number of bytes in the PDF document.
398 //          password    -   A string used as the password for the PDF file.
399 //                          If no password is needed, empty or NULL can be used.
400 // Return value:
401 //          A handle to the loaded document, or NULL on failure.
402 // Comments:
403 //          The memory buffer must remain valid when the document is open.
404 //          The loaded document can be closed by FPDF_CloseDocument.
405 //          If this function fails, you can use FPDF_GetLastError() to retrieve
406 //          the reason why it failed.
407 //
408 //          See the comments for FPDF_LoadDocument() regarding the encoding for
409 //          |password|.
410 // Notes:
411 //          If PDFium is built with the XFA module, the application should call
412 //          FPDF_LoadXFA() function after the PDF document loaded to support XFA
413 //          fields defined in the fpdfformfill.h file.
414 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
415 FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password);
416 
417 // Experimental API.
418 // Function: FPDF_LoadMemDocument64
419 //          Open and load a PDF document from memory.
420 // Parameters:
421 //          data_buf    -   Pointer to a buffer containing the PDF document.
422 //          size        -   Number of bytes in the PDF document.
423 //          password    -   A string used as the password for the PDF file.
424 //                          If no password is needed, empty or NULL can be used.
425 // Return value:
426 //          A handle to the loaded document, or NULL on failure.
427 // Comments:
428 //          The memory buffer must remain valid when the document is open.
429 //          The loaded document can be closed by FPDF_CloseDocument.
430 //          If this function fails, you can use FPDF_GetLastError() to retrieve
431 //          the reason why it failed.
432 //
433 //          See the comments for FPDF_LoadDocument() regarding the encoding for
434 //          |password|.
435 // Notes:
436 //          If PDFium is built with the XFA module, the application should call
437 //          FPDF_LoadXFA() function after the PDF document loaded to support XFA
438 //          fields defined in the fpdfformfill.h file.
439 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
440 FPDF_LoadMemDocument64(const void* data_buf,
441                        size_t size,
442                        FPDF_BYTESTRING password);
443 
444 // Structure for custom file access.
445 typedef struct {
446   // File length, in bytes.
447   unsigned long m_FileLen;
448 
449   // A function pointer for getting a block of data from a specific position.
450   // Position is specified by byte offset from the beginning of the file.
451   // The pointer to the buffer is never NULL and the size is never 0.
452   // The position and size will never go out of range of the file length.
453   // It may be possible for PDFium to call this function multiple times for
454   // the same position.
455   // Return value: should be non-zero if successful, zero for error.
456   int (*m_GetBlock)(void* param,
457                     unsigned long position,
458                     unsigned char* pBuf,
459                     unsigned long size);
460 
461   // A custom pointer for all implementation specific data.  This pointer will
462   // be used as the first parameter to the m_GetBlock callback.
463   void* m_Param;
464 } FPDF_FILEACCESS;
465 
466 // Structure for file reading or writing (I/O).
467 //
468 // Note: This is a handler and should be implemented by callers,
469 // and is only used from XFA.
470 typedef struct FPDF_FILEHANDLER_ {
471   // User-defined data.
472   // Note: Callers can use this field to track controls.
473   void* clientData;
474 
475   // Callback function to release the current file stream object.
476   //
477   // Parameters:
478   //       clientData   -  Pointer to user-defined data.
479   // Returns:
480   //       None.
481   void (*Release)(void* clientData);
482 
483   // Callback function to retrieve the current file stream size.
484   //
485   // Parameters:
486   //       clientData   -  Pointer to user-defined data.
487   // Returns:
488   //       Size of file stream.
489   FPDF_DWORD (*GetSize)(void* clientData);
490 
491   // Callback function to read data from the current file stream.
492   //
493   // Parameters:
494   //       clientData   -  Pointer to user-defined data.
495   //       offset       -  Offset position starts from the beginning of file
496   //                       stream. This parameter indicates reading position.
497   //       buffer       -  Memory buffer to store data which are read from
498   //                       file stream. This parameter should not be NULL.
499   //       size         -  Size of data which should be read from file stream,
500   //                       in bytes. The buffer indicated by |buffer| must be
501   //                       large enough to store specified data.
502   // Returns:
503   //       0 for success, other value for failure.
504   FPDF_RESULT (*ReadBlock)(void* clientData,
505                            FPDF_DWORD offset,
506                            void* buffer,
507                            FPDF_DWORD size);
508 
509   // Callback function to write data into the current file stream.
510   //
511   // Parameters:
512   //       clientData   -  Pointer to user-defined data.
513   //       offset       -  Offset position starts from the beginning of file
514   //                       stream. This parameter indicates writing position.
515   //       buffer       -  Memory buffer contains data which is written into
516   //                       file stream. This parameter should not be NULL.
517   //       size         -  Size of data which should be written into file
518   //                       stream, in bytes.
519   // Returns:
520   //       0 for success, other value for failure.
521   FPDF_RESULT (*WriteBlock)(void* clientData,
522                             FPDF_DWORD offset,
523                             const void* buffer,
524                             FPDF_DWORD size);
525   // Callback function to flush all internal accessing buffers.
526   //
527   // Parameters:
528   //       clientData   -  Pointer to user-defined data.
529   // Returns:
530   //       0 for success, other value for failure.
531   FPDF_RESULT (*Flush)(void* clientData);
532 
533   // Callback function to change file size.
534   //
535   // Description:
536   //       This function is called under writing mode usually. Implementer
537   //       can determine whether to realize it based on application requests.
538   // Parameters:
539   //       clientData   -  Pointer to user-defined data.
540   //       size         -  New size of file stream, in bytes.
541   // Returns:
542   //       0 for success, other value for failure.
543   FPDF_RESULT (*Truncate)(void* clientData, FPDF_DWORD size);
544 } FPDF_FILEHANDLER;
545 
546 // Function: FPDF_LoadCustomDocument
547 //          Load PDF document from a custom access descriptor.
548 // Parameters:
549 //          pFileAccess -   A structure for accessing the file.
550 //          password    -   Optional password for decrypting the PDF file.
551 // Return value:
552 //          A handle to the loaded document, or NULL on failure.
553 // Comments:
554 //          The application must keep the file resources |pFileAccess| points to
555 //          valid until the returned FPDF_DOCUMENT is closed. |pFileAccess|
556 //          itself does not need to outlive the FPDF_DOCUMENT.
557 //
558 //          The loaded document can be closed with FPDF_CloseDocument().
559 //
560 //          See the comments for FPDF_LoadDocument() regarding the encoding for
561 //          |password|.
562 // Notes:
563 //          If PDFium is built with the XFA module, the application should call
564 //          FPDF_LoadXFA() function after the PDF document loaded to support XFA
565 //          fields defined in the fpdfformfill.h file.
566 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
567 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password);
568 
569 // Function: FPDF_GetFileVersion
570 //          Get the file version of the given PDF document.
571 // Parameters:
572 //          doc         -   Handle to a document.
573 //          fileVersion -   The PDF file version. File version: 14 for 1.4, 15
574 //                          for 1.5, ...
575 // Return value:
576 //          True if succeeds, false otherwise.
577 // Comments:
578 //          If the document was created by FPDF_CreateNewDocument,
579 //          then this function will always fail.
580 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetFileVersion(FPDF_DOCUMENT doc,
581                                                         int* fileVersion);
582 
583 #define FPDF_ERR_SUCCESS 0    // No error.
584 #define FPDF_ERR_UNKNOWN 1    // Unknown error.
585 #define FPDF_ERR_FILE 2       // File not found or could not be opened.
586 #define FPDF_ERR_FORMAT 3     // File not in PDF format or corrupted.
587 #define FPDF_ERR_PASSWORD 4   // Password required or incorrect password.
588 #define FPDF_ERR_SECURITY 5   // Unsupported security scheme.
589 #define FPDF_ERR_PAGE 6       // Page not found or content error.
590 #ifdef PDF_ENABLE_XFA
591 #define FPDF_ERR_XFALOAD 7    // Load XFA error.
592 #define FPDF_ERR_XFALAYOUT 8  // Layout XFA error.
593 #endif  // PDF_ENABLE_XFA
594 
595 // Function: FPDF_GetLastError
596 //          Get last error code when a function fails.
597 // Parameters:
598 //          None.
599 // Return value:
600 //          A 32-bit integer indicating error code as defined above.
601 // Comments:
602 //          If the previous SDK call succeeded, the return value of this
603 //          function is not defined. This function only works in conjunction
604 //          with APIs that mention FPDF_GetLastError() in their documentation.
605 FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetLastError();
606 
607 // Experimental API.
608 // Function: FPDF_DocumentHasValidCrossReferenceTable
609 //          Whether the document's cross reference table is valid or not.
610 // Parameters:
611 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
612 // Return value:
613 //          True if the PDF parser did not encounter problems parsing the cross
614 //          reference table. False if the parser could not parse the cross
615 //          reference table and the table had to be rebuild from other data
616 //          within the document.
617 // Comments:
618 //          The return value can change over time as the PDF parser evolves.
619 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
620 FPDF_DocumentHasValidCrossReferenceTable(FPDF_DOCUMENT document);
621 
622 // Experimental API.
623 // Function: FPDF_GetTrailerEnds
624 //          Get the byte offsets of trailer ends.
625 // Parameters:
626 //          document    -   Handle to document. Returned by FPDF_LoadDocument().
627 //          buffer      -   The address of a buffer that receives the
628 //                          byte offsets.
629 //          length      -   The size, in ints, of |buffer|.
630 // Return value:
631 //          Returns the number of ints in the buffer on success, 0 on error.
632 //
633 // |buffer| is an array of integers that describes the exact byte offsets of the
634 // trailer ends in the document. If |length| is less than the returned length,
635 // or |document| or |buffer| is NULL, |buffer| will not be modified.
636 FPDF_EXPORT unsigned long FPDF_CALLCONV
637 FPDF_GetTrailerEnds(FPDF_DOCUMENT document,
638                     unsigned int* buffer,
639                     unsigned long length);
640 
641 // Function: FPDF_GetDocPermissions
642 //          Get file permission flags of the document.
643 // Parameters:
644 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
645 // Return value:
646 //          A 32-bit integer indicating permission flags. Please refer to the
647 //          PDF Reference for detailed descriptions. If the document is not
648 //          protected or was unlocked by the owner, 0xffffffff will be returned.
649 FPDF_EXPORT unsigned long FPDF_CALLCONV
650 FPDF_GetDocPermissions(FPDF_DOCUMENT document);
651 
652 // Function: FPDF_GetDocUserPermissions
653 //          Get user file permission flags of the document.
654 // Parameters:
655 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
656 // Return value:
657 //          A 32-bit integer indicating permission flags. Please refer to the
658 //          PDF Reference for detailed descriptions. If the document is not
659 //          protected, 0xffffffff will be returned. Always returns user
660 //          permissions, even if the document was unlocked by the owner.
661 FPDF_EXPORT unsigned long FPDF_CALLCONV
662 FPDF_GetDocUserPermissions(FPDF_DOCUMENT document);
663 
664 // Function: FPDF_GetSecurityHandlerRevision
665 //          Get the revision for the security handler.
666 // Parameters:
667 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
668 // Return value:
669 //          The security handler revision number. Please refer to the PDF
670 //          Reference for a detailed description. If the document is not
671 //          protected, -1 will be returned.
672 FPDF_EXPORT int FPDF_CALLCONV
673 FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document);
674 
675 // Function: FPDF_GetPageCount
676 //          Get total number of pages in the document.
677 // Parameters:
678 //          document    -   Handle to document. Returned by FPDF_LoadDocument.
679 // Return value:
680 //          Total number of pages in the document.
681 FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageCount(FPDF_DOCUMENT document);
682 
683 // Function: FPDF_LoadPage
684 //          Load a page inside the document.
685 // Parameters:
686 //          document    -   Handle to document. Returned by FPDF_LoadDocument
687 //          page_index  -   Index number of the page. 0 for the first page.
688 // Return value:
689 //          A handle to the loaded page, or NULL if page load fails.
690 // Comments:
691 //          The loaded page can be rendered to devices using FPDF_RenderPage.
692 //          The loaded page can be closed using FPDF_ClosePage.
693 FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document,
694                                                   int page_index);
695 
696 // Experimental API
697 // Function: FPDF_GetPageWidthF
698 //          Get page width.
699 // Parameters:
700 //          page        -   Handle to the page. Returned by FPDF_LoadPage().
701 // Return value:
702 //          Page width (excluding non-displayable area) measured in points.
703 //          One point is 1/72 inch (around 0.3528 mm).
704 FPDF_EXPORT float FPDF_CALLCONV FPDF_GetPageWidthF(FPDF_PAGE page);
705 
706 // Function: FPDF_GetPageWidth
707 //          Get page width.
708 // Parameters:
709 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
710 // Return value:
711 //          Page width (excluding non-displayable area) measured in points.
712 //          One point is 1/72 inch (around 0.3528 mm).
713 // Note:
714 //          Prefer FPDF_GetPageWidthF() above. This will be deprecated in the
715 //          future.
716 FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageWidth(FPDF_PAGE page);
717 
718 // Experimental API
719 // Function: FPDF_GetPageHeightF
720 //          Get page height.
721 // Parameters:
722 //          page        -   Handle to the page. Returned by FPDF_LoadPage().
723 // Return value:
724 //          Page height (excluding non-displayable area) measured in points.
725 //          One point is 1/72 inch (around 0.3528 mm)
726 FPDF_EXPORT float FPDF_CALLCONV FPDF_GetPageHeightF(FPDF_PAGE page);
727 
728 // Function: FPDF_GetPageHeight
729 //          Get page height.
730 // Parameters:
731 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
732 // Return value:
733 //          Page height (excluding non-displayable area) measured in points.
734 //          One point is 1/72 inch (around 0.3528 mm)
735 // Note:
736 //          Prefer FPDF_GetPageHeightF() above. This will be deprecated in the
737 //          future.
738 FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageHeight(FPDF_PAGE page);
739 
740 // Experimental API.
741 // Function: FPDF_GetPageBoundingBox
742 //          Get the bounding box of the page. This is the intersection between
743 //          its media box and its crop box.
744 // Parameters:
745 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
746 //          rect        -   Pointer to a rect to receive the page bounding box.
747 //                          On an error, |rect| won't be filled.
748 // Return value:
749 //          True for success.
750 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageBoundingBox(FPDF_PAGE page,
751                                                             FS_RECTF* rect);
752 
753 // Experimental API.
754 // Function: FPDF_GetPageSizeByIndexF
755 //          Get the size of the page at the given index.
756 // Parameters:
757 //          document    -   Handle to document. Returned by FPDF_LoadDocument().
758 //          page_index  -   Page index, zero for the first page.
759 //          size        -   Pointer to a FS_SIZEF to receive the page size.
760 //                          (in points).
761 // Return value:
762 //          Non-zero for success. 0 for error (document or page not found).
763 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
764 FPDF_GetPageSizeByIndexF(FPDF_DOCUMENT document,
765                          int page_index,
766                          FS_SIZEF* size);
767 
768 // Function: FPDF_GetPageSizeByIndex
769 //          Get the size of the page at the given index.
770 // Parameters:
771 //          document    -   Handle to document. Returned by FPDF_LoadDocument.
772 //          page_index  -   Page index, zero for the first page.
773 //          width       -   Pointer to a double to receive the page width
774 //                          (in points).
775 //          height      -   Pointer to a double to receive the page height
776 //                          (in points).
777 // Return value:
778 //          Non-zero for success. 0 for error (document or page not found).
779 // Note:
780 //          Prefer FPDF_GetPageSizeByIndexF() above. This will be deprecated in
781 //          the future.
782 FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
783                                                       int page_index,
784                                                       double* width,
785                                                       double* height);
786 
787 // Page rendering flags. They can be combined with bit-wise OR.
788 //
789 // Set if annotations are to be rendered.
790 #define FPDF_ANNOT 0x01
791 // Set if using text rendering optimized for LCD display. This flag will only
792 // take effect if anti-aliasing is enabled for text.
793 #define FPDF_LCD_TEXT 0x02
794 // Don't use the native text output available on some platforms
795 #define FPDF_NO_NATIVETEXT 0x04
796 // Grayscale output.
797 #define FPDF_GRAYSCALE 0x08
798 // Obsolete, has no effect, retained for compatibility.
799 #define FPDF_DEBUG_INFO 0x80
800 // Obsolete, has no effect, retained for compatibility.
801 #define FPDF_NO_CATCH 0x100
802 // Limit image cache size.
803 #define FPDF_RENDER_LIMITEDIMAGECACHE 0x200
804 // Always use halftone for image stretching.
805 #define FPDF_RENDER_FORCEHALFTONE 0x400
806 // Render for printing.
807 #define FPDF_PRINTING 0x800
808 // Set to disable anti-aliasing on text. This flag will also disable LCD
809 // optimization for text rendering.
810 #define FPDF_RENDER_NO_SMOOTHTEXT 0x1000
811 // Set to disable anti-aliasing on images.
812 #define FPDF_RENDER_NO_SMOOTHIMAGE 0x2000
813 // Set to disable anti-aliasing on paths.
814 #define FPDF_RENDER_NO_SMOOTHPATH 0x4000
815 // Set whether to render in a reverse Byte order, this flag is only used when
816 // rendering to a bitmap.
817 #define FPDF_REVERSE_BYTE_ORDER 0x10
818 // Set whether fill paths need to be stroked. This flag is only used when
819 // FPDF_COLORSCHEME is passed in, since with a single fill color for paths the
820 // boundaries of adjacent fill paths are less visible.
821 #define FPDF_CONVERT_FILL_TO_STROKE 0x20
822 
823 // Struct for color scheme.
824 // Each should be a 32-bit value specifying the color, in 8888 ARGB format.
825 typedef struct FPDF_COLORSCHEME_ {
826   FPDF_DWORD path_fill_color;
827   FPDF_DWORD path_stroke_color;
828   FPDF_DWORD text_fill_color;
829   FPDF_DWORD text_stroke_color;
830 } FPDF_COLORSCHEME;
831 
832 #ifdef _WIN32
833 // Function: FPDF_RenderPage
834 //          Render contents of a page to a device (screen, bitmap, or printer).
835 //          This function is only supported on Windows.
836 // Parameters:
837 //          dc          -   Handle to the device context.
838 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
839 //          start_x     -   Left pixel position of the display area in
840 //                          device coordinates.
841 //          start_y     -   Top pixel position of the display area in device
842 //                          coordinates.
843 //          size_x      -   Horizontal size (in pixels) for displaying the page.
844 //          size_y      -   Vertical size (in pixels) for displaying the page.
845 //          rotate      -   Page orientation:
846 //                            0 (normal)
847 //                            1 (rotated 90 degrees clockwise)
848 //                            2 (rotated 180 degrees)
849 //                            3 (rotated 90 degrees counter-clockwise)
850 //          flags       -   0 for normal display, or combination of flags
851 //                          defined above.
852 // Return value:
853 //          Returns true if the page is rendered successfully, false otherwise.
854 
855 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_RenderPage(HDC dc,
856                                                FPDF_PAGE page,
857                                                int start_x,
858                                                int start_y,
859                                                int size_x,
860                                                int size_y,
861                                                int rotate,
862                                                int flags);
863 #endif
864 
865 // Function: FPDF_RenderPageBitmap
866 //          Render contents of a page to a device independent bitmap.
867 // Parameters:
868 //          bitmap      -   Handle to the device independent bitmap (as the
869 //                          output buffer). The bitmap handle can be created
870 //                          by FPDFBitmap_Create or retrieved from an image
871 //                          object by FPDFImageObj_GetBitmap.
872 //          page        -   Handle to the page. Returned by FPDF_LoadPage
873 //          start_x     -   Left pixel position of the display area in
874 //                          bitmap coordinates.
875 //          start_y     -   Top pixel position of the display area in bitmap
876 //                          coordinates.
877 //          size_x      -   Horizontal size (in pixels) for displaying the page.
878 //          size_y      -   Vertical size (in pixels) for displaying the page.
879 //          rotate      -   Page orientation:
880 //                            0 (normal)
881 //                            1 (rotated 90 degrees clockwise)
882 //                            2 (rotated 180 degrees)
883 //                            3 (rotated 90 degrees counter-clockwise)
884 //          flags       -   0 for normal display, or combination of the Page
885 //                          Rendering flags defined above. With the FPDF_ANNOT
886 //                          flag, it renders all annotations that do not require
887 //                          user-interaction, which are all annotations except
888 //                          widget and popup annotations.
889 // Return value:
890 //          None.
891 FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
892                                                      FPDF_PAGE page,
893                                                      int start_x,
894                                                      int start_y,
895                                                      int size_x,
896                                                      int size_y,
897                                                      int rotate,
898                                                      int flags);
899 
900 // Function: FPDF_RenderPageBitmapWithMatrix
901 //          Render contents of a page to a device independent bitmap.
902 // Parameters:
903 //          bitmap      -   Handle to the device independent bitmap (as the
904 //                          output buffer). The bitmap handle can be created
905 //                          by FPDFBitmap_Create or retrieved by
906 //                          FPDFImageObj_GetBitmap.
907 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
908 //          matrix      -   The transform matrix, which must be invertible.
909 //                          See PDF Reference 1.7, 4.2.2 Common Transformations.
910 //          clipping    -   The rect to clip to in device coords.
911 //          flags       -   0 for normal display, or combination of the Page
912 //                          Rendering flags defined above. With the FPDF_ANNOT
913 //                          flag, it renders all annotations that do not require
914 //                          user-interaction, which are all annotations except
915 //                          widget and popup annotations.
916 // Return value:
917 //          None. Note that behavior is undefined if det of |matrix| is 0.
918 FPDF_EXPORT void FPDF_CALLCONV
919 FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
920                                 FPDF_PAGE page,
921                                 const FS_MATRIX* matrix,
922                                 const FS_RECTF* clipping,
923                                 int flags);
924 
925 #if defined(PDF_USE_SKIA)
926 // Experimental API.
927 // Function: FPDF_RenderPageSkia
928 //          Render contents of a page to a Skia SkCanvas.
929 // Parameters:
930 //          canvas      -   SkCanvas to render to.
931 //          page        -   Handle to the page.
932 //          size_x      -   Horizontal size (in pixels) for displaying the page.
933 //          size_y      -   Vertical size (in pixels) for displaying the page.
934 // Return value:
935 //          None.
936 FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageSkia(FPDF_SKIA_CANVAS canvas,
937                                                    FPDF_PAGE page,
938                                                    int size_x,
939                                                    int size_y);
940 #endif
941 
942 // Function: FPDF_ClosePage
943 //          Close a loaded PDF page.
944 // Parameters:
945 //          page        -   Handle to the loaded page.
946 // Return value:
947 //          None.
948 FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page);
949 
950 // Function: FPDF_CloseDocument
951 //          Close a loaded PDF document.
952 // Parameters:
953 //          document    -   Handle to the loaded document.
954 // Return value:
955 //          None.
956 FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document);
957 
958 // Function: FPDF_DeviceToPage
959 //          Convert the screen coordinates of a point to page coordinates.
960 // Parameters:
961 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
962 //          start_x     -   Left pixel position of the display area in
963 //                          device coordinates.
964 //          start_y     -   Top pixel position of the display area in device
965 //                          coordinates.
966 //          size_x      -   Horizontal size (in pixels) for displaying the page.
967 //          size_y      -   Vertical size (in pixels) for displaying the page.
968 //          rotate      -   Page orientation:
969 //                            0 (normal)
970 //                            1 (rotated 90 degrees clockwise)
971 //                            2 (rotated 180 degrees)
972 //                            3 (rotated 90 degrees counter-clockwise)
973 //          device_x    -   X value in device coordinates to be converted.
974 //          device_y    -   Y value in device coordinates to be converted.
975 //          page_x      -   A pointer to a double receiving the converted X
976 //                          value in page coordinates.
977 //          page_y      -   A pointer to a double receiving the converted Y
978 //                          value in page coordinates.
979 // Return value:
980 //          Returns true if the conversion succeeds, and |page_x| and |page_y|
981 //          successfully receives the converted coordinates.
982 // Comments:
983 //          The page coordinate system has its origin at the left-bottom corner
984 //          of the page, with the X-axis on the bottom going to the right, and
985 //          the Y-axis on the left side going up.
986 //
987 //          NOTE: this coordinate system can be altered when you zoom, scroll,
988 //          or rotate a page, however, a point on the page should always have
989 //          the same coordinate values in the page coordinate system.
990 //
991 //          The device coordinate system is device dependent. For screen device,
992 //          its origin is at the left-top corner of the window. However this
993 //          origin can be altered by the Windows coordinate transformation
994 //          utilities.
995 //
996 //          You must make sure the start_x, start_y, size_x, size_y
997 //          and rotate parameters have exactly same values as you used in
998 //          the FPDF_RenderPage() function call.
999 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page,
1000                                                       int start_x,
1001                                                       int start_y,
1002                                                       int size_x,
1003                                                       int size_y,
1004                                                       int rotate,
1005                                                       int device_x,
1006                                                       int device_y,
1007                                                       double* page_x,
1008                                                       double* page_y);
1009 
1010 // Function: FPDF_PageToDevice
1011 //          Convert the page coordinates of a point to screen coordinates.
1012 // Parameters:
1013 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
1014 //          start_x     -   Left pixel position of the display area in
1015 //                          device coordinates.
1016 //          start_y     -   Top pixel position of the display area in device
1017 //                          coordinates.
1018 //          size_x      -   Horizontal size (in pixels) for displaying the page.
1019 //          size_y      -   Vertical size (in pixels) for displaying the page.
1020 //          rotate      -   Page orientation:
1021 //                            0 (normal)
1022 //                            1 (rotated 90 degrees clockwise)
1023 //                            2 (rotated 180 degrees)
1024 //                            3 (rotated 90 degrees counter-clockwise)
1025 //          page_x      -   X value in page coordinates.
1026 //          page_y      -   Y value in page coordinate.
1027 //          device_x    -   A pointer to an integer receiving the result X
1028 //                          value in device coordinates.
1029 //          device_y    -   A pointer to an integer receiving the result Y
1030 //                          value in device coordinates.
1031 // Return value:
1032 //          Returns true if the conversion succeeds, and |device_x| and
1033 //          |device_y| successfully receives the converted coordinates.
1034 // Comments:
1035 //          See comments for FPDF_DeviceToPage().
1036 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page,
1037                                                       int start_x,
1038                                                       int start_y,
1039                                                       int size_x,
1040                                                       int size_y,
1041                                                       int rotate,
1042                                                       double page_x,
1043                                                       double page_y,
1044                                                       int* device_x,
1045                                                       int* device_y);
1046 
1047 // Function: FPDFBitmap_Create
1048 //          Create a device independent bitmap (FXDIB).
1049 // Parameters:
1050 //          width       -   The number of pixels in width for the bitmap.
1051 //                          Must be greater than 0.
1052 //          height      -   The number of pixels in height for the bitmap.
1053 //                          Must be greater than 0.
1054 //          alpha       -   A flag indicating whether the alpha channel is used.
1055 //                          Non-zero for using alpha, zero for not using.
1056 // Return value:
1057 //          The created bitmap handle, or NULL if a parameter error or out of
1058 //          memory.
1059 // Comments:
1060 //          The bitmap always uses 4 bytes per pixel. The first byte is always
1061 //          double word aligned.
1062 //
1063 //          The byte order is BGRx (the last byte unused if no alpha channel) or
1064 //          BGRA.
1065 //
1066 //          The pixels in a horizontal line are stored side by side, with the
1067 //          left most pixel stored first (with lower memory address).
1068 //          Each line uses width * 4 bytes.
1069 //
1070 //          Lines are stored one after another, with the top most line stored
1071 //          first. There is no gap between adjacent lines.
1072 //
1073 //          This function allocates enough memory for holding all pixels in the
1074 //          bitmap, but it doesn't initialize the buffer. Applications can use
1075 //          FPDFBitmap_FillRect() to fill the bitmap using any color. If the OS
1076 //          allows it, this function can allocate up to 4 GB of memory.
1077 FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width,
1078                                                         int height,
1079                                                         int alpha);
1080 
1081 // More DIB formats
1082 // Unknown or unsupported format.
1083 #define FPDFBitmap_Unknown 0
1084 // Gray scale bitmap, one byte per pixel.
1085 #define FPDFBitmap_Gray 1
1086 // 3 bytes per pixel, byte order: blue, green, red.
1087 #define FPDFBitmap_BGR 2
1088 // 4 bytes per pixel, byte order: blue, green, red, unused.
1089 #define FPDFBitmap_BGRx 3
1090 // 4 bytes per pixel, byte order: blue, green, red, alpha.
1091 #define FPDFBitmap_BGRA 4
1092 
1093 // Function: FPDFBitmap_CreateEx
1094 //          Create a device independent bitmap (FXDIB)
1095 // Parameters:
1096 //          width       -   The number of pixels in width for the bitmap.
1097 //                          Must be greater than 0.
1098 //          height      -   The number of pixels in height for the bitmap.
1099 //                          Must be greater than 0.
1100 //          format      -   A number indicating for bitmap format, as defined
1101 //                          above.
1102 //          first_scan  -   A pointer to the first byte of the first line if
1103 //                          using an external buffer. If this parameter is NULL,
1104 //                          then a new buffer will be created.
1105 //          stride      -   Number of bytes for each scan line. The value must
1106 //                          be 0 or greater. When the value is 0,
1107 //                          FPDFBitmap_CreateEx() will automatically calculate
1108 //                          the appropriate value using |width| and |format|.
1109 //                          When using an external buffer, it is recommended for
1110 //                          the caller to pass in the value.
1111 //                          When not using an external buffer, it is recommended
1112 //                          for the caller to pass in 0.
1113 // Return value:
1114 //          The bitmap handle, or NULL if parameter error or out of memory.
1115 // Comments:
1116 //          Similar to FPDFBitmap_Create function, but allows for more formats
1117 //          and an external buffer is supported. The bitmap created by this
1118 //          function can be used in any place that a FPDF_BITMAP handle is
1119 //          required.
1120 //
1121 //          If an external buffer is used, then the caller should destroy the
1122 //          buffer. FPDFBitmap_Destroy() will not destroy the buffer.
1123 //
1124 //          It is recommended to use FPDFBitmap_GetStride() to get the stride
1125 //          value.
1126 FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width,
1127                                                           int height,
1128                                                           int format,
1129                                                           void* first_scan,
1130                                                           int stride);
1131 
1132 // Function: FPDFBitmap_GetFormat
1133 //          Get the format of the bitmap.
1134 // Parameters:
1135 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
1136 //                          or FPDFImageObj_GetBitmap.
1137 // Return value:
1138 //          The format of the bitmap.
1139 // Comments:
1140 //          Only formats supported by FPDFBitmap_CreateEx are supported by this
1141 //          function; see the list of such formats above.
1142 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap);
1143 
1144 // Function: FPDFBitmap_FillRect
1145 //          Fill a rectangle in a bitmap.
1146 // Parameters:
1147 //          bitmap      -   The handle to the bitmap. Returned by
1148 //                          FPDFBitmap_Create.
1149 //          left        -   The left position. Starting from 0 at the
1150 //                          left-most pixel.
1151 //          top         -   The top position. Starting from 0 at the
1152 //                          top-most line.
1153 //          width       -   Width in pixels to be filled.
1154 //          height      -   Height in pixels to be filled.
1155 //          color       -   A 32-bit value specifing the color, in 8888 ARGB
1156 //                          format.
1157 // Return value:
1158 //          Returns whether the operation succeeded or not.
1159 // Comments:
1160 //          This function sets the color and (optionally) alpha value in the
1161 //          specified region of the bitmap.
1162 //
1163 //          NOTE: If the alpha channel is used, this function does NOT
1164 //          composite the background with the source color, instead the
1165 //          background will be replaced by the source color and the alpha.
1166 //
1167 //          If the alpha channel is not used, the alpha parameter is ignored.
1168 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
1169                                                         int left,
1170                                                         int top,
1171                                                         int width,
1172                                                         int height,
1173                                                         FPDF_DWORD color);
1174 
1175 // Function: FPDFBitmap_GetBuffer
1176 //          Get data buffer of a bitmap.
1177 // Parameters:
1178 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
1179 //                          or FPDFImageObj_GetBitmap.
1180 // Return value:
1181 //          The pointer to the first byte of the bitmap buffer.
1182 // Comments:
1183 //          The stride may be more than width * number of bytes per pixel
1184 //
1185 //          Applications can use this function to get the bitmap buffer pointer,
1186 //          then manipulate any color and/or alpha values for any pixels in the
1187 //          bitmap.
1188 //
1189 //          Use FPDFBitmap_GetFormat() to find out the format of the data.
1190 FPDF_EXPORT void* FPDF_CALLCONV FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap);
1191 
1192 // Function: FPDFBitmap_GetWidth
1193 //          Get width of a bitmap.
1194 // Parameters:
1195 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
1196 //                          or FPDFImageObj_GetBitmap.
1197 // Return value:
1198 //          The width of the bitmap in pixels.
1199 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetWidth(FPDF_BITMAP bitmap);
1200 
1201 // Function: FPDFBitmap_GetHeight
1202 //          Get height of a bitmap.
1203 // Parameters:
1204 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
1205 //                          or FPDFImageObj_GetBitmap.
1206 // Return value:
1207 //          The height of the bitmap in pixels.
1208 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetHeight(FPDF_BITMAP bitmap);
1209 
1210 // Function: FPDFBitmap_GetStride
1211 //          Get number of bytes for each line in the bitmap buffer.
1212 // Parameters:
1213 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
1214 //                          or FPDFImageObj_GetBitmap.
1215 // Return value:
1216 //          The number of bytes for each line in the bitmap buffer.
1217 // Comments:
1218 //          The stride may be more than width * number of bytes per pixel.
1219 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetStride(FPDF_BITMAP bitmap);
1220 
1221 // Function: FPDFBitmap_Destroy
1222 //          Destroy a bitmap and release all related buffers.
1223 // Parameters:
1224 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
1225 //                          or FPDFImageObj_GetBitmap.
1226 // Return value:
1227 //          None.
1228 // Comments:
1229 //          This function will not destroy any external buffers provided when
1230 //          the bitmap was created.
1231 FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_Destroy(FPDF_BITMAP bitmap);
1232 
1233 // Function: FPDF_VIEWERREF_GetPrintScaling
1234 //          Whether the PDF document prefers to be scaled or not.
1235 // Parameters:
1236 //          document    -   Handle to the loaded document.
1237 // Return value:
1238 //          None.
1239 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
1240 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document);
1241 
1242 // Function: FPDF_VIEWERREF_GetNumCopies
1243 //          Returns the number of copies to be printed.
1244 // Parameters:
1245 //          document    -   Handle to the loaded document.
1246 // Return value:
1247 //          The number of copies to be printed.
1248 FPDF_EXPORT int FPDF_CALLCONV
1249 FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document);
1250 
1251 // Function: FPDF_VIEWERREF_GetPrintPageRange
1252 //          Page numbers to initialize print dialog box when file is printed.
1253 // Parameters:
1254 //          document    -   Handle to the loaded document.
1255 // Return value:
1256 //          The print page range to be used for printing.
1257 FPDF_EXPORT FPDF_PAGERANGE FPDF_CALLCONV
1258 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document);
1259 
1260 // Experimental API.
1261 // Function: FPDF_VIEWERREF_GetPrintPageRangeCount
1262 //          Returns the number of elements in a FPDF_PAGERANGE.
1263 // Parameters:
1264 //          pagerange   -   Handle to the page range.
1265 // Return value:
1266 //          The number of elements in the page range. Returns 0 on error.
1267 FPDF_EXPORT size_t FPDF_CALLCONV
1268 FPDF_VIEWERREF_GetPrintPageRangeCount(FPDF_PAGERANGE pagerange);
1269 
1270 // Experimental API.
1271 // Function: FPDF_VIEWERREF_GetPrintPageRangeElement
1272 //          Returns an element from a FPDF_PAGERANGE.
1273 // Parameters:
1274 //          pagerange   -   Handle to the page range.
1275 //          index       -   Index of the element.
1276 // Return value:
1277 //          The value of the element in the page range at a given index.
1278 //          Returns -1 on error.
1279 FPDF_EXPORT int FPDF_CALLCONV
1280 FPDF_VIEWERREF_GetPrintPageRangeElement(FPDF_PAGERANGE pagerange, size_t index);
1281 
1282 // Function: FPDF_VIEWERREF_GetDuplex
1283 //          Returns the paper handling option to be used when printing from
1284 //          the print dialog.
1285 // Parameters:
1286 //          document    -   Handle to the loaded document.
1287 // Return value:
1288 //          The paper handling option to be used when printing.
1289 FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV
1290 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document);
1291 
1292 // Function: FPDF_VIEWERREF_GetName
1293 //          Gets the contents for a viewer ref, with a given key. The value must
1294 //          be of type "name".
1295 // Parameters:
1296 //          document    -   Handle to the loaded document.
1297 //          key         -   Name of the key in the viewer pref dictionary,
1298 //                          encoded in UTF-8.
1299 //          buffer      -   Caller-allocate buffer to receive the key, or NULL
1300 //                      -   to query the required length.
1301 //          length      -   Length of the buffer.
1302 // Return value:
1303 //          The number of bytes in the contents, including the NULL terminator.
1304 //          Thus if the return value is 0, then that indicates an error, such
1305 //          as when |document| is invalid. If |length| is less than the required
1306 //          length, or |buffer| is NULL, |buffer| will not be modified.
1307 FPDF_EXPORT unsigned long FPDF_CALLCONV
1308 FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document,
1309                        FPDF_BYTESTRING key,
1310                        char* buffer,
1311                        unsigned long length);
1312 
1313 // Function: FPDF_CountNamedDests
1314 //          Get the count of named destinations in the PDF document.
1315 // Parameters:
1316 //          document    -   Handle to a document
1317 // Return value:
1318 //          The count of named destinations.
1319 FPDF_EXPORT FPDF_DWORD FPDF_CALLCONV
1320 FPDF_CountNamedDests(FPDF_DOCUMENT document);
1321 
1322 // Function: FPDF_GetNamedDestByName
1323 //          Get a the destination handle for the given name.
1324 // Parameters:
1325 //          document    -   Handle to the loaded document.
1326 //          name        -   The name of a destination.
1327 // Return value:
1328 //          The handle to the destination.
1329 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV
1330 FPDF_GetNamedDestByName(FPDF_DOCUMENT document, FPDF_BYTESTRING name);
1331 
1332 // Function: FPDF_GetNamedDest
1333 //          Get the named destination by index.
1334 // Parameters:
1335 //          document        -   Handle to a document
1336 //          index           -   The index of a named destination.
1337 //          buffer          -   The buffer to store the destination name,
1338 //                              used as wchar_t*.
1339 //          buflen [in/out] -   Size of the buffer in bytes on input,
1340 //                              length of the result in bytes on output
1341 //                              or -1 if the buffer is too small.
1342 // Return value:
1343 //          The destination handle for a given index, or NULL if there is no
1344 //          named destination corresponding to |index|.
1345 // Comments:
1346 //          Call this function twice to get the name of the named destination:
1347 //            1) First time pass in |buffer| as NULL and get buflen.
1348 //            2) Second time pass in allocated |buffer| and buflen to retrieve
1349 //               |buffer|, which should be used as wchar_t*.
1350 //
1351 //         If buflen is not sufficiently large, it will be set to -1 upon
1352 //         return.
1353 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDest(FPDF_DOCUMENT document,
1354                                                       int index,
1355                                                       void* buffer,
1356                                                       long* buflen);
1357 
1358 // Experimental API.
1359 // Function: FPDF_GetXFAPacketCount
1360 //          Get the number of valid packets in the XFA entry.
1361 // Parameters:
1362 //          document - Handle to the document.
1363 // Return value:
1364 //          The number of valid packets, or -1 on error.
1365 FPDF_EXPORT int FPDF_CALLCONV FPDF_GetXFAPacketCount(FPDF_DOCUMENT document);
1366 
1367 // Experimental API.
1368 // Function: FPDF_GetXFAPacketName
1369 //          Get the name of a packet in the XFA array.
1370 // Parameters:
1371 //          document - Handle to the document.
1372 //          index    - Index number of the packet. 0 for the first packet.
1373 //          buffer   - Buffer for holding the name of the XFA packet.
1374 //          buflen   - Length of |buffer| in bytes.
1375 // Return value:
1376 //          The length of the packet name in bytes, or 0 on error.
1377 //
1378 // |document| must be valid and |index| must be in the range [0, N), where N is
1379 // the value returned by FPDF_GetXFAPacketCount().
1380 // |buffer| is only modified if it is non-NULL and |buflen| is greater than or
1381 // equal to the length of the packet name. The packet name includes a
1382 // terminating NUL character. |buffer| is unmodified on error.
1383 FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetXFAPacketName(
1384     FPDF_DOCUMENT document,
1385     int index,
1386     void* buffer,
1387     unsigned long buflen);
1388 
1389 // Experimental API.
1390 // Function: FPDF_GetXFAPacketContent
1391 //          Get the content of a packet in the XFA array.
1392 // Parameters:
1393 //          document   - Handle to the document.
1394 //          index      - Index number of the packet. 0 for the first packet.
1395 //          buffer     - Buffer for holding the content of the XFA packet.
1396 //          buflen     - Length of |buffer| in bytes.
1397 //          out_buflen - Pointer to the variable that will receive the minimum
1398 //                       buffer size needed to contain the content of the XFA
1399 //                       packet.
1400 // Return value:
1401 //          Whether the operation succeeded or not.
1402 //
1403 // |document| must be valid and |index| must be in the range [0, N), where N is
1404 // the value returned by FPDF_GetXFAPacketCount(). |out_buflen| must not be
1405 // NULL. When the aforementioned arguments are valid, the operation succeeds,
1406 // and |out_buflen| receives the content size. |buffer| is only modified if
1407 // |buffer| is non-null and long enough to contain the content. Callers must
1408 // check both the return value and the input |buflen| is no less than the
1409 // returned |out_buflen| before using the data in |buffer|.
1410 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetXFAPacketContent(
1411     FPDF_DOCUMENT document,
1412     int index,
1413     void* buffer,
1414     unsigned long buflen,
1415     unsigned long* out_buflen);
1416 
1417 #ifdef PDF_ENABLE_V8
1418 // Function: FPDF_GetRecommendedV8Flags
1419 //          Returns a space-separated string of command line flags that are
1420 //          recommended to be passed into V8 via V8::SetFlagsFromString()
1421 //          prior to initializing the PDFium library.
1422 // Parameters:
1423 //          None.
1424 // Return value:
1425 //          NUL-terminated string of the form "--flag1 --flag2".
1426 //          The caller must not attempt to modify or free the result.
1427 FPDF_EXPORT const char* FPDF_CALLCONV FPDF_GetRecommendedV8Flags();
1428 
1429 // Experimental API.
1430 // Function: FPDF_GetArrayBufferAllocatorSharedInstance()
1431 //          Helper function for initializing V8 isolates that will
1432 //          use PDFium's internal memory management.
1433 // Parameters:
1434 //          None.
1435 // Return Value:
1436 //          Pointer to a suitable v8::ArrayBuffer::Allocator, returned
1437 //          as void for C compatibility.
1438 // Notes:
1439 //          Use is optional, but allows external creation of isolates
1440 //          matching the ones PDFium will make when none is provided
1441 //          via |FPDF_LIBRARY_CONFIG::m_pIsolate|.
1442 //
1443 //          Can only be called when the library is in an uninitialized or
1444 //          destroyed state.
1445 FPDF_EXPORT void* FPDF_CALLCONV FPDF_GetArrayBufferAllocatorSharedInstance();
1446 #endif  // PDF_ENABLE_V8
1447 
1448 #ifdef PDF_ENABLE_XFA
1449 // Function: FPDF_BStr_Init
1450 //          Helper function to initialize a FPDF_BSTR.
1451 FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Init(FPDF_BSTR* bstr);
1452 
1453 // Function: FPDF_BStr_Set
1454 //          Helper function to copy string data into the FPDF_BSTR.
1455 FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Set(FPDF_BSTR* bstr,
1456                                                     const char* cstr,
1457                                                     int length);
1458 
1459 // Function: FPDF_BStr_Clear
1460 //          Helper function to clear a FPDF_BSTR.
1461 FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Clear(FPDF_BSTR* bstr);
1462 #endif  // PDF_ENABLE_XFA
1463 
1464 #ifdef __cplusplus
1465 }
1466 #endif
1467 
1468 #endif  // PUBLIC_FPDFVIEW_H_
1469