blob: 0ed9187f35f6c36053840971bb25521ec3c60c38 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Tom Sepez9857e202015-05-13 17:09:26 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez1ed8a212015-05-11 15:25:39 -07007// NOTE: External docs refer to this file as "fpdfview.h", so do not rename
Dan Sinclair50cce602016-02-24 09:51:16 -05008// despite lack of consistency with other public files.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009
Tom Sepez9857e202015-05-13 17:09:26 -070010#ifndef PUBLIC_FPDFVIEW_H_
11#define PUBLIC_FPDFVIEW_H_
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070012
13#if defined(_WIN32) && !defined(__WINDOWS__)
14#include <windows.h>
15#endif
16
Tom Sepezc46d0002015-11-30 15:46:36 -080017#ifdef PDF_ENABLE_XFA
Dan Sinclair3ebd1212016-03-09 09:59:23 -050018// 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.
Bo Xubb5ef882014-11-06 16:13:33 -080020#define PDF_USE_XFA
Tom Sepezc46d0002015-11-30 15:46:36 -080021#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022
23// PDF types
Tom Sepez9857e202015-05-13 17:09:26 -070024typedef void* FPDF_ACTION;
Tom Sepezc46d0002015-11-30 15:46:36 -080025typedef void* FPDF_BITMAP;
26typedef void* FPDF_BOOKMARK;
27typedef void* FPDF_CLIPPATH;
28typedef void* FPDF_DEST;
Tom Sepezc46d0002015-11-30 15:46:36 -080029typedef void* FPDF_DOCUMENT;
30typedef void* FPDF_FONT;
Tom Sepez9857e202015-05-13 17:09:26 -070031typedef void* FPDF_LINK;
Tom Sepezc46d0002015-11-30 15:46:36 -080032typedef void* FPDF_PAGE;
33typedef void* FPDF_PAGELINK;
34typedef void* FPDF_PAGEOBJECT; // Page object(text, path, etc)
Tom Sepez9857e202015-05-13 17:09:26 -070035typedef void* FPDF_PAGERANGE;
Cary Clark399be5b2016-03-14 16:51:29 -040036typedef void* FPDF_RECORDER;
Tom Sepezc46d0002015-11-30 15:46:36 -080037typedef void* FPDF_SCHHANDLE;
thestig9067fd62016-11-23 14:10:06 -080038typedef void* FPDF_STRUCTELEMENT;
39typedef void* FPDF_STRUCTTREE;
Tom Sepezc46d0002015-11-30 15:46:36 -080040typedef void* FPDF_TEXTPAGE;
41
42#ifdef PDF_ENABLE_XFA
43typedef void* FPDF_STRINGHANDLE;
44typedef void* FPDF_WIDGET;
45#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070046
47// Basic data types
Tom Sepez9857e202015-05-13 17:09:26 -070048typedef int FPDF_BOOL;
49typedef int FPDF_ERROR;
50typedef unsigned long FPDF_DWORD;
51typedef float FS_FLOAT;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070052
Tom Sepezc46d0002015-11-30 15:46:36 -080053#ifdef PDF_ENABLE_XFA
54typedef void* FPDF_LPVOID;
55typedef void const* FPDF_LPCVOID;
56typedef char const* FPDF_LPCSTR;
57typedef int FPDF_RESULT;
58#endif
59
Bo Xu9114e832014-07-14 13:22:47 -070060// Duplex types
61typedef enum _FPDF_DUPLEXTYPE_ {
Nico Weber9d8ec5a2015-08-04 13:00:21 -070062 DuplexUndefined = 0,
63 Simplex,
64 DuplexFlipShortEdge,
65 DuplexFlipLongEdge
Bo Xu9114e832014-07-14 13:22:47 -070066} FPDF_DUPLEXTYPE;
67
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070068// String types
Tom Sepez9857e202015-05-13 17:09:26 -070069typedef unsigned short FPDF_WCHAR;
70typedef unsigned char const* FPDF_LPCBYTE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072// FPDFSDK may use three types of strings: byte string, wide string (UTF-16LE
73// encoded), and platform dependent string
Tom Sepez9857e202015-05-13 17:09:26 -070074typedef const char* FPDF_BYTESTRING;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075
Dan Sinclair49f88b72015-10-20 15:18:51 -040076// FPDFSDK always uses UTF-16LE encoded wide strings, each character uses 2
77// bytes (except surrogation), with the low byte first.
78typedef const unsigned short* FPDF_WIDESTRING;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070079
Tom Sepezc46d0002015-11-30 15:46:36 -080080#ifdef PDF_ENABLE_XFA
Dan Sinclair49f88b72015-10-20 15:18:51 -040081// Structure for a byte string.
82// Note, a byte string commonly means a UTF-16LE formated string.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083typedef struct _FPDF_BSTR {
Dan Sinclair49f88b72015-10-20 15:18:51 -040084 // String buffer.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070085 char* str;
Dan Sinclair49f88b72015-10-20 15:18:51 -040086 // Length of the string, in bytes.
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087 int len;
Bo Xufdc00a72014-10-28 23:03:33 -070088} FPDF_BSTR;
Tom Sepezc46d0002015-11-30 15:46:36 -080089#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -070090
Dan Sinclair49f88b72015-10-20 15:18:51 -040091// For Windows programmers: In most cases it's OK to treat FPDF_WIDESTRING as a
92// Windows unicode string, however, special care needs to be taken if you
93// expect to process Unicode larger than 0xffff.
94//
95// For Linux/Unix programmers: most compiler/library environments use 4 bytes
96// for a Unicode character, and you have to convert between FPDF_WIDESTRING and
97// system wide string by yourself.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070098typedef const char* FPDF_STRING;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099
Dan Sinclair49f88b72015-10-20 15:18:51 -0400100// Matrix for transformation.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101typedef struct _FS_MATRIX_ {
Dan Sinclair49f88b72015-10-20 15:18:51 -0400102 float a;
103 float b;
104 float c;
105 float d;
106 float e;
107 float f;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700108} FS_MATRIX;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109
Dan Sinclair49f88b72015-10-20 15:18:51 -0400110// Rectangle area(float) in device or page coordinate system.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700111typedef struct _FS_RECTF_ {
Dan Sinclair49f88b72015-10-20 15:18:51 -0400112 // The x-coordinate of the left-top corner.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113 float left;
Dan Sinclair49f88b72015-10-20 15:18:51 -0400114 // The y-coordinate of the left-top corner.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 float top;
Dan Sinclair49f88b72015-10-20 15:18:51 -0400116 // The x-coordinate of the right-bottom corner.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 float right;
Dan Sinclair49f88b72015-10-20 15:18:51 -0400118 // The y-coordinate of the right-bottom corner.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 float bottom;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120} * FS_LPRECTF, FS_RECTF;
Dan Sinclair49f88b72015-10-20 15:18:51 -0400121
122// Const Pointer to FS_RECTF structure.
Tom Sepez9857e202015-05-13 17:09:26 -0700123typedef const FS_RECTF* FS_LPCRECTF;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700124
125#if defined(_WIN32) && defined(FPDFSDK_EXPORTS)
126// On Windows system, functions are exported in a DLL
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127#define DLLEXPORT __declspec(dllexport)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700128#define STDCALL __stdcall
129#else
130#define DLLEXPORT
131#define STDCALL
132#endif
133
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700134// Exported Functions
135#ifdef __cplusplus
136extern "C" {
137#endif
138
139// Function: FPDF_InitLibrary
Tom Sepez9857e202015-05-13 17:09:26 -0700140// Initialize the FPDFSDK library
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700142// None
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700144// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145// Comments:
Lei Zhang6f62d532015-09-23 15:31:44 -0700146// Convenience function to call FPDF_InitLibraryWithConfig() for
147// backwards comatibility purposes.
148DLLEXPORT void STDCALL FPDF_InitLibrary();
149
Dan Sinclair49f88b72015-10-20 15:18:51 -0400150// Process-wide options for initializing the library.
Lei Zhang6f62d532015-09-23 15:31:44 -0700151typedef struct FPDF_LIBRARY_CONFIG_ {
Tom Sepeza72e8e22015-10-07 10:17:53 -0700152 // Version number of the interface. Currently must be 2.
Lei Zhang6f62d532015-09-23 15:31:44 -0700153 int version;
154
155 // Array of paths to scan in place of the defaults when using built-in
156 // FXGE font loading code. The array is terminated by a NULL pointer.
157 // The Array may be NULL itself to use the default paths. May be ignored
158 // entirely depending upon the platform.
159 const char** m_pUserFontPaths;
Tom Sepeza72e8e22015-10-07 10:17:53 -0700160
161 // Version 2.
162
163 // pointer to the v8::Isolate to use, or NULL to force PDFium to create one.
164 void* m_pIsolate;
165
166 // The embedder data slot to use in the v8::Isolate to store PDFium's
167 // per-isolate data. The value needs to be between 0 and
168 // v8::Internals::kNumIsolateDataLots (exclusive). Note that 0 is fine
169 // for most embedders.
170 unsigned int m_v8EmbedderSlot;
Lei Zhang6f62d532015-09-23 15:31:44 -0700171} FPDF_LIBRARY_CONFIG;
172
173// Function: FPDF_InitLibraryWithConfig
174// Initialize the FPDFSDK library
175// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400176// config - configuration information as above.
Lei Zhang6f62d532015-09-23 15:31:44 -0700177// Return value:
178// None.
179// Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180// You have to call this function before you can call any PDF
181// processing functions.
Tom Sepez326a2a72015-11-20 10:47:32 -0800182DLLEXPORT void STDCALL FPDF_InitLibraryWithConfig(
183 const FPDF_LIBRARY_CONFIG* config);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700184
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700185// Function: FPDF_DestroyLibary
Tom Sepez9857e202015-05-13 17:09:26 -0700186// Release all resources allocated by the FPDFSDK library.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700187// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700188// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700189// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700190// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700191// Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700192// You can call this function to release all memory blocks allocated by
193// the library.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400194// After this function is called, you should not call any PDF
195// processing functions.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196DLLEXPORT void STDCALL FPDF_DestroyLibrary();
197
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198// Policy for accessing the local machine time.
199#define FPDF_POLICY_MACHINETIME_ACCESS 0
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700200
201// Function: FPDF_SetSandBoxPolicy
Tom Sepez9857e202015-05-13 17:09:26 -0700202// Set the policy for the sandbox environment.
203// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400204// policy - The specified policy for setting, for example:
205// FPDF_POLICY_MACHINETIME_ACCESS.
206// enable - True to enable, false to disable the policy.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700208// None.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209DLLEXPORT void STDCALL FPDF_SetSandBoxPolicy(FPDF_DWORD policy,
210 FPDF_BOOL enable);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700211
rbpotterdb764702017-01-12 10:31:43 -0800212#if defined(_WIN32)
213#if defined(PDFIUM_PRINT_TEXT_WITH_GDI)
thestigfdb35ff2016-07-18 13:45:44 -0700214// Pointer to a helper function to make |font| with |text| of |text_length|
215// accessible when printing text with GDI. This is useful in sandboxed
216// environments where PDFium's access to GDI may be restricted.
217typedef void (*PDFiumEnsureTypefaceCharactersAccessible)(const LOGFONT* font,
218 const wchar_t* text,
219 size_t text_length);
220
221// Function: FPDF_SetTypefaceAccessibleFunc
222// Set the function pointer that makes GDI fonts available in sandboxed
223// environments. Experimental API.
224// Parameters:
225// func - A function pointer. See description above.
226// Return value:
227// None.
228DLLEXPORT void STDCALL
229FPDF_SetTypefaceAccessibleFunc(PDFiumEnsureTypefaceCharactersAccessible func);
230
231// Function: FPDF_SetPrintTextWithGDI
232// Set whether to use GDI to draw fonts when printing on Windows.
233// Experimental API.
234// Parameters:
235// use_gdi - Set to true to enable printing text with GDI.
236// Return value:
237// None.
238DLLEXPORT void STDCALL FPDF_SetPrintTextWithGDI(FPDF_BOOL use_gdi);
rbpotterdb764702017-01-12 10:31:43 -0800239#endif // PDFIUM_PRINT_TEXT_WITH_GDI
240
241// Function: FPDF_SetPrintPostscriptLevel
242// Set postscript printing level when printing on Windows.
243// Experimental API.
244// Parameters:
245// postscript_level - 0 to disable postscript printing,
246// 2 to print with postscript level 2,
247// 3 to print with postscript level 3.
248// All other values are invalid.
249// Return value:
250// True if successful, false if unsucessful (typically invalid input).
Lei Zhang9162ff82017-02-24 18:22:46 -0800251DLLEXPORT FPDF_BOOL STDCALL
252FPDF_SetPrintPostscriptLevel(FPDF_BOOL postscript_level);
rbpotterdb764702017-01-12 10:31:43 -0800253#endif // defined(_WIN32)
thestigfdb35ff2016-07-18 13:45:44 -0700254
Tom Sepez3c3201f2015-05-20 10:20:35 -0700255// Function: FPDF_LoadDocument
256// Open and load a PDF document.
257// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400258// file_path - Path to the PDF file (including extension).
259// password - A string used as the password for the PDF file.
260// If no password is needed, empty or NULL can be used.
Tom Sepez3c3201f2015-05-20 10:20:35 -0700261// Return value:
262// A handle to the loaded document, or NULL on failure.
263// Comments:
264// Loaded document can be closed by FPDF_CloseDocument().
265// If this function fails, you can use FPDF_GetLastError() to retrieve
266// the reason why it failed.
Tom Sepez9857e202015-05-13 17:09:26 -0700267DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700268 FPDF_BYTESTRING password);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700269
270// Function: FPDF_LoadMemDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700271// Open and load a PDF document from memory.
272// Parameters:
273// data_buf - Pointer to a buffer containing the PDF document.
274// size - Number of bytes in the PDF document.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400275// password - A string used as the password for the PDF file.
276// If no password is needed, empty or NULL can be used.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700277// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400278// A handle to the loaded document, or NULL on failure.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700279// Comments:
Tom Sepez9857e202015-05-13 17:09:26 -0700280// The memory buffer must remain valid when the document is open.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400281// The loaded document can be closed by FPDF_CloseDocument.
Tom Sepez9857e202015-05-13 17:09:26 -0700282// If this function fails, you can use FPDF_GetLastError() to retrieve
Dan Sinclair49f88b72015-10-20 15:18:51 -0400283// the reason why it failed.
Bo Xufdc00a72014-10-28 23:03:33 -0700284// Notes:
Tom Sepezc46d0002015-11-30 15:46:36 -0800285// If PDFium is built with the XFA module, the application should call
286// FPDF_LoadXFA() function after the PDF document loaded to support XFA
287// fields defined in the fpdfformfill.h file.
Tom Sepez9857e202015-05-13 17:09:26 -0700288DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 int size,
290 FPDF_BYTESTRING password);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700291
292// Structure for custom file access.
293typedef struct {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 // File length, in bytes.
295 unsigned long m_FileLen;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700296
Dan Sinclair49f88b72015-10-20 15:18:51 -0400297 // A function pointer for getting a block of data from a specific position.
298 // Position is specified by byte offset from the beginning of the file.
299 // The position and size will never go out of range of the file length.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 // It may be possible for FPDFSDK to call this function multiple times for
Dan Sinclair49f88b72015-10-20 15:18:51 -0400301 // the same position.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 // Return value: should be non-zero if successful, zero for error.
303 int (*m_GetBlock)(void* param,
304 unsigned long position,
305 unsigned char* pBuf,
306 unsigned long size);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700307
Dan Sinclair49f88b72015-10-20 15:18:51 -0400308 // A custom pointer for all implementation specific data. This pointer will
309 // be used as the first parameter to the m_GetBlock callback.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 void* m_Param;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700311} FPDF_FILEACCESS;
312
Tom Sepezc46d0002015-11-30 15:46:36 -0800313#ifdef PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700314/**
315 * @brief Structure for file reading or writing (I/O).
316 *
317 * @note This is a handler and should be implemented by callers.
318 */
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700319typedef struct _FPDF_FILEHANDLER {
320 /**
321 * @brief User-defined data.
322 * @note Callers can use this field to track controls.
323 */
324 FPDF_LPVOID clientData;
325 /**
326 * @brief Callback function to release the current file stream object.
327 *
328 * @param[in] clientData Pointer to user-defined data.
329 *
330 * @return None.
331 */
332 void (*Release)(FPDF_LPVOID clientData);
333 /**
334 * @brief Callback function to retrieve the current file stream size.
335 *
336 * @param[in] clientData Pointer to user-defined data.
337 *
338 * @return Size of file stream.
339 */
340 FPDF_DWORD (*GetSize)(FPDF_LPVOID clientData);
341 /**
342 * @brief Callback function to read data from the current file stream.
343 *
344 * @param[in] clientData Pointer to user-defined data.
345 * @param[in] offset Offset position starts from the beginning of file
346 * stream. This parameter indicates reading position.
347 * @param[in] buffer Memory buffer to store data which are read from
348 * file stream. This parameter should not be <b>NULL</b>.
349 * @param[in] size Size of data which should be read from file
350 * stream, in bytes. The buffer indicated by the parameter <i>buffer</i>
351 * should be enough to store specified data.
352 *
353 * @return 0 for success, other value for failure.
354 */
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500355 FPDF_RESULT (*ReadBlock)(FPDF_LPVOID clientData,
356 FPDF_DWORD offset,
357 FPDF_LPVOID buffer,
358 FPDF_DWORD size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359 /**
360 * @brief Callback function to write data into the current file stream.
361 *
362 * @param[in] clientData Pointer to user-defined data.
363 * @param[in] offset Offset position starts from the beginning of file
364 * stream. This parameter indicates writing position.
365 * @param[in] buffer Memory buffer contains data which is written into
366 * file stream. This parameter should not be <b>NULL</b>.
367 * @param[in] size Size of data which should be written into file
368 * stream, in bytes.
369 *
370 * @return 0 for success, other value for failure.
371 */
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500372 FPDF_RESULT (*WriteBlock)(FPDF_LPVOID clientData,
373 FPDF_DWORD offset,
374 FPDF_LPCVOID buffer,
375 FPDF_DWORD size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376 /**
377 * @brief Callback function to flush all internal accessing buffers.
378 *
379 * @param[in] clientData Pointer to user-defined data.
380 *
381 * @return 0 for success, other value for failure.
382 */
383 FPDF_RESULT (*Flush)(FPDF_LPVOID clientData);
384 /**
385 * @brief Callback function to change file size.
386 *
387 * @details This function is called under writing mode usually. Implementer
388 * can determine whether to realize it based on application requests.
389 *
390 * @param[in] clientData Pointer to user-defined data.
391 * @param[in] size New size of file stream, in bytes.
392 *
393 * @return 0 for success, other value for failure.
394 */
395 FPDF_RESULT (*Truncate)(FPDF_LPVOID clientData, FPDF_DWORD size);
Bo Xufdc00a72014-10-28 23:03:33 -0700396} FPDF_FILEHANDLER, *FPDF_LPFILEHANDLER;
397
Tom Sepezc46d0002015-11-30 15:46:36 -0800398#endif
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700399// Function: FPDF_LoadCustomDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700400// Load PDF document from a custom access descriptor.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400402// pFileAccess - A structure for accessing the file.
Tom Sepez9857e202015-05-13 17:09:26 -0700403// password - Optional password for decrypting the PDF file.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700404// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400405// A handle to the loaded document, or NULL on failure.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700406// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400407// The application must keep the file resources valid until the PDF
408// document is closed.
Bo Xufdc00a72014-10-28 23:03:33 -0700409//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400410// The loaded document can be closed with FPDF_CloseDocument.
411// Notes:
Tom Sepezc46d0002015-11-30 15:46:36 -0800412// If PDFium is built with the XFA module, the application should call
413// FPDF_LoadXFA() function after the PDF document loaded to support XFA
414// fields defined in the fpdfformfill.h file.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415DLLEXPORT FPDF_DOCUMENT STDCALL
416FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700417
418// Function: FPDF_GetFileVersion
Dan Sinclair49f88b72015-10-20 15:18:51 -0400419// Get the file version of the given PDF document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700420// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400421// doc - Handle to a document.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422// fileVersion - The PDF file version. File version: 14 for 1.4, 15
Dan Sinclair49f88b72015-10-20 15:18:51 -0400423// for 1.5, ...
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700424// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400425// True if succeeds, false otherwise.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700426// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400427// If the document was created by FPDF_CreateNewDocument,
428// then this function will always fail.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
430 int* fileVersion);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700431
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432#define FPDF_ERR_SUCCESS 0 // No error.
433#define FPDF_ERR_UNKNOWN 1 // Unknown error.
434#define FPDF_ERR_FILE 2 // File not found or could not be opened.
435#define FPDF_ERR_FORMAT 3 // File not in PDF format or corrupted.
436#define FPDF_ERR_PASSWORD 4 // Password required or incorrect password.
437#define FPDF_ERR_SECURITY 5 // Unsupported security scheme.
438#define FPDF_ERR_PAGE 6 // Page not found or content error.
Tom Sepezc46d0002015-11-30 15:46:36 -0800439#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440#define FPDF_ERR_XFALOAD 7 // Load XFA error.
441#define FPDF_ERR_XFALAYOUT 8 // Layout XFA error.
Tom Sepezc46d0002015-11-30 15:46:36 -0800442#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700443
444// Function: FPDF_GetLastError
Dan Sinclair49f88b72015-10-20 15:18:51 -0400445// Get last error code when a function fails.
Tom Sepez9857e202015-05-13 17:09:26 -0700446// Parameters:
447// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400449// A 32-bit integer indicating error code as defined above.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450// Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451// If the previous SDK call succeeded, the return value of this
Dan Sinclair49f88b72015-10-20 15:18:51 -0400452// function is not defined.
Tom Sepez9857e202015-05-13 17:09:26 -0700453DLLEXPORT unsigned long STDCALL FPDF_GetLastError();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454
455// Function: FPDF_GetDocPermission
Tom Sepez9857e202015-05-13 17:09:26 -0700456// Get file permission flags of the document.
457// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400458// document - Handle to a document. Returned by FPDF_LoadDocument.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700459// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400460// A 32-bit integer indicating permission flags. Please refer to the
461// PDF Reference for detailed descriptions. If the document is not
462// protected, 0xffffffff will be returned.
Tom Sepez9857e202015-05-13 17:09:26 -0700463DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700464
Bo Xuc5cab022014-09-19 19:16:31 -0700465// Function: FPDF_GetSecurityHandlerRevision
Dan Sinclair49f88b72015-10-20 15:18:51 -0400466// Get the revision for the security handler.
Bo Xuc5cab022014-09-19 19:16:31 -0700467// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400468// document - Handle to a document. Returned by FPDF_LoadDocument.
Bo Xuc5cab022014-09-19 19:16:31 -0700469// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400470// The security handler revision number. Please refer to the PDF
471// Reference for a detailed description. If the document is not
472// protected, -1 will be returned.
Bo Xuc5cab022014-09-19 19:16:31 -0700473DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document);
474
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700475// Function: FPDF_GetPageCount
Dan Sinclair49f88b72015-10-20 15:18:51 -0400476// Get total number of pages in the document.
Tom Sepez9857e202015-05-13 17:09:26 -0700477// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400478// document - Handle to document. Returned by FPDF_LoadDocument.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700479// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700480// Total number of pages in the document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700481DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document);
482
483// Function: FPDF_LoadPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400484// Load a page inside the document.
Tom Sepez9857e202015-05-13 17:09:26 -0700485// Parameters:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486// document - Handle to document. Returned by FPDF_LoadDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700487// page_index - Index number of the page. 0 for the first page.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700488// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400489// A handle to the loaded page, or NULL if page load fails.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700490// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400491// The loaded page can be rendered to devices using FPDF_RenderPage.
492// The loaded page can be closed using FPDF_ClosePage.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
494 int page_index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700495
496// Function: FPDF_GetPageWidth
Tom Sepez9857e202015-05-13 17:09:26 -0700497// Get page width.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400499// page - Handle to the page. Returned by FPDF_LoadPage.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700500// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700501// Page width (excluding non-displayable area) measured in points.
502// One point is 1/72 inch (around 0.3528 mm).
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700503DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page);
504
505// Function: FPDF_GetPageHeight
Tom Sepez9857e202015-05-13 17:09:26 -0700506// Get page height.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400508// page - Handle to the page. Returned by FPDF_LoadPage.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700509// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700510// Page height (excluding non-displayable area) measured in points.
511// One point is 1/72 inch (around 0.3528 mm)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700512DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page);
513
514// Function: FPDF_GetPageSizeByIndex
Dan Sinclair49f88b72015-10-20 15:18:51 -0400515// Get the size of the page at the given index.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700516// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400517// document - Handle to document. Returned by FPDF_LoadDocument.
Tom Sepez9857e202015-05-13 17:09:26 -0700518// page_index - Page index, zero for the first page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400519// width - Pointer to a double to receive the page width
520// (in points).
521// height - Pointer to a double to receive the page height
522// (in points).
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700524// Non-zero for success. 0 for error (document or page not found).
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
526 int page_index,
527 double* width,
528 double* height);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700529
Dan Sinclair49f88b72015-10-20 15:18:51 -0400530// Page rendering flags. They can be combined with bit-wise OR.
531//
532// Set if annotations are to be rendered.
533#define FPDF_ANNOT 0x01
534// Set if using text rendering optimized for LCD display.
535#define FPDF_LCD_TEXT 0x02
536// Don't use the native text output available on some platforms
537#define FPDF_NO_NATIVETEXT 0x04
538// Grayscale output.
539#define FPDF_GRAYSCALE 0x08
540// Set if you want to get some debug info.
541#define FPDF_DEBUG_INFO 0x80
542// Set if you don't want to catch exceptions.
543#define FPDF_NO_CATCH 0x100
544// Limit image cache size.
545#define FPDF_RENDER_LIMITEDIMAGECACHE 0x200
546// Always use halftone for image stretching.
547#define FPDF_RENDER_FORCEHALFTONE 0x400
548// Render for printing.
549#define FPDF_PRINTING 0x800
550// Set to disable anti-aliasing on text.
551#define FPDF_RENDER_NO_SMOOTHTEXT 0x1000
552// Set to disable anti-aliasing on images.
553#define FPDF_RENDER_NO_SMOOTHIMAGE 0x2000
554// Set to disable anti-aliasing on paths.
555#define FPDF_RENDER_NO_SMOOTHPATH 0x4000
556// Set whether to render in a reverse Byte order, this flag is only used when
557// rendering to a bitmap.
558#define FPDF_REVERSE_BYTE_ORDER 0x10
559
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560#ifdef _WIN32
561// Function: FPDF_RenderPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400562// Render contents of a page to a device (screen, bitmap, or printer).
563// This function is only supported on Windows.
Tom Sepez9857e202015-05-13 17:09:26 -0700564// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400565// dc - Handle to the device context.
566// page - Handle to the page. Returned by FPDF_LoadPage.
567// start_x - Left pixel position of the display area in
568// device coordinates.
569// start_y - Top pixel position of the display area in device
570// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700571// size_x - Horizontal size (in pixels) for displaying the page.
572// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400573// rotate - Page orientation:
574// 0 (normal)
575// 1 (rotated 90 degrees clockwise)
576// 2 (rotated 180 degrees)
577// 3 (rotated 90 degrees counter-clockwise)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578// flags - 0 for normal display, or combination of flags
Dan Sinclair49f88b72015-10-20 15:18:51 -0400579// defined above.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700580// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700581// None.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc,
583 FPDF_PAGE page,
584 int start_x,
585 int start_y,
586 int size_x,
587 int size_y,
588 int rotate,
589 int flags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590#endif
591
592// Function: FPDF_RenderPageBitmap
Dan Sinclair49f88b72015-10-20 15:18:51 -0400593// Render contents of a page to a device independent bitmap.
Tom Sepez9857e202015-05-13 17:09:26 -0700594// Parameters:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595// bitmap - Handle to the device independent bitmap (as the
Dan Sinclair49f88b72015-10-20 15:18:51 -0400596// output buffer). The bitmap handle can be created
597// by FPDFBitmap_Create.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700598// page - Handle to the page. Returned by FPDF_LoadPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400599// start_x - Left pixel position of the display area in
600// bitmap coordinates.
601// start_y - Top pixel position of the display area in bitmap
602// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700603// size_x - Horizontal size (in pixels) for displaying the page.
604// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400605// rotate - Page orientation:
606// 0 (normal)
607// 1 (rotated 90 degrees clockwise)
608// 2 (rotated 180 degrees)
609// 3 (rotated 90 degrees counter-clockwise)
thestiga78ba602016-11-23 15:25:48 -0800610// flags - 0 for normal display, or combination of the Page
611// Rendering flags defined above. With the FPDF_ANNOT
612// flag, it renders all annotations that do not require
613// user-interaction, which are all annotations except
614// widget and popup annotations.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700616// None.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700617DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
618 FPDF_PAGE page,
619 int start_x,
620 int start_y,
621 int size_x,
622 int size_y,
623 int rotate,
624 int flags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625
thestiga78ba602016-11-23 15:25:48 -0800626// Function: FPDF_RenderPageBitmapWithMatrix
627// Render contents of a page to a device independent bitmap.
628// Parameters:
629// bitmap - Handle to the device independent bitmap (as the
630// output buffer). The bitmap handle can be created
631// by FPDFBitmap_Create.
632// page - Handle to the page. Returned by FPDF_LoadPage
633// matrix - The transform matrix.
634// clipping - The rect to clip to.
635// flags - 0 for normal display, or combination of the Page
636// Rendering flags defined above. With the FPDF_ANNOT
637// flag, it renders all annotations that do not require
638// user-interaction, which are all annotations except
639// widget and popup annotations.
640// Return value:
641// None.
642DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
643 FPDF_PAGE page,
644 const FS_MATRIX* matrix,
645 const FS_RECTF* clipping,
646 int flags);
647
Cary Clark399be5b2016-03-14 16:51:29 -0400648#ifdef _SKIA_SUPPORT_
649DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page,
650 int size_x,
651 int size_y);
652#endif
653
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654// Function: FPDF_ClosePage
Tom Sepez9857e202015-05-13 17:09:26 -0700655// Close a loaded PDF page.
656// Parameters:
657// page - Handle to the loaded page.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700659// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page);
661
662// Function: FPDF_CloseDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700663// Close a loaded PDF document.
664// Parameters:
665// document - Handle to the loaded document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700666// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700667// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document);
669
670// Function: FPDF_DeviceToPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400671// Convert the screen coordinates of a point to page coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400673// page - Handle to the page. Returned by FPDF_LoadPage.
674// start_x - Left pixel position of the display area in
675// device coordinates.
676// start_y - Top pixel position of the display area in device
677// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700678// size_x - Horizontal size (in pixels) for displaying the page.
679// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400680// rotate - Page orientation:
681// 0 (normal)
682// 1 (rotated 90 degrees clockwise)
683// 2 (rotated 180 degrees)
684// 3 (rotated 90 degrees counter-clockwise)
685// device_x - X value in device coordinates to be converted.
686// device_y - Y value in device coordinates to be converted.
687// page_x - A pointer to a double receiving the converted X
688// value in page coordinates.
689// page_y - A pointer to a double receiving the converted Y
690// value in page coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700691// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700692// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700693// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400694// The page coordinate system has its origin at the left-bottom corner
695// of the page, with the X-axis on the bottom going to the right, and
696// the Y-axis on the left side going up.
697//
698// NOTE: this coordinate system can be altered when you zoom, scroll,
699// or rotate a page, however, a point on the page should always have
Tom Sepez9857e202015-05-13 17:09:26 -0700700// the same coordinate values in the page coordinate system.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702// The device coordinate system is device dependent. For screen device,
Dan Sinclair49f88b72015-10-20 15:18:51 -0400703// its origin is at the left-top corner of the window. However this
704// origin can be altered by the Windows coordinate transformation
705// utilities.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700706//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400707// You must make sure the start_x, start_y, size_x, size_y
708// and rotate parameters have exactly same values as you used in
709// the FPDF_RenderPage() function call.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700710DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
711 int start_x,
712 int start_y,
713 int size_x,
714 int size_y,
715 int rotate,
716 int device_x,
717 int device_y,
718 double* page_x,
719 double* page_y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720
721// Function: FPDF_PageToDevice
Dan Sinclair49f88b72015-10-20 15:18:51 -0400722// Convert the page coordinates of a point to screen coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700723// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400724// page - Handle to the page. Returned by FPDF_LoadPage.
725// start_x - Left pixel position of the display area in
726// device coordinates.
727// start_y - Top pixel position of the display area in device
728// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700729// size_x - Horizontal size (in pixels) for displaying the page.
730// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400731// rotate - Page orientation:
732// 0 (normal)
733// 1 (rotated 90 degrees clockwise)
734// 2 (rotated 180 degrees)
735// 3 (rotated 90 degrees counter-clockwise)
736// page_x - X value in page coordinates.
737// page_y - Y value in page coordinate.
738// device_x - A pointer to an integer receiving the result X
739// value in device coordinates.
740// device_y - A pointer to an integer receiving the result Y
741// value in device coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700743// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400745// See comments for FPDF_DeviceToPage().
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
747 int start_x,
748 int start_y,
749 int size_x,
750 int size_y,
751 int rotate,
752 double page_x,
753 double page_y,
754 int* device_x,
755 int* device_y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756
757// Function: FPDFBitmap_Create
Dan Sinclair49f88b72015-10-20 15:18:51 -0400758// Create a device independent bitmap (FXDIB).
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400760// width - The number of pixels in width for the bitmap.
761// Must be greater than 0.
762// height - The number of pixels in height for the bitmap.
763// Must be greater than 0.
764// alpha - A flag indicating whether the alpha channel is used.
765// Non-zero for using alpha, zero for not using.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400767// The created bitmap handle, or NULL if a parameter error or out of
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768// memory.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400770// The bitmap always uses 4 bytes per pixel. The first byte is always
771// double word aligned.
772//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700773// The byte order is BGRx (the last byte unused if no alpha channel) or
774// BGRA.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400776// The pixels in a horizontal line are stored side by side, with the
777// left most pixel stored first (with lower memory address).
778// Each line uses width * 4 bytes.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700779//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400780// Lines are stored one after another, with the top most line stored
781// first. There is no gap between adjacent lines.
Tom Sepez9857e202015-05-13 17:09:26 -0700782//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783// This function allocates enough memory for holding all pixels in the
Dan Sinclair49f88b72015-10-20 15:18:51 -0400784// bitmap, but it doesn't initialize the buffer. Applications can use
785// FPDFBitmap_FillRect to fill the bitmap using any color.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700786DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
787 int height,
788 int alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700789
790// More DIB formats
Dan Sinclair49f88b72015-10-20 15:18:51 -0400791// Gray scale bitmap, one byte per pixel.
792#define FPDFBitmap_Gray 1
793// 3 bytes per pixel, byte order: blue, green, red.
794#define FPDFBitmap_BGR 2
795// 4 bytes per pixel, byte order: blue, green, red, unused.
796#define FPDFBitmap_BGRx 3
797// 4 bytes per pixel, byte order: blue, green, red, alpha.
798#define FPDFBitmap_BGRA 4
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700799
800// Function: FPDFBitmap_CreateEx
Dan Sinclair49f88b72015-10-20 15:18:51 -0400801// Create a device independent bitmap (FXDIB)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700802// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400803// width - The number of pixels in width for the bitmap.
804// Must be greater than 0.
805// height - The number of pixels in height for the bitmap.
806// Must be greater than 0.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807// format - A number indicating for bitmap format, as defined
Dan Sinclair49f88b72015-10-20 15:18:51 -0400808// above.
809// first_scan - A pointer to the first byte of the first line if
810// using an external buffer. If this parameter is NULL,
811// then the a new buffer will be created.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812// stride - Number of bytes for each scan line, for external
Dan Sinclair49f88b72015-10-20 15:18:51 -0400813// buffer only.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700814// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400815// The bitmap handle, or NULL if parameter error or out of memory.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400817// Similar to FPDFBitmap_Create function, but allows for more formats
818// and an external buffer is supported. The bitmap created by this
819// function can be used in any place that a FPDF_BITMAP handle is
Tom Sepez9857e202015-05-13 17:09:26 -0700820// required.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400822// If an external buffer is used, then the application should destroy
823// the buffer by itself. FPDFBitmap_Destroy function will not destroy
824// the buffer.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700825DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width,
826 int height,
827 int format,
828 void* first_scan,
829 int stride);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700830
831// Function: FPDFBitmap_FillRect
Dan Sinclair49f88b72015-10-20 15:18:51 -0400832// Fill a rectangle in a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700833// Parameters:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700834// bitmap - The handle to the bitmap. Returned by
Dan Sinclair49f88b72015-10-20 15:18:51 -0400835// FPDFBitmap_Create.
836// left - The left position. Starting from 0 at the
837// left-most pixel.
838// top - The top position. Starting from 0 at the
839// top-most line.
840// width - Width in pixels to be filled.
841// height - Height in pixels to be filled.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700842// color - A 32-bit value specifing the color, in 8888 ARGB
Dan Sinclair49f88b72015-10-20 15:18:51 -0400843// format.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700844// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700845// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700846// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400847// This function sets the color and (optionally) alpha value in the
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700848// specified region of the bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700849//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400850// NOTE: If the alpha channel is used, this function does NOT
851// composite the background with the source color, instead the
852// background will be replaced by the source color and the alpha.
853//
854// If the alpha channel is not used, the alpha parameter is ignored.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700855DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
856 int left,
857 int top,
858 int width,
859 int height,
860 FPDF_DWORD color);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700861
862// Function: FPDFBitmap_GetBuffer
Dan Sinclair49f88b72015-10-20 15:18:51 -0400863// Get data buffer of a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700864// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400865// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700866// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700867// The pointer to the first byte of the bitmap buffer.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700868// Comments:
Tom Sepez9857e202015-05-13 17:09:26 -0700869// The stride may be more than width * number of bytes per pixel
Dan Sinclair49f88b72015-10-20 15:18:51 -0400870//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700871// Applications can use this function to get the bitmap buffer pointer,
Dan Sinclair49f88b72015-10-20 15:18:51 -0400872// then manipulate any color and/or alpha values for any pixels in the
873// bitmap.
874//
875// The data is in BGRA format. Where the A maybe unused if alpha was
876// not specified.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700877DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap);
878
879// Function: FPDFBitmap_GetWidth
Dan Sinclair49f88b72015-10-20 15:18:51 -0400880// Get width of a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700881// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400882// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700883// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400884// The width of the bitmap in pixels.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700885DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap);
886
887// Function: FPDFBitmap_GetHeight
Dan Sinclair49f88b72015-10-20 15:18:51 -0400888// Get height of a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700889// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400890// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700891// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400892// The height of the bitmap in pixels.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700893DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap);
894
895// Function: FPDFBitmap_GetStride
Dan Sinclair49f88b72015-10-20 15:18:51 -0400896// Get number of bytes for each line in the bitmap buffer.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700897// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400898// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700899// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400900// The number of bytes for each line in the bitmap buffer.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700901// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400902// The stride may be more than width * number of bytes per pixel.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700903DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap);
904
905// Function: FPDFBitmap_Destroy
Dan Sinclair49f88b72015-10-20 15:18:51 -0400906// Destroy a bitmap and release all related buffers.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700907// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400908// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700909// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700910// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700911// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400912// This function will not destroy any external buffers provided when
913// the bitmap was created.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700914DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap);
915
916// Function: FPDF_VIEWERREF_GetPrintScaling
Tom Sepez9857e202015-05-13 17:09:26 -0700917// Whether the PDF document prefers to be scaled or not.
918// Parameters:
919// document - Handle to the loaded document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700920// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700921// None.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700922DLLEXPORT FPDF_BOOL STDCALL
923FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700924
Bo Xu9114e832014-07-14 13:22:47 -0700925// Function: FPDF_VIEWERREF_GetNumCopies
Tom Sepez9857e202015-05-13 17:09:26 -0700926// Returns the number of copies to be printed.
Bo Xu9114e832014-07-14 13:22:47 -0700927// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700928// document - Handle to the loaded document.
Bo Xu9114e832014-07-14 13:22:47 -0700929// Return value:
930// The number of copies to be printed.
Bo Xu9114e832014-07-14 13:22:47 -0700931DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document);
932
933// Function: FPDF_VIEWERREF_GetPrintPageRange
Tom Sepez9857e202015-05-13 17:09:26 -0700934// Page numbers to initialize print dialog box when file is printed.
Bo Xu9114e832014-07-14 13:22:47 -0700935// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700936// document - Handle to the loaded document.
Bo Xu9114e832014-07-14 13:22:47 -0700937// Return value:
938// The print page range to be used for printing.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700939DLLEXPORT FPDF_PAGERANGE STDCALL
940FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document);
Bo Xu9114e832014-07-14 13:22:47 -0700941
942// Function: FPDF_VIEWERREF_GetDuplex
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700943// Returns the paper handling option to be used when printing from
Dan Sinclair49f88b72015-10-20 15:18:51 -0400944// the print dialog.
Bo Xu9114e832014-07-14 13:22:47 -0700945// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700946// document - Handle to the loaded document.
Bo Xu9114e832014-07-14 13:22:47 -0700947// Return value:
948// The paper handling option to be used when printing.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700949DLLEXPORT FPDF_DUPLEXTYPE STDCALL
950FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document);
Bo Xu9114e832014-07-14 13:22:47 -0700951
thestig04bebfe2016-11-04 16:07:25 -0700952// Function: FPDF_VIEWERREF_GetName
953// Gets the contents for a viewer ref, with a given key. The value must
954// be of type "name".
955// Parameters:
956// document - Handle to the loaded document.
957// key - Name of the key in the viewer pref dictionary.
958// buffer - A string to write the contents of the key to.
959// length - Length of the buffer.
960// Return value:
961// The number of bytes in the contents, including the NULL terminator.
962// Thus if the return value is 0, then that indicates an error, such
963// as when |document| is invalid or |buffer| is NULL. If |length| is
964// less than the returned length, or |buffer| is NULL, |buffer| will
965// not be modified.
966DLLEXPORT unsigned long STDCALL FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document,
967 FPDF_BYTESTRING key,
968 char* buffer,
969 unsigned long length);
970
Bo Xu4d62b6b2015-01-10 22:52:59 -0800971// Function: FPDF_CountNamedDests
Tom Sepez9857e202015-05-13 17:09:26 -0700972// Get the count of named destinations in the PDF document.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800973// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700974// document - Handle to a document
Bo Xu4d62b6b2015-01-10 22:52:59 -0800975// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700976// The count of named destinations.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800977DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document);
978
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700979// Function: FPDF_GetNamedDestByName
Dan Sinclair49f88b72015-10-20 15:18:51 -0400980// Get a the destination handle for the given name.
Tom Sepez9857e202015-05-13 17:09:26 -0700981// Parameters:
982// document - Handle to the loaded document.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400983// name - The name of a destination.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700984// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400985// The handle to the destination.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700986DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
987 FPDF_BYTESTRING name);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700988
Bo Xu4d62b6b2015-01-10 22:52:59 -0800989// Function: FPDF_GetNamedDest
Dan Sinclair49f88b72015-10-20 15:18:51 -0400990// Get the named destination by index.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800991// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700992// document - Handle to a document
Dan Sinclair49f88b72015-10-20 15:18:51 -0400993// index - The index of a named destination.
994// buffer - The buffer to store the destination name,
995// used as wchar_t*.
996// buflen [in/out] - Size of the buffer in bytes on input,
997// length of the result in bytes on output
998// or -1 if the buffer is too small.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800999// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -04001000// The destination handle for a given index, or NULL if there is no
1001// named destination corresponding to |index|.
Bo Xu4d62b6b2015-01-10 22:52:59 -08001002// Comments:
Tom Sepez9857e202015-05-13 17:09:26 -07001003// Call this function twice to get the name of the named destination:
Dan Sinclair49f88b72015-10-20 15:18:51 -04001004// 1) First time pass in |buffer| as NULL and get buflen.
1005// 2) Second time pass in allocated |buffer| and buflen to retrieve
1006// |buffer|, which should be used as wchar_t*.
Bo Xu4d62b6b2015-01-10 22:52:59 -08001007//
Dan Sinclair49f88b72015-10-20 15:18:51 -04001008// If buflen is not sufficiently large, it will be set to -1 upon
1009// return.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001010DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
1011 int index,
1012 void* buffer,
1013 long* buflen);
Bo Xu4d62b6b2015-01-10 22:52:59 -08001014
Tom Sepezc46d0002015-11-30 15:46:36 -08001015#ifdef PDF_ENABLE_XFA
Tom Sepez9857e202015-05-13 17:09:26 -07001016// Function: FPDF_BStr_Init
1017// Helper function to initialize a byte string.
Bo Xufdc00a72014-10-28 23:03:33 -07001018DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Init(FPDF_BSTR* str);
1019
Tom Sepez9857e202015-05-13 17:09:26 -07001020// Function: FPDF_BStr_Set
1021// Helper function to set string data.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001022DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Set(FPDF_BSTR* str,
1023 FPDF_LPCSTR bstr,
1024 int length);
Bo Xufdc00a72014-10-28 23:03:33 -07001025
Tom Sepez9857e202015-05-13 17:09:26 -07001026// Function: FPDF_BStr_Clear
1027// Helper function to clear a byte string.
Bo Xufdc00a72014-10-28 23:03:33 -07001028DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Clear(FPDF_BSTR* str);
Tom Sepezc46d0002015-11-30 15:46:36 -08001029#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -07001030
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001031#ifdef __cplusplus
Tom Sepez9857e202015-05-13 17:09:26 -07001032}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001033#endif
1034
Tom Sepez9857e202015-05-13 17:09:26 -07001035#endif // PUBLIC_FPDFVIEW_H_