• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
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 // NOTE: External docs refer to this file as "fpdfview.h", so do not rename
8 // despite lack of consistency with other public files.
9 
10 #ifndef PUBLIC_FPDFVIEW_H_
11 #define PUBLIC_FPDFVIEW_H_
12 
13 #if defined(_WIN32) && !defined(__WINDOWS__)
14 #include <windows.h>
15 #endif
16 
17 #ifdef PDF_ENABLE_XFA
18 // PDF_USE_XFA is set in confirmation that this version of PDFium can support
19 // XFA forms as requested by the PDF_ENABLE_XFA setting.
20 #define PDF_USE_XFA
21 #endif  // PDF_ENABLE_XFA
22 
23 // PDF object types
24 #define FPDF_OBJECT_UNKNOWN 0
25 #define FPDF_OBJECT_BOOLEAN 1
26 #define FPDF_OBJECT_NUMBER 2
27 #define FPDF_OBJECT_STRING 3
28 #define FPDF_OBJECT_NAME 4
29 #define FPDF_OBJECT_ARRAY 5
30 #define FPDF_OBJECT_DICTIONARY 6
31 #define FPDF_OBJECT_STREAM 7
32 #define FPDF_OBJECT_NULLOBJ 8
33 #define FPDF_OBJECT_REFERENCE 9
34 
35 // PDF types
36 typedef void* FPDF_ACTION;
37 typedef void* FPDF_ANNOTATION;
38 typedef void* FPDF_ATTACHMENT;
39 typedef void* FPDF_BITMAP;
40 typedef void* FPDF_BOOKMARK;
41 typedef void* FPDF_CLIPPATH;
42 typedef void* FPDF_DEST;
43 typedef void* FPDF_DOCUMENT;
44 typedef void* FPDF_FONT;
45 typedef void* FPDF_LINK;
46 typedef void* FPDF_PAGE;
47 typedef void* FPDF_PAGELINK;
48 typedef void* FPDF_PAGEOBJECT;  // Page object(text, path, etc)
49 typedef void* FPDF_PAGERANGE;
50 typedef void* FPDF_RECORDER;
51 typedef void* FPDF_SCHHANDLE;
52 typedef void* FPDF_STRUCTELEMENT;
53 typedef void* FPDF_STRUCTTREE;
54 typedef void* FPDF_TEXTPAGE;
55 typedef void const* FPDF_PATHSEGMENT;
56 
57 #ifdef PDF_ENABLE_XFA
58 typedef void* FPDF_STRINGHANDLE;
59 typedef void* FPDF_WIDGET;
60 #endif  // PDF_ENABLE_XFA
61 
62 // Basic data types
63 typedef int FPDF_BOOL;
64 typedef int FPDF_ERROR;
65 typedef unsigned long FPDF_DWORD;
66 typedef float FS_FLOAT;
67 
68 #ifdef PDF_ENABLE_XFA
69 typedef void* FPDF_LPVOID;
70 typedef void const* FPDF_LPCVOID;
71 typedef char const* FPDF_LPCSTR;
72 typedef int FPDF_RESULT;
73 #endif
74 
75 // Duplex types
76 typedef enum _FPDF_DUPLEXTYPE_ {
77   DuplexUndefined = 0,
78   Simplex,
79   DuplexFlipShortEdge,
80   DuplexFlipLongEdge
81 } FPDF_DUPLEXTYPE;
82 
83 // String types
84 typedef unsigned short FPDF_WCHAR;
85 typedef unsigned char const* FPDF_LPCBYTE;
86 
87 // FPDFSDK may use three types of strings: byte string, wide string (UTF-16LE
88 // encoded), and platform dependent string
89 typedef const char* FPDF_BYTESTRING;
90 
91 // FPDFSDK always uses UTF-16LE encoded wide strings, each character uses 2
92 // bytes (except surrogation), with the low byte first.
93 typedef const unsigned short* FPDF_WIDESTRING;
94 
95 #ifdef PDF_ENABLE_XFA
96 // Structure for a byte string.
97 // Note, a byte string commonly means a UTF-16LE formated string.
98 typedef struct _FPDF_BSTR {
99   // String buffer.
100   char* str;
101   // Length of the string, in bytes.
102   int len;
103 } FPDF_BSTR;
104 #endif  // PDF_ENABLE_XFA
105 
106 // For Windows programmers: In most cases it's OK to treat FPDF_WIDESTRING as a
107 // Windows unicode string, however, special care needs to be taken if you
108 // expect to process Unicode larger than 0xffff.
109 //
110 // For Linux/Unix programmers: most compiler/library environments use 4 bytes
111 // for a Unicode character, and you have to convert between FPDF_WIDESTRING and
112 // system wide string by yourself.
113 typedef const char* FPDF_STRING;
114 
115 // Matrix for transformation, in the form [a b c d e f], equivalent to:
116 // | a  b  0 |
117 // | c  d  0 |
118 // | e  f  1 |
119 //
120 // Translation is performed with [1 0 0 1 tx ty].
121 // Scaling is performed with [sx 0 0 sy 0 0].
122 // See PDF Reference 1.7, 4.2.2 Common Transformations for more.
123 typedef struct _FS_MATRIX_ {
124   float a;
125   float b;
126   float c;
127   float d;
128   float e;
129   float f;
130 } FS_MATRIX;
131 
132 // Rectangle area(float) in device or page coordinate system.
133 typedef struct _FS_RECTF_ {
134   // The x-coordinate of the left-top corner.
135   float left;
136   // The y-coordinate of the left-top corner.
137   float top;
138   // The x-coordinate of the right-bottom corner.
139   float right;
140   // The y-coordinate of the right-bottom corner.
141   float bottom;
142 } * FS_LPRECTF, FS_RECTF;
143 
144 // Const Pointer to FS_RECTF structure.
145 typedef const FS_RECTF* FS_LPCRECTF;
146 
147 // Annotation enums.
148 typedef int FPDF_ANNOTATION_SUBTYPE;
149 typedef int FPDF_ANNOT_APPEARANCEMODE;
150 
151 // Dictionary value types.
152 typedef int FPDF_OBJECT_TYPE;
153 
154 #if defined(_WIN32) && defined(FPDFSDK_EXPORTS)
155 // On Windows system, functions are exported in a DLL
156 #define FPDF_EXPORT __declspec(dllexport)
157 #define FPDF_CALLCONV __stdcall
158 #else
159 #define FPDF_EXPORT
160 #define FPDF_CALLCONV
161 #endif
162 
163 // Exported Functions
164 #ifdef __cplusplus
165 extern "C" {
166 #endif
167 
168 // Function: FPDF_InitLibrary
169 //          Initialize the FPDFSDK library
170 // Parameters:
171 //          None
172 // Return value:
173 //          None.
174 // Comments:
175 //          Convenience function to call FPDF_InitLibraryWithConfig() for
176 //          backwards comatibility purposes.
177 FPDF_EXPORT void FPDF_CALLCONV FPDF_InitLibrary();
178 
179 // Process-wide options for initializing the library.
180 typedef struct FPDF_LIBRARY_CONFIG_ {
181   // Version number of the interface. Currently must be 2.
182   int version;
183 
184   // Array of paths to scan in place of the defaults when using built-in
185   // FXGE font loading code. The array is terminated by a NULL pointer.
186   // The Array may be NULL itself to use the default paths. May be ignored
187   // entirely depending upon the platform.
188   const char** m_pUserFontPaths;
189 
190   // Version 2.
191 
192   // pointer to the v8::Isolate to use, or NULL to force PDFium to create one.
193   void* m_pIsolate;
194 
195   // The embedder data slot to use in the v8::Isolate to store PDFium's
196   // per-isolate data. The value needs to be between 0 and
197   // v8::Internals::kNumIsolateDataLots (exclusive). Note that 0 is fine
198   // for most embedders.
199   unsigned int m_v8EmbedderSlot;
200 } FPDF_LIBRARY_CONFIG;
201 
202 // Function: FPDF_InitLibraryWithConfig
203 //          Initialize the FPDFSDK library
204 // Parameters:
205 //          config - configuration information as above.
206 // Return value:
207 //          None.
208 // Comments:
209 //          You have to call this function before you can call any PDF
210 //          processing functions.
211 FPDF_EXPORT void FPDF_CALLCONV
212 FPDF_InitLibraryWithConfig(const FPDF_LIBRARY_CONFIG* config);
213 
214 // Function: FPDF_DestroyLibary
215 //          Release all resources allocated by the FPDFSDK library.
216 // Parameters:
217 //          None.
218 // Return value:
219 //          None.
220 // Comments:
221 //          You can call this function to release all memory blocks allocated by
222 //          the library.
223 //          After this function is called, you should not call any PDF
224 //          processing functions.
225 FPDF_EXPORT void FPDF_CALLCONV FPDF_DestroyLibrary();
226 
227 // Policy for accessing the local machine time.
228 #define FPDF_POLICY_MACHINETIME_ACCESS 0
229 
230 // Function: FPDF_SetSandBoxPolicy
231 //          Set the policy for the sandbox environment.
232 // Parameters:
233 //          policy -   The specified policy for setting, for example:
234 //                     FPDF_POLICY_MACHINETIME_ACCESS.
235 //          enable -   True to enable, false to disable the policy.
236 // Return value:
237 //          None.
238 FPDF_EXPORT void FPDF_CALLCONV FPDF_SetSandBoxPolicy(FPDF_DWORD policy,
239                                                      FPDF_BOOL enable);
240 
241 #if defined(_WIN32)
242 #if defined(PDFIUM_PRINT_TEXT_WITH_GDI)
243 // Pointer to a helper function to make |font| with |text| of |text_length|
244 // accessible when printing text with GDI. This is useful in sandboxed
245 // environments where PDFium's access to GDI may be restricted.
246 typedef void (*PDFiumEnsureTypefaceCharactersAccessible)(const LOGFONT* font,
247                                                          const wchar_t* text,
248                                                          size_t text_length);
249 
250 // Function: FPDF_SetTypefaceAccessibleFunc
251 //          Set the function pointer that makes GDI fonts available in sandboxed
252 //          environments. Experimental API.
253 // Parameters:
254 //          func -   A function pointer. See description above.
255 // Return value:
256 //          None.
257 FPDF_EXPORT void FPDF_CALLCONV
258 FPDF_SetTypefaceAccessibleFunc(PDFiumEnsureTypefaceCharactersAccessible func);
259 
260 // Function: FPDF_SetPrintTextWithGDI
261 //          Set whether to use GDI to draw fonts when printing on Windows.
262 //          Experimental API.
263 // Parameters:
264 //          use_gdi -   Set to true to enable printing text with GDI.
265 // Return value:
266 //          None.
267 FPDF_EXPORT void FPDF_CALLCONV FPDF_SetPrintTextWithGDI(FPDF_BOOL use_gdi);
268 #endif  // PDFIUM_PRINT_TEXT_WITH_GDI
269 
270 // Function: FPDF_SetPrintPostscriptLevel
271 //          Set postscript printing level when printing on Windows.
272 //          Experimental API.
273 // Parameters:
274 //          postscript_level- 0 to disable postscript printing,
275 //                            2 to print with postscript level 2,
276 //                            3 to print with postscript level 3.
277 //                            All other values are invalid.
278 // Return value:
279 //          True if successful, false if unsuccessful (typically invalid input).
280 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
281 FPDF_SetPrintPostscriptLevel(int postscript_level);
282 
283 // Function: FPDF_SetPrintMode
284 //          Set printing mode when printing on Windows.
285 //          Experimental API.
286 // Parameters:
287 //          mode - FPDF_PRINTMODE_EMF to output EMF (default)
288 //                 FPDF_PRINTMODE_TEXTONLY to output text only (for charstream
289 //                 devices)
290 //                 FPDF_PRINTMODE_POSTSCRIPT2 to output level 2 postscript
291 //                 FPDF_PRINTMODE_POSTSCRIPT3 to output level 3 postscript
292 // Return value:
293 //          True if successful, false if unsuccessful (typically invalid input).
294 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_SetPrintMode(int mode);
295 #endif  // defined(_WIN32)
296 
297 // Function: FPDF_LoadDocument
298 //          Open and load a PDF document.
299 // Parameters:
300 //          file_path -  Path to the PDF file (including extension).
301 //          password  -  A string used as the password for the PDF file.
302 //                       If no password is needed, empty or NULL can be used.
303 // Return value:
304 //          A handle to the loaded document, or NULL on failure.
305 // Comments:
306 //          Loaded document can be closed by FPDF_CloseDocument().
307 //          If this function fails, you can use FPDF_GetLastError() to retrieve
308 //          the reason why it failed.
309 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
310 FPDF_LoadDocument(FPDF_STRING file_path, FPDF_BYTESTRING password);
311 
312 // Function: FPDF_LoadMemDocument
313 //          Open and load a PDF document from memory.
314 // Parameters:
315 //          data_buf    -   Pointer to a buffer containing the PDF document.
316 //          size        -   Number of bytes in the PDF document.
317 //          password    -   A string used as the password for the PDF file.
318 //                          If no password is needed, empty or NULL can be used.
319 // Return value:
320 //          A handle to the loaded document, or NULL on failure.
321 // Comments:
322 //          The memory buffer must remain valid when the document is open.
323 //          The loaded document can be closed by FPDF_CloseDocument.
324 //          If this function fails, you can use FPDF_GetLastError() to retrieve
325 //          the reason why it failed.
326 // Notes:
327 //          If PDFium is built with the XFA module, the application should call
328 //          FPDF_LoadXFA() function after the PDF document loaded to support XFA
329 //          fields defined in the fpdfformfill.h file.
330 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
331 FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password);
332 
333 // Structure for custom file access.
334 typedef struct {
335   // File length, in bytes.
336   unsigned long m_FileLen;
337 
338   // A function pointer for getting a block of data from a specific position.
339   // Position is specified by byte offset from the beginning of the file.
340   // The position and size will never go out of range of the file length.
341   // It may be possible for FPDFSDK to call this function multiple times for
342   // the same position.
343   // Return value: should be non-zero if successful, zero for error.
344   int (*m_GetBlock)(void* param,
345                     unsigned long position,
346                     unsigned char* pBuf,
347                     unsigned long size);
348 
349   // A custom pointer for all implementation specific data.  This pointer will
350   // be used as the first parameter to the m_GetBlock callback.
351   void* m_Param;
352 } FPDF_FILEACCESS;
353 
354 #ifdef PDF_ENABLE_XFA
355 /**
356  * @brief Structure for file reading or writing (I/O).
357  *
358  * @note This is a handler and should be implemented by callers.
359  */
360 typedef struct _FPDF_FILEHANDLER {
361   /**
362    * @brief User-defined data.
363    * @note Callers can use this field to track controls.
364    */
365   FPDF_LPVOID clientData;
366   /**
367    * @brief Callback function to release the current file stream object.
368    *
369    * @param[in] clientData    Pointer to user-defined data.
370    *
371    * @return None.
372    */
373   void (*Release)(FPDF_LPVOID clientData);
374   /**
375    * @brief Callback function to retrieve the current file stream size.
376    *
377    * @param[in] clientData    Pointer to user-defined data.
378    *
379    * @return Size of file stream.
380    */
381   FPDF_DWORD (*GetSize)(FPDF_LPVOID clientData);
382   /**
383    * @brief Callback function to read data from the current file stream.
384    *
385    * @param[in]   clientData  Pointer to user-defined data.
386    * @param[in]   offset      Offset position starts from the beginning of file
387    * stream. This parameter indicates reading position.
388    * @param[in]   buffer      Memory buffer to store data which are read from
389    * file stream. This parameter should not be <b>NULL</b>.
390    * @param[in]   size        Size of data which should be read from file
391    * stream, in bytes. The buffer indicated by the parameter <i>buffer</i>
392    * should be enough to store specified data.
393    *
394    * @return 0 for success, other value for failure.
395    */
396   FPDF_RESULT (*ReadBlock)(FPDF_LPVOID clientData,
397                            FPDF_DWORD offset,
398                            FPDF_LPVOID buffer,
399                            FPDF_DWORD size);
400   /**
401    * @brief   Callback function to write data into the current file stream.
402    *
403    * @param[in]   clientData  Pointer to user-defined data.
404    * @param[in]   offset      Offset position starts from the beginning of file
405    * stream. This parameter indicates writing position.
406    * @param[in]   buffer      Memory buffer contains data which is written into
407    * file stream. This parameter should not be <b>NULL</b>.
408    * @param[in]   size        Size of data which should be written into file
409    * stream, in bytes.
410    *
411    * @return 0 for success, other value for failure.
412    */
413   FPDF_RESULT (*WriteBlock)(FPDF_LPVOID clientData,
414                             FPDF_DWORD offset,
415                             FPDF_LPCVOID buffer,
416                             FPDF_DWORD size);
417   /**
418    * @brief   Callback function to flush all internal accessing buffers.
419    *
420    * @param[in]   clientData  Pointer to user-defined data.
421    *
422    * @return 0 for success, other value for failure.
423    */
424   FPDF_RESULT (*Flush)(FPDF_LPVOID clientData);
425   /**
426    * @brief   Callback function to change file size.
427    *
428    * @details This function is called under writing mode usually. Implementer
429    * can determine whether to realize it based on application requests.
430    *
431    * @param[in]   clientData  Pointer to user-defined data.
432    * @param[in]   size        New size of file stream, in bytes.
433    *
434    * @return 0 for success, other value for failure.
435    */
436   FPDF_RESULT (*Truncate)(FPDF_LPVOID clientData, FPDF_DWORD size);
437 } FPDF_FILEHANDLER, *FPDF_LPFILEHANDLER;
438 
439 #endif
440 // Function: FPDF_LoadCustomDocument
441 //          Load PDF document from a custom access descriptor.
442 // Parameters:
443 //          pFileAccess -   A structure for accessing the file.
444 //          password    -   Optional password for decrypting the PDF file.
445 // Return value:
446 //          A handle to the loaded document, or NULL on failure.
447 // Comments:
448 //          The application must keep the file resources valid until the PDF
449 //          document is closed.
450 //
451 //          The loaded document can be closed with FPDF_CloseDocument.
452 // Notes:
453 //          If PDFium is built with the XFA module, the application should call
454 //          FPDF_LoadXFA() function after the PDF document loaded to support XFA
455 //          fields defined in the fpdfformfill.h file.
456 FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV
457 FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password);
458 
459 // Function: FPDF_GetFileVersion
460 //          Get the file version of the given PDF document.
461 // Parameters:
462 //          doc         -   Handle to a document.
463 //          fileVersion -   The PDF file version. File version: 14 for 1.4, 15
464 //                          for 1.5, ...
465 // Return value:
466 //          True if succeeds, false otherwise.
467 // Comments:
468 //          If the document was created by FPDF_CreateNewDocument,
469 //          then this function will always fail.
470 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetFileVersion(FPDF_DOCUMENT doc,
471                                                         int* fileVersion);
472 
473 #define FPDF_ERR_SUCCESS 0    // No error.
474 #define FPDF_ERR_UNKNOWN 1    // Unknown error.
475 #define FPDF_ERR_FILE 2       // File not found or could not be opened.
476 #define FPDF_ERR_FORMAT 3     // File not in PDF format or corrupted.
477 #define FPDF_ERR_PASSWORD 4   // Password required or incorrect password.
478 #define FPDF_ERR_SECURITY 5   // Unsupported security scheme.
479 #define FPDF_ERR_PAGE 6       // Page not found or content error.
480 #ifdef PDF_ENABLE_XFA
481 #define FPDF_ERR_XFALOAD 7    // Load XFA error.
482 #define FPDF_ERR_XFALAYOUT 8  // Layout XFA error.
483 #endif  // PDF_ENABLE_XFA
484 
485 // Function: FPDF_GetLastError
486 //          Get last error code when a function fails.
487 // Parameters:
488 //          None.
489 // Return value:
490 //          A 32-bit integer indicating error code as defined above.
491 // Comments:
492 //          If the previous SDK call succeeded, the return value of this
493 //          function is not defined.
494 FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetLastError();
495 
496 // Function: FPDF_GetDocPermission
497 //          Get file permission flags of the document.
498 // Parameters:
499 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
500 // Return value:
501 //          A 32-bit integer indicating permission flags. Please refer to the
502 //          PDF Reference for detailed descriptions. If the document is not
503 //          protected, 0xffffffff will be returned.
504 FPDF_EXPORT unsigned long FPDF_CALLCONV
505 FPDF_GetDocPermissions(FPDF_DOCUMENT document);
506 
507 // Function: FPDF_GetSecurityHandlerRevision
508 //          Get the revision for the security handler.
509 // Parameters:
510 //          document    -   Handle to a document. Returned by FPDF_LoadDocument.
511 // Return value:
512 //          The security handler revision number. Please refer to the PDF
513 //          Reference for a detailed description. If the document is not
514 //          protected, -1 will be returned.
515 FPDF_EXPORT int FPDF_CALLCONV
516 FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document);
517 
518 // Function: FPDF_GetPageCount
519 //          Get total number of pages in the document.
520 // Parameters:
521 //          document    -   Handle to document. Returned by FPDF_LoadDocument.
522 // Return value:
523 //          Total number of pages in the document.
524 FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageCount(FPDF_DOCUMENT document);
525 
526 // Function: FPDF_LoadPage
527 //          Load a page inside the document.
528 // Parameters:
529 //          document    -   Handle to document. Returned by FPDF_LoadDocument
530 //          page_index  -   Index number of the page. 0 for the first page.
531 // Return value:
532 //          A handle to the loaded page, or NULL if page load fails.
533 // Comments:
534 //          The loaded page can be rendered to devices using FPDF_RenderPage.
535 //          The loaded page can be closed using FPDF_ClosePage.
536 FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDF_LoadPage(FPDF_DOCUMENT document,
537                                                   int page_index);
538 
539 // Function: FPDF_GetPageWidth
540 //          Get page width.
541 // Parameters:
542 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
543 // Return value:
544 //          Page width (excluding non-displayable area) measured in points.
545 //          One point is 1/72 inch (around 0.3528 mm).
546 FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageWidth(FPDF_PAGE page);
547 
548 // Function: FPDF_GetPageHeight
549 //          Get page height.
550 // Parameters:
551 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
552 // Return value:
553 //          Page height (excluding non-displayable area) measured in points.
554 //          One point is 1/72 inch (around 0.3528 mm)
555 FPDF_EXPORT double FPDF_CALLCONV FPDF_GetPageHeight(FPDF_PAGE page);
556 
557 // Experimental API.
558 // Function: FPDF_GetPageBoundingBox
559 //          Get the bounding box of the page. This is the intersection between
560 //          its media box and its crop box.
561 // Parameters:
562 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
563 //          rect        -   Pointer to a rect to receive the page bounding box.
564 //                          On an error, |rect| won't be filled.
565 // Return value:
566 //          True for success.
567 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDF_GetPageBoundingBox(FPDF_PAGE page,
568                                                             FS_RECTF* rect);
569 
570 // Function: FPDF_GetPageSizeByIndex
571 //          Get the size of the page at the given index.
572 // Parameters:
573 //          document    -   Handle to document. Returned by FPDF_LoadDocument.
574 //          page_index  -   Page index, zero for the first page.
575 //          width       -   Pointer to a double to receive the page width
576 //                          (in points).
577 //          height      -   Pointer to a double to receive the page height
578 //                          (in points).
579 // Return value:
580 //          Non-zero for success. 0 for error (document or page not found).
581 FPDF_EXPORT int FPDF_CALLCONV FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
582                                                       int page_index,
583                                                       double* width,
584                                                       double* height);
585 
586 // Page rendering flags. They can be combined with bit-wise OR.
587 //
588 // Set if annotations are to be rendered.
589 #define FPDF_ANNOT 0x01
590 // Set if using text rendering optimized for LCD display.
591 #define FPDF_LCD_TEXT 0x02
592 // Don't use the native text output available on some platforms
593 #define FPDF_NO_NATIVETEXT 0x04
594 // Grayscale output.
595 #define FPDF_GRAYSCALE 0x08
596 // Set if you want to get some debug info.
597 #define FPDF_DEBUG_INFO 0x80
598 // Set if you don't want to catch exceptions.
599 #define FPDF_NO_CATCH 0x100
600 // Limit image cache size.
601 #define FPDF_RENDER_LIMITEDIMAGECACHE 0x200
602 // Always use halftone for image stretching.
603 #define FPDF_RENDER_FORCEHALFTONE 0x400
604 // Render for printing.
605 #define FPDF_PRINTING 0x800
606 // Set to disable anti-aliasing on text.
607 #define FPDF_RENDER_NO_SMOOTHTEXT 0x1000
608 // Set to disable anti-aliasing on images.
609 #define FPDF_RENDER_NO_SMOOTHIMAGE 0x2000
610 // Set to disable anti-aliasing on paths.
611 #define FPDF_RENDER_NO_SMOOTHPATH 0x4000
612 // Set whether to render in a reverse Byte order, this flag is only used when
613 // rendering to a bitmap.
614 #define FPDF_REVERSE_BYTE_ORDER 0x10
615 
616 #ifdef _WIN32
617 // Function: FPDF_RenderPage
618 //          Render contents of a page to a device (screen, bitmap, or printer).
619 //          This function is only supported on Windows.
620 // Parameters:
621 //          dc          -   Handle to the device context.
622 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
623 //          start_x     -   Left pixel position of the display area in
624 //                          device coordinates.
625 //          start_y     -   Top pixel position of the display area in device
626 //                          coordinates.
627 //          size_x      -   Horizontal size (in pixels) for displaying the page.
628 //          size_y      -   Vertical size (in pixels) for displaying the page.
629 //          rotate      -   Page orientation:
630 //                            0 (normal)
631 //                            1 (rotated 90 degrees clockwise)
632 //                            2 (rotated 180 degrees)
633 //                            3 (rotated 90 degrees counter-clockwise)
634 //          flags       -   0 for normal display, or combination of flags
635 //                          defined above.
636 // Return value:
637 //          None.
638 FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPage(HDC dc,
639                                                FPDF_PAGE page,
640                                                int start_x,
641                                                int start_y,
642                                                int size_x,
643                                                int size_y,
644                                                int rotate,
645                                                int flags);
646 #endif
647 
648 // Function: FPDF_RenderPageBitmap
649 //          Render contents of a page to a device independent bitmap.
650 // Parameters:
651 //          bitmap      -   Handle to the device independent bitmap (as the
652 //                          output buffer). The bitmap handle can be created
653 //                          by FPDFBitmap_Create or retrieved from an image
654 //                          object by FPDFImageObj_GetBitmap.
655 //          page        -   Handle to the page. Returned by FPDF_LoadPage
656 //          start_x     -   Left pixel position of the display area in
657 //                          bitmap coordinates.
658 //          start_y     -   Top pixel position of the display area in bitmap
659 //                          coordinates.
660 //          size_x      -   Horizontal size (in pixels) for displaying the page.
661 //          size_y      -   Vertical size (in pixels) for displaying the page.
662 //          rotate      -   Page orientation:
663 //                            0 (normal)
664 //                            1 (rotated 90 degrees clockwise)
665 //                            2 (rotated 180 degrees)
666 //                            3 (rotated 90 degrees counter-clockwise)
667 //          flags       -   0 for normal display, or combination of the Page
668 //                          Rendering flags defined above. With the FPDF_ANNOT
669 //                          flag, it renders all annotations that do not require
670 //                          user-interaction, which are all annotations except
671 //                          widget and popup annotations.
672 // Return value:
673 //          None.
674 FPDF_EXPORT void FPDF_CALLCONV FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
675                                                      FPDF_PAGE page,
676                                                      int start_x,
677                                                      int start_y,
678                                                      int size_x,
679                                                      int size_y,
680                                                      int rotate,
681                                                      int flags);
682 
683 // Function: FPDF_RenderPageBitmapWithMatrix
684 //          Render contents of a page to a device independent bitmap.
685 // Parameters:
686 //          bitmap      -   Handle to the device independent bitmap (as the
687 //                          output buffer). The bitmap handle can be created
688 //                          by FPDFBitmap_Create or retrieved by
689 //                          FPDFImageObj_GetBitmap.
690 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
691 //          matrix      -   The transform matrix, which must be invertible.
692 //                          See PDF Reference 1.7, 4.2.2 Common Transformations.
693 //          clipping    -   The rect to clip to in device coords.
694 //          flags       -   0 for normal display, or combination of the Page
695 //                          Rendering flags defined above. With the FPDF_ANNOT
696 //                          flag, it renders all annotations that do not require
697 //                          user-interaction, which are all annotations except
698 //                          widget and popup annotations.
699 // Return value:
700 //          None. Note that behavior is undefined if det of |matrix| is 0.
701 FPDF_EXPORT void FPDF_CALLCONV
702 FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
703                                 FPDF_PAGE page,
704                                 const FS_MATRIX* matrix,
705                                 const FS_RECTF* clipping,
706                                 int flags);
707 
708 #ifdef _SKIA_SUPPORT_
709 FPDF_EXPORT FPDF_RECORDER FPDF_CALLCONV FPDF_RenderPageSkp(FPDF_PAGE page,
710                                                            int size_x,
711                                                            int size_y);
712 #endif
713 
714 // Function: FPDF_ClosePage
715 //          Close a loaded PDF page.
716 // Parameters:
717 //          page        -   Handle to the loaded page.
718 // Return value:
719 //          None.
720 FPDF_EXPORT void FPDF_CALLCONV FPDF_ClosePage(FPDF_PAGE page);
721 
722 // Function: FPDF_CloseDocument
723 //          Close a loaded PDF document.
724 // Parameters:
725 //          document    -   Handle to the loaded document.
726 // Return value:
727 //          None.
728 FPDF_EXPORT void FPDF_CALLCONV FPDF_CloseDocument(FPDF_DOCUMENT document);
729 
730 // Function: FPDF_DeviceToPage
731 //          Convert the screen coordinates of a point to page coordinates.
732 // Parameters:
733 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
734 //          start_x     -   Left pixel position of the display area in
735 //                          device coordinates.
736 //          start_y     -   Top pixel position of the display area in device
737 //                          coordinates.
738 //          size_x      -   Horizontal size (in pixels) for displaying the page.
739 //          size_y      -   Vertical size (in pixels) for displaying the page.
740 //          rotate      -   Page orientation:
741 //                            0 (normal)
742 //                            1 (rotated 90 degrees clockwise)
743 //                            2 (rotated 180 degrees)
744 //                            3 (rotated 90 degrees counter-clockwise)
745 //          device_x    -   X value in device coordinates to be converted.
746 //          device_y    -   Y value in device coordinates to be converted.
747 //          page_x      -   A pointer to a double receiving the converted X
748 //                          value in page coordinates.
749 //          page_y      -   A pointer to a double receiving the converted Y
750 //                          value in page coordinates.
751 // Return value:
752 //          None.
753 // Comments:
754 //          The page coordinate system has its origin at the left-bottom corner
755 //          of the page, with the X-axis on the bottom going to the right, and
756 //          the Y-axis on the left side going up.
757 //
758 //          NOTE: this coordinate system can be altered when you zoom, scroll,
759 //          or rotate a page, however, a point on the page should always have
760 //          the same coordinate values in the page coordinate system.
761 //
762 //          The device coordinate system is device dependent. For screen device,
763 //          its origin is at the left-top corner of the window. However this
764 //          origin can be altered by the Windows coordinate transformation
765 //          utilities.
766 //
767 //          You must make sure the start_x, start_y, size_x, size_y
768 //          and rotate parameters have exactly same values as you used in
769 //          the FPDF_RenderPage() function call.
770 FPDF_EXPORT void FPDF_CALLCONV FPDF_DeviceToPage(FPDF_PAGE page,
771                                                  int start_x,
772                                                  int start_y,
773                                                  int size_x,
774                                                  int size_y,
775                                                  int rotate,
776                                                  int device_x,
777                                                  int device_y,
778                                                  double* page_x,
779                                                  double* page_y);
780 
781 // Function: FPDF_PageToDevice
782 //          Convert the page coordinates of a point to screen coordinates.
783 // Parameters:
784 //          page        -   Handle to the page. Returned by FPDF_LoadPage.
785 //          start_x     -   Left pixel position of the display area in
786 //                          device coordinates.
787 //          start_y     -   Top pixel position of the display area in device
788 //                          coordinates.
789 //          size_x      -   Horizontal size (in pixels) for displaying the page.
790 //          size_y      -   Vertical size (in pixels) for displaying the page.
791 //          rotate      -   Page orientation:
792 //                            0 (normal)
793 //                            1 (rotated 90 degrees clockwise)
794 //                            2 (rotated 180 degrees)
795 //                            3 (rotated 90 degrees counter-clockwise)
796 //          page_x      -   X value in page coordinates.
797 //          page_y      -   Y value in page coordinate.
798 //          device_x    -   A pointer to an integer receiving the result X
799 //                          value in device coordinates.
800 //          device_y    -   A pointer to an integer receiving the result Y
801 //                          value in device coordinates.
802 // Return value:
803 //          None.
804 // Comments:
805 //          See comments for FPDF_DeviceToPage().
806 FPDF_EXPORT void FPDF_CALLCONV FPDF_PageToDevice(FPDF_PAGE page,
807                                                  int start_x,
808                                                  int start_y,
809                                                  int size_x,
810                                                  int size_y,
811                                                  int rotate,
812                                                  double page_x,
813                                                  double page_y,
814                                                  int* device_x,
815                                                  int* device_y);
816 
817 // Function: FPDFBitmap_Create
818 //          Create a device independent bitmap (FXDIB).
819 // Parameters:
820 //          width       -   The number of pixels in width for the bitmap.
821 //                          Must be greater than 0.
822 //          height      -   The number of pixels in height for the bitmap.
823 //                          Must be greater than 0.
824 //          alpha       -   A flag indicating whether the alpha channel is used.
825 //                          Non-zero for using alpha, zero for not using.
826 // Return value:
827 //          The created bitmap handle, or NULL if a parameter error or out of
828 //          memory.
829 // Comments:
830 //          The bitmap always uses 4 bytes per pixel. The first byte is always
831 //          double word aligned.
832 //
833 //          The byte order is BGRx (the last byte unused if no alpha channel) or
834 //          BGRA.
835 //
836 //          The pixels in a horizontal line are stored side by side, with the
837 //          left most pixel stored first (with lower memory address).
838 //          Each line uses width * 4 bytes.
839 //
840 //          Lines are stored one after another, with the top most line stored
841 //          first. There is no gap between adjacent lines.
842 //
843 //          This function allocates enough memory for holding all pixels in the
844 //          bitmap, but it doesn't initialize the buffer. Applications can use
845 //          FPDFBitmap_FillRect to fill the bitmap using any color.
846 FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_Create(int width,
847                                                         int height,
848                                                         int alpha);
849 
850 // More DIB formats
851 // Unknown or unsupported format.
852 #define FPDFBitmap_Unknown 0
853 // Gray scale bitmap, one byte per pixel.
854 #define FPDFBitmap_Gray 1
855 // 3 bytes per pixel, byte order: blue, green, red.
856 #define FPDFBitmap_BGR 2
857 // 4 bytes per pixel, byte order: blue, green, red, unused.
858 #define FPDFBitmap_BGRx 3
859 // 4 bytes per pixel, byte order: blue, green, red, alpha.
860 #define FPDFBitmap_BGRA 4
861 
862 // Function: FPDFBitmap_CreateEx
863 //          Create a device independent bitmap (FXDIB)
864 // Parameters:
865 //          width       -   The number of pixels in width for the bitmap.
866 //                          Must be greater than 0.
867 //          height      -   The number of pixels in height for the bitmap.
868 //                          Must be greater than 0.
869 //          format      -   A number indicating for bitmap format, as defined
870 //                          above.
871 //          first_scan  -   A pointer to the first byte of the first line if
872 //                          using an external buffer. If this parameter is NULL,
873 //                          then the a new buffer will be created.
874 //          stride      -   Number of bytes for each scan line, for external
875 //                          buffer only.
876 // Return value:
877 //          The bitmap handle, or NULL if parameter error or out of memory.
878 // Comments:
879 //          Similar to FPDFBitmap_Create function, but allows for more formats
880 //          and an external buffer is supported. The bitmap created by this
881 //          function can be used in any place that a FPDF_BITMAP handle is
882 //          required.
883 //
884 //          If an external buffer is used, then the application should destroy
885 //          the buffer by itself. FPDFBitmap_Destroy function will not destroy
886 //          the buffer.
887 FPDF_EXPORT FPDF_BITMAP FPDF_CALLCONV FPDFBitmap_CreateEx(int width,
888                                                           int height,
889                                                           int format,
890                                                           void* first_scan,
891                                                           int stride);
892 
893 // Function: FPDFBitmap_GetFormat
894 //          Get the format of the bitmap.
895 // Parameters:
896 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
897 //                          or FPDFImageObj_GetBitmap.
898 // Return value:
899 //          The format of the bitmap.
900 // Comments:
901 //          Only formats supported by FPDFBitmap_CreateEx are supported by this
902 //          function; see the list of such formats above.
903 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetFormat(FPDF_BITMAP bitmap);
904 
905 // Function: FPDFBitmap_FillRect
906 //          Fill a rectangle in a bitmap.
907 // Parameters:
908 //          bitmap      -   The handle to the bitmap. Returned by
909 //                          FPDFBitmap_Create.
910 //          left        -   The left position. Starting from 0 at the
911 //                          left-most pixel.
912 //          top         -   The top position. Starting from 0 at the
913 //                          top-most line.
914 //          width       -   Width in pixels to be filled.
915 //          height      -   Height in pixels to be filled.
916 //          color       -   A 32-bit value specifing the color, in 8888 ARGB
917 //                          format.
918 // Return value:
919 //          None.
920 // Comments:
921 //          This function sets the color and (optionally) alpha value in the
922 //          specified region of the bitmap.
923 //
924 //          NOTE: If the alpha channel is used, this function does NOT
925 //          composite the background with the source color, instead the
926 //          background will be replaced by the source color and the alpha.
927 //
928 //          If the alpha channel is not used, the alpha parameter is ignored.
929 FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
930                                                    int left,
931                                                    int top,
932                                                    int width,
933                                                    int height,
934                                                    FPDF_DWORD color);
935 
936 // Function: FPDFBitmap_GetBuffer
937 //          Get data buffer of a bitmap.
938 // Parameters:
939 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
940 //                          or FPDFImageObj_GetBitmap.
941 // Return value:
942 //          The pointer to the first byte of the bitmap buffer.
943 // Comments:
944 //          The stride may be more than width * number of bytes per pixel
945 //
946 //          Applications can use this function to get the bitmap buffer pointer,
947 //          then manipulate any color and/or alpha values for any pixels in the
948 //          bitmap.
949 //
950 //          The data is in BGRA format. Where the A maybe unused if alpha was
951 //          not specified.
952 FPDF_EXPORT void* FPDF_CALLCONV FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap);
953 
954 // Function: FPDFBitmap_GetWidth
955 //          Get width of a bitmap.
956 // Parameters:
957 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
958 //                          or FPDFImageObj_GetBitmap.
959 // Return value:
960 //          The width of the bitmap in pixels.
961 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetWidth(FPDF_BITMAP bitmap);
962 
963 // Function: FPDFBitmap_GetHeight
964 //          Get height of a bitmap.
965 // Parameters:
966 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
967 //                          or FPDFImageObj_GetBitmap.
968 // Return value:
969 //          The height of the bitmap in pixels.
970 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetHeight(FPDF_BITMAP bitmap);
971 
972 // Function: FPDFBitmap_GetStride
973 //          Get number of bytes for each line in the bitmap buffer.
974 // Parameters:
975 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
976 //                          or FPDFImageObj_GetBitmap.
977 // Return value:
978 //          The number of bytes for each line in the bitmap buffer.
979 // Comments:
980 //          The stride may be more than width * number of bytes per pixel.
981 FPDF_EXPORT int FPDF_CALLCONV FPDFBitmap_GetStride(FPDF_BITMAP bitmap);
982 
983 // Function: FPDFBitmap_Destroy
984 //          Destroy a bitmap and release all related buffers.
985 // Parameters:
986 //          bitmap      -   Handle to the bitmap. Returned by FPDFBitmap_Create
987 //                          or FPDFImageObj_GetBitmap.
988 // Return value:
989 //          None.
990 // Comments:
991 //          This function will not destroy any external buffers provided when
992 //          the bitmap was created.
993 FPDF_EXPORT void FPDF_CALLCONV FPDFBitmap_Destroy(FPDF_BITMAP bitmap);
994 
995 // Function: FPDF_VIEWERREF_GetPrintScaling
996 //          Whether the PDF document prefers to be scaled or not.
997 // Parameters:
998 //          document    -   Handle to the loaded document.
999 // Return value:
1000 //          None.
1001 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
1002 FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document);
1003 
1004 // Function: FPDF_VIEWERREF_GetNumCopies
1005 //          Returns the number of copies to be printed.
1006 // Parameters:
1007 //          document    -   Handle to the loaded document.
1008 // Return value:
1009 //          The number of copies to be printed.
1010 FPDF_EXPORT int FPDF_CALLCONV
1011 FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document);
1012 
1013 // Function: FPDF_VIEWERREF_GetPrintPageRange
1014 //          Page numbers to initialize print dialog box when file is printed.
1015 // Parameters:
1016 //          document    -   Handle to the loaded document.
1017 // Return value:
1018 //          The print page range to be used for printing.
1019 FPDF_EXPORT FPDF_PAGERANGE FPDF_CALLCONV
1020 FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document);
1021 
1022 // Function: FPDF_VIEWERREF_GetDuplex
1023 //          Returns the paper handling option to be used when printing from
1024 //          the print dialog.
1025 // Parameters:
1026 //          document    -   Handle to the loaded document.
1027 // Return value:
1028 //          The paper handling option to be used when printing.
1029 FPDF_EXPORT FPDF_DUPLEXTYPE FPDF_CALLCONV
1030 FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document);
1031 
1032 // Function: FPDF_VIEWERREF_GetName
1033 //          Gets the contents for a viewer ref, with a given key. The value must
1034 //          be of type "name".
1035 // Parameters:
1036 //          document    -   Handle to the loaded document.
1037 //          key         -   Name of the key in the viewer pref dictionary,
1038 //                          encoded in UTF-8.
1039 //          buffer      -   A string to write the contents of the key to.
1040 //          length      -   Length of the buffer.
1041 // Return value:
1042 //          The number of bytes in the contents, including the NULL terminator.
1043 //          Thus if the return value is 0, then that indicates an error, such
1044 //          as when |document| is invalid or |buffer| is NULL. If |length| is
1045 //          less than the returned length, or |buffer| is NULL, |buffer| will
1046 //          not be modified.
1047 FPDF_EXPORT unsigned long FPDF_CALLCONV
1048 FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document,
1049                        FPDF_BYTESTRING key,
1050                        char* buffer,
1051                        unsigned long length);
1052 
1053 // Function: FPDF_CountNamedDests
1054 //          Get the count of named destinations in the PDF document.
1055 // Parameters:
1056 //          document    -   Handle to a document
1057 // Return value:
1058 //          The count of named destinations.
1059 FPDF_EXPORT FPDF_DWORD FPDF_CALLCONV
1060 FPDF_CountNamedDests(FPDF_DOCUMENT document);
1061 
1062 // Function: FPDF_GetNamedDestByName
1063 //          Get a the destination handle for the given name.
1064 // Parameters:
1065 //          document    -   Handle to the loaded document.
1066 //          name        -   The name of a destination.
1067 // Return value:
1068 //          The handle to the destination.
1069 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV
1070 FPDF_GetNamedDestByName(FPDF_DOCUMENT document, FPDF_BYTESTRING name);
1071 
1072 // Function: FPDF_GetNamedDest
1073 //          Get the named destination by index.
1074 // Parameters:
1075 //          document        -   Handle to a document
1076 //          index           -   The index of a named destination.
1077 //          buffer          -   The buffer to store the destination name,
1078 //                              used as wchar_t*.
1079 //          buflen [in/out] -   Size of the buffer in bytes on input,
1080 //                              length of the result in bytes on output
1081 //                              or -1 if the buffer is too small.
1082 // Return value:
1083 //          The destination handle for a given index, or NULL if there is no
1084 //          named destination corresponding to |index|.
1085 // Comments:
1086 //          Call this function twice to get the name of the named destination:
1087 //            1) First time pass in |buffer| as NULL and get buflen.
1088 //            2) Second time pass in allocated |buffer| and buflen to retrieve
1089 //               |buffer|, which should be used as wchar_t*.
1090 //
1091 //         If buflen is not sufficiently large, it will be set to -1 upon
1092 //         return.
1093 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDF_GetNamedDest(FPDF_DOCUMENT document,
1094                                                       int index,
1095                                                       void* buffer,
1096                                                       long* buflen);
1097 
1098 #ifdef PDF_ENABLE_XFA
1099 // Function: FPDF_BStr_Init
1100 //          Helper function to initialize a byte string.
1101 FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Init(FPDF_BSTR* str);
1102 
1103 // Function: FPDF_BStr_Set
1104 //          Helper function to set string data.
1105 FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Set(FPDF_BSTR* str,
1106                                                     FPDF_LPCSTR bstr,
1107                                                     int length);
1108 
1109 // Function: FPDF_BStr_Clear
1110 //          Helper function to clear a byte string.
1111 FPDF_EXPORT FPDF_RESULT FPDF_CALLCONV FPDF_BStr_Clear(FPDF_BSTR* str);
1112 #endif  // PDF_ENABLE_XFA
1113 
1114 #ifdef __cplusplus
1115 }
1116 #endif
1117 
1118 #endif  // PUBLIC_FPDFVIEW_H_
1119