blob: 13e4f1f5f1e0df504b70d9bf181c44d987564350 [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 Zhangd1c9b452017-05-05 17:21:36 -0700251DLLEXPORT FPDF_BOOL STDCALL FPDF_SetPrintPostscriptLevel(int postscript_level);
rbpotterdb764702017-01-12 10:31:43 -0800252#endif // defined(_WIN32)
thestigfdb35ff2016-07-18 13:45:44 -0700253
Tom Sepez3c3201f2015-05-20 10:20:35 -0700254// Function: FPDF_LoadDocument
255// Open and load a PDF document.
256// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400257// file_path - Path to the PDF file (including extension).
258// password - A string used as the password for the PDF file.
259// If no password is needed, empty or NULL can be used.
Tom Sepez3c3201f2015-05-20 10:20:35 -0700260// Return value:
261// A handle to the loaded document, or NULL on failure.
262// Comments:
263// Loaded document can be closed by FPDF_CloseDocument().
264// If this function fails, you can use FPDF_GetLastError() to retrieve
265// the reason why it failed.
Tom Sepez9857e202015-05-13 17:09:26 -0700266DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267 FPDF_BYTESTRING password);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700268
269// Function: FPDF_LoadMemDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700270// Open and load a PDF document from memory.
271// Parameters:
272// data_buf - Pointer to a buffer containing the PDF document.
273// size - Number of bytes in the PDF document.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400274// password - A string used as the password for the PDF file.
275// If no password is needed, empty or NULL can be used.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400277// A handle to the loaded document, or NULL on failure.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700278// Comments:
Tom Sepez9857e202015-05-13 17:09:26 -0700279// The memory buffer must remain valid when the document is open.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400280// The loaded document can be closed by FPDF_CloseDocument.
Tom Sepez9857e202015-05-13 17:09:26 -0700281// If this function fails, you can use FPDF_GetLastError() to retrieve
Dan Sinclair49f88b72015-10-20 15:18:51 -0400282// the reason why it failed.
Bo Xufdc00a72014-10-28 23:03:33 -0700283// Notes:
Tom Sepezc46d0002015-11-30 15:46:36 -0800284// If PDFium is built with the XFA module, the application should call
285// FPDF_LoadXFA() function after the PDF document loaded to support XFA
286// fields defined in the fpdfformfill.h file.
Tom Sepez9857e202015-05-13 17:09:26 -0700287DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288 int size,
289 FPDF_BYTESTRING password);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700290
291// Structure for custom file access.
292typedef struct {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293 // File length, in bytes.
294 unsigned long m_FileLen;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700295
Dan Sinclair49f88b72015-10-20 15:18:51 -0400296 // A function pointer for getting a block of data from a specific position.
297 // Position is specified by byte offset from the beginning of the file.
298 // The position and size will never go out of range of the file length.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299 // It may be possible for FPDFSDK to call this function multiple times for
Dan Sinclair49f88b72015-10-20 15:18:51 -0400300 // the same position.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301 // Return value: should be non-zero if successful, zero for error.
302 int (*m_GetBlock)(void* param,
303 unsigned long position,
304 unsigned char* pBuf,
305 unsigned long size);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700306
Dan Sinclair49f88b72015-10-20 15:18:51 -0400307 // A custom pointer for all implementation specific data. This pointer will
308 // be used as the first parameter to the m_GetBlock callback.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 void* m_Param;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700310} FPDF_FILEACCESS;
311
Tom Sepezc46d0002015-11-30 15:46:36 -0800312#ifdef PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -0700313/**
314 * @brief Structure for file reading or writing (I/O).
315 *
316 * @note This is a handler and should be implemented by callers.
317 */
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318typedef struct _FPDF_FILEHANDLER {
319 /**
320 * @brief User-defined data.
321 * @note Callers can use this field to track controls.
322 */
323 FPDF_LPVOID clientData;
324 /**
325 * @brief Callback function to release the current file stream object.
326 *
327 * @param[in] clientData Pointer to user-defined data.
328 *
329 * @return None.
330 */
331 void (*Release)(FPDF_LPVOID clientData);
332 /**
333 * @brief Callback function to retrieve the current file stream size.
334 *
335 * @param[in] clientData Pointer to user-defined data.
336 *
337 * @return Size of file stream.
338 */
339 FPDF_DWORD (*GetSize)(FPDF_LPVOID clientData);
340 /**
341 * @brief Callback function to read data from the current file stream.
342 *
343 * @param[in] clientData Pointer to user-defined data.
344 * @param[in] offset Offset position starts from the beginning of file
345 * stream. This parameter indicates reading position.
346 * @param[in] buffer Memory buffer to store data which are read from
347 * file stream. This parameter should not be <b>NULL</b>.
348 * @param[in] size Size of data which should be read from file
349 * stream, in bytes. The buffer indicated by the parameter <i>buffer</i>
350 * should be enough to store specified data.
351 *
352 * @return 0 for success, other value for failure.
353 */
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500354 FPDF_RESULT (*ReadBlock)(FPDF_LPVOID clientData,
355 FPDF_DWORD offset,
356 FPDF_LPVOID buffer,
357 FPDF_DWORD size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358 /**
359 * @brief Callback function to write data into the current file stream.
360 *
361 * @param[in] clientData Pointer to user-defined data.
362 * @param[in] offset Offset position starts from the beginning of file
363 * stream. This parameter indicates writing position.
364 * @param[in] buffer Memory buffer contains data which is written into
365 * file stream. This parameter should not be <b>NULL</b>.
366 * @param[in] size Size of data which should be written into file
367 * stream, in bytes.
368 *
369 * @return 0 for success, other value for failure.
370 */
Dan Sinclair3ebd1212016-03-09 09:59:23 -0500371 FPDF_RESULT (*WriteBlock)(FPDF_LPVOID clientData,
372 FPDF_DWORD offset,
373 FPDF_LPCVOID buffer,
374 FPDF_DWORD size);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 /**
376 * @brief Callback function to flush all internal accessing buffers.
377 *
378 * @param[in] clientData Pointer to user-defined data.
379 *
380 * @return 0 for success, other value for failure.
381 */
382 FPDF_RESULT (*Flush)(FPDF_LPVOID clientData);
383 /**
384 * @brief Callback function to change file size.
385 *
386 * @details This function is called under writing mode usually. Implementer
387 * can determine whether to realize it based on application requests.
388 *
389 * @param[in] clientData Pointer to user-defined data.
390 * @param[in] size New size of file stream, in bytes.
391 *
392 * @return 0 for success, other value for failure.
393 */
394 FPDF_RESULT (*Truncate)(FPDF_LPVOID clientData, FPDF_DWORD size);
Bo Xufdc00a72014-10-28 23:03:33 -0700395} FPDF_FILEHANDLER, *FPDF_LPFILEHANDLER;
396
Tom Sepezc46d0002015-11-30 15:46:36 -0800397#endif
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398// Function: FPDF_LoadCustomDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700399// Load PDF document from a custom access descriptor.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700400// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400401// pFileAccess - A structure for accessing the file.
Tom Sepez9857e202015-05-13 17:09:26 -0700402// password - Optional password for decrypting the PDF file.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700403// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400404// A handle to the loaded document, or NULL on failure.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700405// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400406// The application must keep the file resources valid until the PDF
407// document is closed.
Bo Xufdc00a72014-10-28 23:03:33 -0700408//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400409// The loaded document can be closed with FPDF_CloseDocument.
410// Notes:
Tom Sepezc46d0002015-11-30 15:46:36 -0800411// If PDFium is built with the XFA module, the application should call
412// FPDF_LoadXFA() function after the PDF document loaded to support XFA
413// fields defined in the fpdfformfill.h file.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414DLLEXPORT FPDF_DOCUMENT STDCALL
415FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700416
417// Function: FPDF_GetFileVersion
Dan Sinclair49f88b72015-10-20 15:18:51 -0400418// Get the file version of the given PDF document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700419// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400420// doc - Handle to a document.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421// fileVersion - The PDF file version. File version: 14 for 1.4, 15
Dan Sinclair49f88b72015-10-20 15:18:51 -0400422// for 1.5, ...
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700423// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400424// True if succeeds, false otherwise.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700425// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400426// If the document was created by FPDF_CreateNewDocument,
427// then this function will always fail.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc,
429 int* fileVersion);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431#define FPDF_ERR_SUCCESS 0 // No error.
432#define FPDF_ERR_UNKNOWN 1 // Unknown error.
433#define FPDF_ERR_FILE 2 // File not found or could not be opened.
434#define FPDF_ERR_FORMAT 3 // File not in PDF format or corrupted.
435#define FPDF_ERR_PASSWORD 4 // Password required or incorrect password.
436#define FPDF_ERR_SECURITY 5 // Unsupported security scheme.
437#define FPDF_ERR_PAGE 6 // Page not found or content error.
Tom Sepezc46d0002015-11-30 15:46:36 -0800438#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439#define FPDF_ERR_XFALOAD 7 // Load XFA error.
440#define FPDF_ERR_XFALAYOUT 8 // Layout XFA error.
Tom Sepezc46d0002015-11-30 15:46:36 -0800441#endif // PDF_ENABLE_XFA
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700442
443// Function: FPDF_GetLastError
Dan Sinclair49f88b72015-10-20 15:18:51 -0400444// Get last error code when a function fails.
Tom Sepez9857e202015-05-13 17:09:26 -0700445// Parameters:
446// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700447// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400448// A 32-bit integer indicating error code as defined above.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700449// Comments:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450// If the previous SDK call succeeded, the return value of this
Dan Sinclair49f88b72015-10-20 15:18:51 -0400451// function is not defined.
Tom Sepez9857e202015-05-13 17:09:26 -0700452DLLEXPORT unsigned long STDCALL FPDF_GetLastError();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700453
454// Function: FPDF_GetDocPermission
Tom Sepez9857e202015-05-13 17:09:26 -0700455// Get file permission flags of the document.
456// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400457// document - Handle to a document. Returned by FPDF_LoadDocument.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700458// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400459// A 32-bit integer indicating permission flags. Please refer to the
460// PDF Reference for detailed descriptions. If the document is not
461// protected, 0xffffffff will be returned.
Tom Sepez9857e202015-05-13 17:09:26 -0700462DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700463
Bo Xuc5cab022014-09-19 19:16:31 -0700464// Function: FPDF_GetSecurityHandlerRevision
Dan Sinclair49f88b72015-10-20 15:18:51 -0400465// Get the revision for the security handler.
Bo Xuc5cab022014-09-19 19:16:31 -0700466// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400467// document - Handle to a document. Returned by FPDF_LoadDocument.
Bo Xuc5cab022014-09-19 19:16:31 -0700468// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400469// The security handler revision number. Please refer to the PDF
470// Reference for a detailed description. If the document is not
471// protected, -1 will be returned.
Bo Xuc5cab022014-09-19 19:16:31 -0700472DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document);
473
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474// Function: FPDF_GetPageCount
Dan Sinclair49f88b72015-10-20 15:18:51 -0400475// Get total number of pages in the document.
Tom Sepez9857e202015-05-13 17:09:26 -0700476// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400477// document - Handle to document. Returned by FPDF_LoadDocument.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700479// Total number of pages in the document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480DLLEXPORT int STDCALL FPDF_GetPageCount(FPDF_DOCUMENT document);
481
482// Function: FPDF_LoadPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400483// Load a page inside the document.
Tom Sepez9857e202015-05-13 17:09:26 -0700484// Parameters:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485// document - Handle to document. Returned by FPDF_LoadDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700486// page_index - Index number of the page. 0 for the first page.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700487// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400488// A handle to the loaded page, or NULL if page load fails.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700489// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400490// The loaded page can be rendered to devices using FPDF_RenderPage.
491// The loaded page can be closed using FPDF_ClosePage.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492DLLEXPORT FPDF_PAGE STDCALL FPDF_LoadPage(FPDF_DOCUMENT document,
493 int page_index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700494
495// Function: FPDF_GetPageWidth
Tom Sepez9857e202015-05-13 17:09:26 -0700496// Get page width.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700497// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400498// page - Handle to the page. Returned by FPDF_LoadPage.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700500// Page width (excluding non-displayable area) measured in points.
501// One point is 1/72 inch (around 0.3528 mm).
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700502DLLEXPORT double STDCALL FPDF_GetPageWidth(FPDF_PAGE page);
503
504// Function: FPDF_GetPageHeight
Tom Sepez9857e202015-05-13 17:09:26 -0700505// Get page height.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700506// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400507// page - Handle to the page. Returned by FPDF_LoadPage.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700508// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700509// Page height (excluding non-displayable area) measured in points.
510// One point is 1/72 inch (around 0.3528 mm)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700511DLLEXPORT double STDCALL FPDF_GetPageHeight(FPDF_PAGE page);
512
513// Function: FPDF_GetPageSizeByIndex
Dan Sinclair49f88b72015-10-20 15:18:51 -0400514// Get the size of the page at the given index.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400516// document - Handle to document. Returned by FPDF_LoadDocument.
Tom Sepez9857e202015-05-13 17:09:26 -0700517// page_index - Page index, zero for the first page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400518// width - Pointer to a double to receive the page width
519// (in points).
520// height - Pointer to a double to receive the page height
521// (in points).
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700522// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700523// Non-zero for success. 0 for error (document or page not found).
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524DLLEXPORT int STDCALL FPDF_GetPageSizeByIndex(FPDF_DOCUMENT document,
525 int page_index,
526 double* width,
527 double* height);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700528
Dan Sinclair49f88b72015-10-20 15:18:51 -0400529// Page rendering flags. They can be combined with bit-wise OR.
530//
531// Set if annotations are to be rendered.
532#define FPDF_ANNOT 0x01
533// Set if using text rendering optimized for LCD display.
534#define FPDF_LCD_TEXT 0x02
535// Don't use the native text output available on some platforms
536#define FPDF_NO_NATIVETEXT 0x04
537// Grayscale output.
538#define FPDF_GRAYSCALE 0x08
539// Set if you want to get some debug info.
540#define FPDF_DEBUG_INFO 0x80
541// Set if you don't want to catch exceptions.
542#define FPDF_NO_CATCH 0x100
543// Limit image cache size.
544#define FPDF_RENDER_LIMITEDIMAGECACHE 0x200
545// Always use halftone for image stretching.
546#define FPDF_RENDER_FORCEHALFTONE 0x400
547// Render for printing.
548#define FPDF_PRINTING 0x800
549// Set to disable anti-aliasing on text.
550#define FPDF_RENDER_NO_SMOOTHTEXT 0x1000
551// Set to disable anti-aliasing on images.
552#define FPDF_RENDER_NO_SMOOTHIMAGE 0x2000
553// Set to disable anti-aliasing on paths.
554#define FPDF_RENDER_NO_SMOOTHPATH 0x4000
555// Set whether to render in a reverse Byte order, this flag is only used when
556// rendering to a bitmap.
557#define FPDF_REVERSE_BYTE_ORDER 0x10
558
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700559#ifdef _WIN32
560// Function: FPDF_RenderPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400561// Render contents of a page to a device (screen, bitmap, or printer).
562// This function is only supported on Windows.
Tom Sepez9857e202015-05-13 17:09:26 -0700563// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400564// dc - Handle to the device context.
565// page - Handle to the page. Returned by FPDF_LoadPage.
566// start_x - Left pixel position of the display area in
567// device coordinates.
568// start_y - Top pixel position of the display area in device
569// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700570// size_x - Horizontal size (in pixels) for displaying the page.
571// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400572// rotate - Page orientation:
573// 0 (normal)
574// 1 (rotated 90 degrees clockwise)
575// 2 (rotated 180 degrees)
576// 3 (rotated 90 degrees counter-clockwise)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577// flags - 0 for normal display, or combination of flags
Dan Sinclair49f88b72015-10-20 15:18:51 -0400578// defined above.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700579// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700580// None.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581DLLEXPORT void STDCALL FPDF_RenderPage(HDC dc,
582 FPDF_PAGE page,
583 int start_x,
584 int start_y,
585 int size_x,
586 int size_y,
587 int rotate,
588 int flags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700589#endif
590
591// Function: FPDF_RenderPageBitmap
Dan Sinclair49f88b72015-10-20 15:18:51 -0400592// Render contents of a page to a device independent bitmap.
Tom Sepez9857e202015-05-13 17:09:26 -0700593// Parameters:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594// bitmap - Handle to the device independent bitmap (as the
Dan Sinclair49f88b72015-10-20 15:18:51 -0400595// output buffer). The bitmap handle can be created
596// by FPDFBitmap_Create.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597// page - Handle to the page. Returned by FPDF_LoadPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400598// start_x - Left pixel position of the display area in
599// bitmap coordinates.
600// start_y - Top pixel position of the display area in bitmap
601// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700602// size_x - Horizontal size (in pixels) for displaying the page.
603// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400604// rotate - Page orientation:
605// 0 (normal)
606// 1 (rotated 90 degrees clockwise)
607// 2 (rotated 180 degrees)
608// 3 (rotated 90 degrees counter-clockwise)
thestiga78ba602016-11-23 15:25:48 -0800609// flags - 0 for normal display, or combination of the Page
610// Rendering flags defined above. With the FPDF_ANNOT
611// flag, it renders all annotations that do not require
612// user-interaction, which are all annotations except
613// widget and popup annotations.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700615// None.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616DLLEXPORT void STDCALL FPDF_RenderPageBitmap(FPDF_BITMAP bitmap,
617 FPDF_PAGE page,
618 int start_x,
619 int start_y,
620 int size_x,
621 int size_y,
622 int rotate,
623 int flags);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624
thestiga78ba602016-11-23 15:25:48 -0800625// Function: FPDF_RenderPageBitmapWithMatrix
626// Render contents of a page to a device independent bitmap.
627// Parameters:
628// bitmap - Handle to the device independent bitmap (as the
629// output buffer). The bitmap handle can be created
630// by FPDFBitmap_Create.
631// page - Handle to the page. Returned by FPDF_LoadPage
632// matrix - The transform matrix.
633// clipping - The rect to clip to.
634// flags - 0 for normal display, or combination of the Page
635// Rendering flags defined above. With the FPDF_ANNOT
636// flag, it renders all annotations that do not require
637// user-interaction, which are all annotations except
638// widget and popup annotations.
639// Return value:
640// None.
641DLLEXPORT void STDCALL FPDF_RenderPageBitmapWithMatrix(FPDF_BITMAP bitmap,
642 FPDF_PAGE page,
643 const FS_MATRIX* matrix,
644 const FS_RECTF* clipping,
645 int flags);
646
Cary Clark399be5b2016-03-14 16:51:29 -0400647#ifdef _SKIA_SUPPORT_
648DLLEXPORT FPDF_RECORDER STDCALL FPDF_RenderPageSkp(FPDF_PAGE page,
649 int size_x,
650 int size_y);
651#endif
652
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700653// Function: FPDF_ClosePage
Tom Sepez9857e202015-05-13 17:09:26 -0700654// Close a loaded PDF page.
655// Parameters:
656// page - Handle to the loaded page.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700657// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700658// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700659DLLEXPORT void STDCALL FPDF_ClosePage(FPDF_PAGE page);
660
661// Function: FPDF_CloseDocument
Tom Sepez9857e202015-05-13 17:09:26 -0700662// Close a loaded PDF document.
663// Parameters:
664// document - Handle to the loaded document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700665// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700666// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700667DLLEXPORT void STDCALL FPDF_CloseDocument(FPDF_DOCUMENT document);
668
669// Function: FPDF_DeviceToPage
Dan Sinclair49f88b72015-10-20 15:18:51 -0400670// Convert the screen coordinates of a point to page coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700671// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400672// page - Handle to the page. Returned by FPDF_LoadPage.
673// start_x - Left pixel position of the display area in
674// device coordinates.
675// start_y - Top pixel position of the display area in device
676// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700677// size_x - Horizontal size (in pixels) for displaying the page.
678// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400679// rotate - Page orientation:
680// 0 (normal)
681// 1 (rotated 90 degrees clockwise)
682// 2 (rotated 180 degrees)
683// 3 (rotated 90 degrees counter-clockwise)
684// device_x - X value in device coordinates to be converted.
685// device_y - Y value in device coordinates to be converted.
686// page_x - A pointer to a double receiving the converted X
687// value in page coordinates.
688// page_y - A pointer to a double receiving the converted Y
689// value in page coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700690// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700691// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400693// The page coordinate system has its origin at the left-bottom corner
694// of the page, with the X-axis on the bottom going to the right, and
695// the Y-axis on the left side going up.
696//
697// NOTE: this coordinate system can be altered when you zoom, scroll,
698// or rotate a page, however, a point on the page should always have
Tom Sepez9857e202015-05-13 17:09:26 -0700699// the same coordinate values in the page coordinate system.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701// The device coordinate system is device dependent. For screen device,
Dan Sinclair49f88b72015-10-20 15:18:51 -0400702// its origin is at the left-top corner of the window. However this
703// origin can be altered by the Windows coordinate transformation
704// utilities.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400706// You must make sure the start_x, start_y, size_x, size_y
707// and rotate parameters have exactly same values as you used in
708// the FPDF_RenderPage() function call.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709DLLEXPORT void STDCALL FPDF_DeviceToPage(FPDF_PAGE page,
710 int start_x,
711 int start_y,
712 int size_x,
713 int size_y,
714 int rotate,
715 int device_x,
716 int device_y,
717 double* page_x,
718 double* page_y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719
720// Function: FPDF_PageToDevice
Dan Sinclair49f88b72015-10-20 15:18:51 -0400721// Convert the page coordinates of a point to screen coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700722// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400723// page - Handle to the page. Returned by FPDF_LoadPage.
724// start_x - Left pixel position of the display area in
725// device coordinates.
726// start_y - Top pixel position of the display area in device
727// coordinates.
Tom Sepez9857e202015-05-13 17:09:26 -0700728// size_x - Horizontal size (in pixels) for displaying the page.
729// size_y - Vertical size (in pixels) for displaying the page.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400730// rotate - Page orientation:
731// 0 (normal)
732// 1 (rotated 90 degrees clockwise)
733// 2 (rotated 180 degrees)
734// 3 (rotated 90 degrees counter-clockwise)
735// page_x - X value in page coordinates.
736// page_y - Y value in page coordinate.
737// device_x - A pointer to an integer receiving the result X
738// value in device coordinates.
739// device_y - A pointer to an integer receiving the result Y
740// value in device coordinates.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700742// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400744// See comments for FPDF_DeviceToPage().
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745DLLEXPORT void STDCALL FPDF_PageToDevice(FPDF_PAGE page,
746 int start_x,
747 int start_y,
748 int size_x,
749 int size_y,
750 int rotate,
751 double page_x,
752 double page_y,
753 int* device_x,
754 int* device_y);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700755
756// Function: FPDFBitmap_Create
Dan Sinclair49f88b72015-10-20 15:18:51 -0400757// Create a device independent bitmap (FXDIB).
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700758// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400759// width - The number of pixels in width for the bitmap.
760// Must be greater than 0.
761// height - The number of pixels in height for the bitmap.
762// Must be greater than 0.
763// alpha - A flag indicating whether the alpha channel is used.
764// Non-zero for using alpha, zero for not using.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700765// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400766// The created bitmap handle, or NULL if a parameter error or out of
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700767// memory.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700768// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400769// The bitmap always uses 4 bytes per pixel. The first byte is always
770// double word aligned.
771//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772// The byte order is BGRx (the last byte unused if no alpha channel) or
773// BGRA.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700774//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400775// The pixels in a horizontal line are stored side by side, with the
776// left most pixel stored first (with lower memory address).
777// Each line uses width * 4 bytes.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700778//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400779// Lines are stored one after another, with the top most line stored
780// first. There is no gap between adjacent lines.
Tom Sepez9857e202015-05-13 17:09:26 -0700781//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700782// This function allocates enough memory for holding all pixels in the
Dan Sinclair49f88b72015-10-20 15:18:51 -0400783// bitmap, but it doesn't initialize the buffer. Applications can use
784// FPDFBitmap_FillRect to fill the bitmap using any color.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_Create(int width,
786 int height,
787 int alpha);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788
789// More DIB formats
Dan Sinclair49f88b72015-10-20 15:18:51 -0400790// Gray scale bitmap, one byte per pixel.
791#define FPDFBitmap_Gray 1
792// 3 bytes per pixel, byte order: blue, green, red.
793#define FPDFBitmap_BGR 2
794// 4 bytes per pixel, byte order: blue, green, red, unused.
795#define FPDFBitmap_BGRx 3
796// 4 bytes per pixel, byte order: blue, green, red, alpha.
797#define FPDFBitmap_BGRA 4
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798
799// Function: FPDFBitmap_CreateEx
Dan Sinclair49f88b72015-10-20 15:18:51 -0400800// Create a device independent bitmap (FXDIB)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400802// width - The number of pixels in width for the bitmap.
803// Must be greater than 0.
804// height - The number of pixels in height for the bitmap.
805// Must be greater than 0.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806// format - A number indicating for bitmap format, as defined
Dan Sinclair49f88b72015-10-20 15:18:51 -0400807// above.
808// first_scan - A pointer to the first byte of the first line if
809// using an external buffer. If this parameter is NULL,
810// then the a new buffer will be created.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700811// stride - Number of bytes for each scan line, for external
Dan Sinclair49f88b72015-10-20 15:18:51 -0400812// buffer only.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700813// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400814// The bitmap handle, or NULL if parameter error or out of memory.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400816// Similar to FPDFBitmap_Create function, but allows for more formats
817// and an external buffer is supported. The bitmap created by this
818// function can be used in any place that a FPDF_BITMAP handle is
Tom Sepez9857e202015-05-13 17:09:26 -0700819// required.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700820//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400821// If an external buffer is used, then the application should destroy
822// the buffer by itself. FPDFBitmap_Destroy function will not destroy
823// the buffer.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824DLLEXPORT FPDF_BITMAP STDCALL FPDFBitmap_CreateEx(int width,
825 int height,
826 int format,
827 void* first_scan,
828 int stride);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700829
830// Function: FPDFBitmap_FillRect
Dan Sinclair49f88b72015-10-20 15:18:51 -0400831// Fill a rectangle in a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832// Parameters:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700833// bitmap - The handle to the bitmap. Returned by
Dan Sinclair49f88b72015-10-20 15:18:51 -0400834// FPDFBitmap_Create.
835// left - The left position. Starting from 0 at the
836// left-most pixel.
837// top - The top position. Starting from 0 at the
838// top-most line.
839// width - Width in pixels to be filled.
840// height - Height in pixels to be filled.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700841// color - A 32-bit value specifing the color, in 8888 ARGB
Dan Sinclair49f88b72015-10-20 15:18:51 -0400842// format.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700844// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700845// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400846// This function sets the color and (optionally) alpha value in the
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700847// specified region of the bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700848//
Dan Sinclair49f88b72015-10-20 15:18:51 -0400849// NOTE: If the alpha channel is used, this function does NOT
850// composite the background with the source color, instead the
851// background will be replaced by the source color and the alpha.
852//
853// If the alpha channel is not used, the alpha parameter is ignored.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700854DLLEXPORT void STDCALL FPDFBitmap_FillRect(FPDF_BITMAP bitmap,
855 int left,
856 int top,
857 int width,
858 int height,
859 FPDF_DWORD color);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700860
861// Function: FPDFBitmap_GetBuffer
Dan Sinclair49f88b72015-10-20 15:18:51 -0400862// Get data buffer of a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700863// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400864// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700865// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700866// The pointer to the first byte of the bitmap buffer.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700867// Comments:
Tom Sepez9857e202015-05-13 17:09:26 -0700868// The stride may be more than width * number of bytes per pixel
Dan Sinclair49f88b72015-10-20 15:18:51 -0400869//
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700870// Applications can use this function to get the bitmap buffer pointer,
Dan Sinclair49f88b72015-10-20 15:18:51 -0400871// then manipulate any color and/or alpha values for any pixels in the
872// bitmap.
873//
874// The data is in BGRA format. Where the A maybe unused if alpha was
875// not specified.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700876DLLEXPORT void* STDCALL FPDFBitmap_GetBuffer(FPDF_BITMAP bitmap);
877
878// Function: FPDFBitmap_GetWidth
Dan Sinclair49f88b72015-10-20 15:18:51 -0400879// Get width of a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700880// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400881// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700882// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400883// The width of the bitmap in pixels.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700884DLLEXPORT int STDCALL FPDFBitmap_GetWidth(FPDF_BITMAP bitmap);
885
886// Function: FPDFBitmap_GetHeight
Dan Sinclair49f88b72015-10-20 15:18:51 -0400887// Get height of a bitmap.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700888// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400889// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700890// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400891// The height of the bitmap in pixels.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700892DLLEXPORT int STDCALL FPDFBitmap_GetHeight(FPDF_BITMAP bitmap);
893
894// Function: FPDFBitmap_GetStride
Dan Sinclair49f88b72015-10-20 15:18:51 -0400895// Get number of bytes for each line in the bitmap buffer.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700896// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400897// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700898// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400899// The number of bytes for each line in the bitmap buffer.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700900// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400901// The stride may be more than width * number of bytes per pixel.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700902DLLEXPORT int STDCALL FPDFBitmap_GetStride(FPDF_BITMAP bitmap);
903
904// Function: FPDFBitmap_Destroy
Dan Sinclair49f88b72015-10-20 15:18:51 -0400905// Destroy a bitmap and release all related buffers.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700906// Parameters:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400907// bitmap - Handle to the bitmap. Returned by FPDFBitmap_Create.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700908// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700909// None.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700910// Comments:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400911// This function will not destroy any external buffers provided when
912// the bitmap was created.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700913DLLEXPORT void STDCALL FPDFBitmap_Destroy(FPDF_BITMAP bitmap);
914
915// Function: FPDF_VIEWERREF_GetPrintScaling
Tom Sepez9857e202015-05-13 17:09:26 -0700916// Whether the PDF document prefers to be scaled or not.
917// Parameters:
918// document - Handle to the loaded document.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700919// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700920// None.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700921DLLEXPORT FPDF_BOOL STDCALL
922FPDF_VIEWERREF_GetPrintScaling(FPDF_DOCUMENT document);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700923
Bo Xu9114e832014-07-14 13:22:47 -0700924// Function: FPDF_VIEWERREF_GetNumCopies
Tom Sepez9857e202015-05-13 17:09:26 -0700925// Returns the number of copies to be printed.
Bo Xu9114e832014-07-14 13:22:47 -0700926// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700927// document - Handle to the loaded document.
Bo Xu9114e832014-07-14 13:22:47 -0700928// Return value:
929// The number of copies to be printed.
Bo Xu9114e832014-07-14 13:22:47 -0700930DLLEXPORT int STDCALL FPDF_VIEWERREF_GetNumCopies(FPDF_DOCUMENT document);
931
932// Function: FPDF_VIEWERREF_GetPrintPageRange
Tom Sepez9857e202015-05-13 17:09:26 -0700933// Page numbers to initialize print dialog box when file is printed.
Bo Xu9114e832014-07-14 13:22:47 -0700934// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700935// document - Handle to the loaded document.
Bo Xu9114e832014-07-14 13:22:47 -0700936// Return value:
937// The print page range to be used for printing.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700938DLLEXPORT FPDF_PAGERANGE STDCALL
939FPDF_VIEWERREF_GetPrintPageRange(FPDF_DOCUMENT document);
Bo Xu9114e832014-07-14 13:22:47 -0700940
941// Function: FPDF_VIEWERREF_GetDuplex
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700942// Returns the paper handling option to be used when printing from
Dan Sinclair49f88b72015-10-20 15:18:51 -0400943// the print dialog.
Bo Xu9114e832014-07-14 13:22:47 -0700944// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700945// document - Handle to the loaded document.
Bo Xu9114e832014-07-14 13:22:47 -0700946// Return value:
947// The paper handling option to be used when printing.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700948DLLEXPORT FPDF_DUPLEXTYPE STDCALL
949FPDF_VIEWERREF_GetDuplex(FPDF_DOCUMENT document);
Bo Xu9114e832014-07-14 13:22:47 -0700950
thestig04bebfe2016-11-04 16:07:25 -0700951// Function: FPDF_VIEWERREF_GetName
952// Gets the contents for a viewer ref, with a given key. The value must
953// be of type "name".
954// Parameters:
955// document - Handle to the loaded document.
956// key - Name of the key in the viewer pref dictionary.
957// buffer - A string to write the contents of the key to.
958// length - Length of the buffer.
959// Return value:
960// The number of bytes in the contents, including the NULL terminator.
961// Thus if the return value is 0, then that indicates an error, such
962// as when |document| is invalid or |buffer| is NULL. If |length| is
963// less than the returned length, or |buffer| is NULL, |buffer| will
964// not be modified.
965DLLEXPORT unsigned long STDCALL FPDF_VIEWERREF_GetName(FPDF_DOCUMENT document,
966 FPDF_BYTESTRING key,
967 char* buffer,
968 unsigned long length);
969
Bo Xu4d62b6b2015-01-10 22:52:59 -0800970// Function: FPDF_CountNamedDests
Tom Sepez9857e202015-05-13 17:09:26 -0700971// Get the count of named destinations in the PDF document.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800972// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700973// document - Handle to a document
Bo Xu4d62b6b2015-01-10 22:52:59 -0800974// Return value:
Tom Sepez9857e202015-05-13 17:09:26 -0700975// The count of named destinations.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800976DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document);
977
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700978// Function: FPDF_GetNamedDestByName
Dan Sinclair49f88b72015-10-20 15:18:51 -0400979// Get a the destination handle for the given name.
Tom Sepez9857e202015-05-13 17:09:26 -0700980// Parameters:
981// document - Handle to the loaded document.
Dan Sinclair49f88b72015-10-20 15:18:51 -0400982// name - The name of a destination.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700983// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400984// The handle to the destination.
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700985DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document,
986 FPDF_BYTESTRING name);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700987
Bo Xu4d62b6b2015-01-10 22:52:59 -0800988// Function: FPDF_GetNamedDest
Dan Sinclair49f88b72015-10-20 15:18:51 -0400989// Get the named destination by index.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800990// Parameters:
Tom Sepez9857e202015-05-13 17:09:26 -0700991// document - Handle to a document
Dan Sinclair49f88b72015-10-20 15:18:51 -0400992// index - The index of a named destination.
993// buffer - The buffer to store the destination name,
994// used as wchar_t*.
995// buflen [in/out] - Size of the buffer in bytes on input,
996// length of the result in bytes on output
997// or -1 if the buffer is too small.
Bo Xu4d62b6b2015-01-10 22:52:59 -0800998// Return value:
Dan Sinclair49f88b72015-10-20 15:18:51 -0400999// The destination handle for a given index, or NULL if there is no
1000// named destination corresponding to |index|.
Bo Xu4d62b6b2015-01-10 22:52:59 -08001001// Comments:
Tom Sepez9857e202015-05-13 17:09:26 -07001002// Call this function twice to get the name of the named destination:
Dan Sinclair49f88b72015-10-20 15:18:51 -04001003// 1) First time pass in |buffer| as NULL and get buflen.
1004// 2) Second time pass in allocated |buffer| and buflen to retrieve
1005// |buffer|, which should be used as wchar_t*.
Bo Xu4d62b6b2015-01-10 22:52:59 -08001006//
Dan Sinclair49f88b72015-10-20 15:18:51 -04001007// If buflen is not sufficiently large, it will be set to -1 upon
1008// return.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001009DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDest(FPDF_DOCUMENT document,
1010 int index,
1011 void* buffer,
1012 long* buflen);
Bo Xu4d62b6b2015-01-10 22:52:59 -08001013
Tom Sepezc46d0002015-11-30 15:46:36 -08001014#ifdef PDF_ENABLE_XFA
Tom Sepez9857e202015-05-13 17:09:26 -07001015// Function: FPDF_BStr_Init
1016// Helper function to initialize a byte string.
Bo Xufdc00a72014-10-28 23:03:33 -07001017DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Init(FPDF_BSTR* str);
1018
Tom Sepez9857e202015-05-13 17:09:26 -07001019// Function: FPDF_BStr_Set
1020// Helper function to set string data.
Nico Weber9d8ec5a2015-08-04 13:00:21 -07001021DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Set(FPDF_BSTR* str,
1022 FPDF_LPCSTR bstr,
1023 int length);
Bo Xufdc00a72014-10-28 23:03:33 -07001024
Tom Sepez9857e202015-05-13 17:09:26 -07001025// Function: FPDF_BStr_Clear
1026// Helper function to clear a byte string.
Bo Xufdc00a72014-10-28 23:03:33 -07001027DLLEXPORT FPDF_RESULT STDCALL FPDF_BStr_Clear(FPDF_BSTR* str);
Tom Sepezc46d0002015-11-30 15:46:36 -08001028#endif // PDF_ENABLE_XFA
Bo Xufdc00a72014-10-28 23:03:33 -07001029
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001030#ifdef __cplusplus
Tom Sepez9857e202015-05-13 17:09:26 -07001031}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001032#endif
1033
Tom Sepez9857e202015-05-13 17:09:26 -07001034#endif // PUBLIC_FPDFVIEW_H_