Home | History | Annotate | Download | only in public
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef PUBLIC_FPDF_DOC_H_
      8 #define PUBLIC_FPDF_DOC_H_
      9 
     10 // NOLINTNEXTLINE(build/include)
     11 #include "fpdfview.h"
     12 
     13 #ifdef __cplusplus
     14 extern "C" {
     15 #endif  // __cplusplus
     16 
     17 // Unsupported action type.
     18 #define PDFACTION_UNSUPPORTED 0
     19 // Go to a destination within current document.
     20 #define PDFACTION_GOTO 1
     21 // Go to a destination within another document.
     22 #define PDFACTION_REMOTEGOTO 2
     23 // URI, including web pages and other Internet resources.
     24 #define PDFACTION_URI 3
     25 // Launch an application or open a file.
     26 #define PDFACTION_LAUNCH 4
     27 
     28 // View destination fit types. See pdfmark reference v9, page 48.
     29 #define PDFDEST_VIEW_UNKNOWN_MODE 0
     30 #define PDFDEST_VIEW_XYZ 1
     31 #define PDFDEST_VIEW_FIT 2
     32 #define PDFDEST_VIEW_FITH 3
     33 #define PDFDEST_VIEW_FITV 4
     34 #define PDFDEST_VIEW_FITR 5
     35 #define PDFDEST_VIEW_FITB 6
     36 #define PDFDEST_VIEW_FITBH 7
     37 #define PDFDEST_VIEW_FITBV 8
     38 
     39 typedef struct _FS_QUADPOINTSF {
     40   FS_FLOAT x1;
     41   FS_FLOAT y1;
     42   FS_FLOAT x2;
     43   FS_FLOAT y2;
     44   FS_FLOAT x3;
     45   FS_FLOAT y3;
     46   FS_FLOAT x4;
     47   FS_FLOAT y4;
     48 } FS_QUADPOINTSF;
     49 
     50 // Get the first child of |bookmark|, or the first top-level bookmark item.
     51 //
     52 //   document - handle to the document.
     53 //   bookmark - handle to the current bookmark. Pass NULL for the first top
     54 //              level item.
     55 //
     56 // Returns a handle to the first child of |bookmark| or the first top-level
     57 // bookmark item. NULL if no child or top-level bookmark found.
     58 FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
     59 FPDFBookmark_GetFirstChild(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);
     60 
     61 // Get the next sibling of |bookmark|.
     62 //
     63 //   document - handle to the document.
     64 //   bookmark - handle to the current bookmark.
     65 //
     66 // Returns a handle to the next sibling of |bookmark|, or NULL if this is the
     67 // last bookmark at this level.
     68 FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
     69 FPDFBookmark_GetNextSibling(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);
     70 
     71 // Get the title of |bookmark|.
     72 //
     73 //   bookmark - handle to the bookmark.
     74 //   buffer   - buffer for the title. May be NULL.
     75 //   buflen   - the length of the buffer in bytes. May be 0.
     76 //
     77 // Returns the number of bytes in the title, including the terminating NUL
     78 // character. The number of bytes is returned regardless of the |buffer| and
     79 // |buflen| parameters.
     80 //
     81 // Regardless of the platform, the |buffer| is always in UTF-16LE encoding. The
     82 // string is terminated by a UTF16 NUL character. If |buflen| is less than the
     83 // required length, or |buffer| is NULL, |buffer| will not be modified.
     84 FPDF_EXPORT unsigned long FPDF_CALLCONV
     85 FPDFBookmark_GetTitle(FPDF_BOOKMARK bookmark,
     86                       void* buffer,
     87                       unsigned long buflen);
     88 
     89 // Find the bookmark with |title| in |document|.
     90 //
     91 //   document - handle to the document.
     92 //   title    - the UTF-16LE encoded Unicode title for which to search.
     93 //
     94 // Returns the handle to the bookmark, or NULL if |title| can't be found.
     95 //
     96 // |FPDFBookmark_Find| will always return the first bookmark found even if
     97 // multiple bookmarks have the same |title|.
     98 FPDF_EXPORT FPDF_BOOKMARK FPDF_CALLCONV
     99 FPDFBookmark_Find(FPDF_DOCUMENT document, FPDF_WIDESTRING title);
    100 
    101 // Get the destination associated with |bookmark|.
    102 //
    103 //   document - handle to the document.
    104 //   bookmark - handle to the bookmark.
    105 //
    106 // Returns the handle to the destination data,  NULL if no destination is
    107 // associated with |bookmark|.
    108 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV
    109 FPDFBookmark_GetDest(FPDF_DOCUMENT document, FPDF_BOOKMARK bookmark);
    110 
    111 // Get the action associated with |bookmark|.
    112 //
    113 //   bookmark - handle to the bookmark.
    114 //
    115 // Returns the handle to the action data, or NULL if no action is associated
    116 // with |bookmark|. When NULL is returned, |FPDFBookmark_GetDest| should be
    117 // called to get the |bookmark| destination data.
    118 FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV
    119 FPDFBookmark_GetAction(FPDF_BOOKMARK bookmark);
    120 
    121 // Get the type of |action|.
    122 //
    123 //   action - handle to the action.
    124 //
    125 // Returns one of:
    126 //   PDFACTION_UNSUPPORTED
    127 //   PDFACTION_GOTO
    128 //   PDFACTION_REMOTEGOTO
    129 //   PDFACTION_URI
    130 //   PDFACTION_LAUNCH
    131 FPDF_EXPORT unsigned long FPDF_CALLCONV FPDFAction_GetType(FPDF_ACTION action);
    132 
    133 // Get the destination of |action|.
    134 //
    135 //   document - handle to the document.
    136 //   action   - handle to the action. |action| must be a |PDFACTION_GOTO| or
    137 //              |PDFACTION_REMOTEGOTO|.
    138 //
    139 // Returns a handle to the destination data.
    140 //
    141 // In the case of |PDFACTION_REMOTEGOTO|, you should first call
    142 // |FPDFAction_GetFilePath| then load that document, the document handle from
    143 // that document should pass as |document| to |FPDFAction_GetDest|.
    144 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFAction_GetDest(FPDF_DOCUMENT document,
    145                                                        FPDF_ACTION action);
    146 
    147 // Get file path of a |PDFACTION_REMOTEGOTO| |action|.
    148 //
    149 //   action - handle to the action. |action| must be a |PDFACTION_LAUNCH| or
    150 //            |PDFACTION_REMOTEGOTO|
    151 //   buffer - a buffer for output the path string. May be NULL.
    152 //   buflen - the length of the buffer, in bytes. May be 0.
    153 //
    154 // Returns the number of bytes in the file path, including the trailing NUL
    155 // character.
    156 //
    157 // Regardless of the platform, the |buffer| is always in UTF-8 encoding.
    158 // If |buflen| is less than the returned length, or |buffer| is NULL, |buffer|
    159 // will not be modified.
    160 FPDF_EXPORT unsigned long FPDF_CALLCONV
    161 FPDFAction_GetFilePath(FPDF_ACTION action, void* buffer, unsigned long buflen);
    162 
    163 // Get the URI path of a |PDFACTION_URI| |action|.
    164 //
    165 //   document - handle to the document.
    166 //   action   - handle to the action. Must be a |PDFACTION_URI|.
    167 //   buffer   - a buffer for the path string. May be NULL.
    168 //   buflen   - the length of the buffer, in bytes. May be 0.
    169 //
    170 // Returns the number of bytes in the URI path, including trailing zeros.
    171 //
    172 // The |buffer| is always encoded in 7-bit ASCII. If |buflen| is less than the
    173 // returned length, or |buffer| is NULL, |buffer| will not be modified.
    174 FPDF_EXPORT unsigned long FPDF_CALLCONV
    175 FPDFAction_GetURIPath(FPDF_DOCUMENT document,
    176                       FPDF_ACTION action,
    177                       void* buffer,
    178                       unsigned long buflen);
    179 
    180 // Get the page index of |dest|.
    181 //
    182 //   document - handle to the document.
    183 //   dest     - handle to the destination.
    184 //
    185 // Returns the page index containing |dest|. Page indices start from 0.
    186 FPDF_EXPORT unsigned long FPDF_CALLCONV
    187 FPDFDest_GetPageIndex(FPDF_DOCUMENT document, FPDF_DEST dest);
    188 
    189 // Get the view (fit type) specified by |dest|.
    190 // Experimental API. Subject to change.
    191 //
    192 //   dest         - handle to the destination.
    193 //   pNumParams   - receives the number of view parameters, which is at most 4.
    194 //   pParams      - buffer to write the view parameters. Must be at least 4
    195 //                  FS_FLOATs long.
    196 // Returns one of the PDFDEST_VIEW_* constants, PDFDEST_VIEW_UNKNOWN_MODE if
    197 // |dest| does not specify a view.
    198 FPDF_EXPORT unsigned long FPDF_CALLCONV
    199 FPDFDest_GetView(FPDF_DEST dest, unsigned long* pNumParams, FS_FLOAT* pParams);
    200 
    201 // Get the (x, y, zoom) location of |dest| in the destination page, if the
    202 // destination is in [page /XYZ x y zoom] syntax.
    203 //
    204 //   dest       - handle to the destination.
    205 //   hasXVal    - out parameter; true if the x value is not null
    206 //   hasYVal    - out parameter; true if the y value is not null
    207 //   hasZoomVal - out parameter; true if the zoom value is not null
    208 //   x          - out parameter; the x coordinate, in page coordinates.
    209 //   y          - out parameter; the y coordinate, in page coordinates.
    210 //   zoom       - out parameter; the zoom value.
    211 // Returns TRUE on successfully reading the /XYZ value.
    212 //
    213 // Note the [x, y, zoom] values are only set if the corresponding hasXVal,
    214 // hasYVal or hasZoomVal flags are true.
    215 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
    216 FPDFDest_GetLocationInPage(FPDF_DEST dest,
    217                            FPDF_BOOL* hasXCoord,
    218                            FPDF_BOOL* hasYCoord,
    219                            FPDF_BOOL* hasZoom,
    220                            FS_FLOAT* x,
    221                            FS_FLOAT* y,
    222                            FS_FLOAT* zoom);
    223 
    224 // Find a link at point (|x|,|y|) on |page|.
    225 //
    226 //   page - handle to the document page.
    227 //   x    - the x coordinate, in the page coordinate system.
    228 //   y    - the y coordinate, in the page coordinate system.
    229 //
    230 // Returns a handle to the link, or NULL if no link found at the given point.
    231 //
    232 // You can convert coordinates from screen coordinates to page coordinates using
    233 // |FPDF_DeviceToPage|.
    234 FPDF_EXPORT FPDF_LINK FPDF_CALLCONV FPDFLink_GetLinkAtPoint(FPDF_PAGE page,
    235                                                             double x,
    236                                                             double y);
    237 
    238 // Find the Z-order of link at point (|x|,|y|) on |page|.
    239 //
    240 //   page - handle to the document page.
    241 //   x    - the x coordinate, in the page coordinate system.
    242 //   y    - the y coordinate, in the page coordinate system.
    243 //
    244 // Returns the Z-order of the link, or -1 if no link found at the given point.
    245 // Larger Z-order numbers are closer to the front.
    246 //
    247 // You can convert coordinates from screen coordinates to page coordinates using
    248 // |FPDF_DeviceToPage|.
    249 FPDF_EXPORT int FPDF_CALLCONV FPDFLink_GetLinkZOrderAtPoint(FPDF_PAGE page,
    250                                                             double x,
    251                                                             double y);
    252 
    253 // Get destination info for |link|.
    254 //
    255 //   document - handle to the document.
    256 //   link     - handle to the link.
    257 //
    258 // Returns a handle to the destination, or NULL if there is no destination
    259 // associated with the link. In this case, you should call |FPDFLink_GetAction|
    260 // to retrieve the action associated with |link|.
    261 FPDF_EXPORT FPDF_DEST FPDF_CALLCONV FPDFLink_GetDest(FPDF_DOCUMENT document,
    262                                                      FPDF_LINK link);
    263 
    264 // Get action info for |link|.
    265 //
    266 //   link - handle to the link.
    267 //
    268 // Returns a handle to the action associated to |link|, or NULL if no action.
    269 FPDF_EXPORT FPDF_ACTION FPDF_CALLCONV FPDFLink_GetAction(FPDF_LINK link);
    270 
    271 // Enumerates all the link annotations in |page|.
    272 //
    273 //   page      - handle to the page.
    274 //   startPos  - the start position, should initially be 0 and is updated with
    275 //               the next start position on return.
    276 //   linkAnnot - the link handle for |startPos|.
    277 //
    278 // Returns TRUE on success.
    279 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_Enumerate(FPDF_PAGE page,
    280                                                        int* startPos,
    281                                                        FPDF_LINK* linkAnnot);
    282 
    283 // Get the rectangle for |linkAnnot|.
    284 //
    285 //   linkAnnot - handle to the link annotation.
    286 //   rect      - the annotation rectangle.
    287 //
    288 // Returns true on success.
    289 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFLink_GetAnnotRect(FPDF_LINK linkAnnot,
    290                                                           FS_RECTF* rect);
    291 
    292 // Get the count of quadrilateral points to the |linkAnnot|.
    293 //
    294 //   linkAnnot - handle to the link annotation.
    295 //
    296 // Returns the count of quadrilateral points.
    297 FPDF_EXPORT int FPDF_CALLCONV FPDFLink_CountQuadPoints(FPDF_LINK linkAnnot);
    298 
    299 // Get the quadrilateral points for the specified |quadIndex| in |linkAnnot|.
    300 //
    301 //   linkAnnot  - handle to the link annotation.
    302 //   quadIndex  - the specified quad point index.
    303 //   quadPoints - receives the quadrilateral points.
    304 //
    305 // Returns true on success.
    306 FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
    307 FPDFLink_GetQuadPoints(FPDF_LINK linkAnnot,
    308                        int quadIndex,
    309                        FS_QUADPOINTSF* quadPoints);
    310 
    311 // Get meta-data |tag| content from |document|.
    312 //
    313 //   document - handle to the document.
    314 //   tag      - the tag to retrieve. The tag can be one of:
    315 //                Title, Author, Subject, Keywords, Creator, Producer,
    316 //                CreationDate, or ModDate.
    317 //              For detailed explanations of these tags and their respective
    318 //              values, please refer to PDF Reference 1.6, section 10.2.1,
    319 //              'Document Information Dictionary'.
    320 //   buffer   - a buffer for the tag. May be NULL.
    321 //   buflen   - the length of the buffer, in bytes. May be 0.
    322 //
    323 // Returns the number of bytes in the tag, including trailing zeros.
    324 //
    325 // The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two
    326 // bytes of zeros indicating the end of the string.  If |buflen| is less than
    327 // the returned length, or |buffer| is NULL, |buffer| will not be modified.
    328 //
    329 // For linearized files, FPDFAvail_IsFormAvail must be called before this, and
    330 // it must have returned PDF_FORM_AVAIL or PDF_FORM_NOTEXIST. Before that, there
    331 // is no guarantee the metadata has been loaded.
    332 FPDF_EXPORT unsigned long FPDF_CALLCONV FPDF_GetMetaText(FPDF_DOCUMENT document,
    333                                                          FPDF_BYTESTRING tag,
    334                                                          void* buffer,
    335                                                          unsigned long buflen);
    336 
    337 // Get the page label for |page_index| from |document|.
    338 //
    339 //   document    - handle to the document.
    340 //   page_index  - the 0-based index of the page.
    341 //   buffer      - a buffer for the page label. May be NULL.
    342 //   buflen      - the length of the buffer, in bytes. May be 0.
    343 //
    344 // Returns the number of bytes in the page label, including trailing zeros.
    345 //
    346 // The |buffer| is always encoded in UTF-16LE. The |buffer| is followed by two
    347 // bytes of zeros indicating the end of the string.  If |buflen| is less than
    348 // the returned length, or |buffer| is NULL, |buffer| will not be modified.
    349 FPDF_EXPORT unsigned long FPDF_CALLCONV
    350 FPDF_GetPageLabel(FPDF_DOCUMENT document,
    351                   int page_index,
    352                   void* buffer,
    353                   unsigned long buflen);
    354 
    355 #ifdef __cplusplus
    356 }  // extern "C"
    357 #endif  // __cplusplus
    358 
    359 #endif  // PUBLIC_FPDF_DOC_H_
    360