blob: 7b5597480079c2d8e55d5fae884b8fb2059b0971 [file] [log] [blame]
Jane Liu53aafa92017-07-12 19:55:02 -04001// Copyright 2017 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#ifndef PUBLIC_FPDF_ATTACHMENT_H_
6#define PUBLIC_FPDF_ATTACHMENT_H_
7
8// NOLINTNEXTLINE(build/include)
9#include "fpdfview.h"
10
11#ifdef __cplusplus
12extern "C" {
13#endif // __cplusplus
14
15// Experimental API.
16// Get the number of embedded files in |document|.
17//
18// document - handle to a document.
19//
20// Returns the number of embedded files in |document|.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040021FPDF_EXPORT int FPDF_CALLCONV
22FPDFDoc_GetAttachmentCount(FPDF_DOCUMENT document);
Jane Liu53aafa92017-07-12 19:55:02 -040023
24// Experimental API.
Jane Liu54a42142017-07-24 16:40:54 -040025// Add an embedded file with |name| in |document|. If |name| is empty, or if
26// |name| is the name of a existing embedded file in |document|, or if
27// |document|'s embedded file name tree is too deep (i.e. |document| has too
28// many embedded files already), then a new attachment will not be added.
29//
30// document - handle to a document.
31// name - name of the new attachment.
32//
33// Returns a handle to the new attachment object, or NULL on failure.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040034FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV
35FPDFDoc_AddAttachment(FPDF_DOCUMENT document, FPDF_WIDESTRING name);
Jane Liu54a42142017-07-24 16:40:54 -040036
37// Experimental API.
Jane Liu18ae06d2017-07-18 10:15:16 -040038// Get the embedded attachment at |index| in |document|. Note that the returned
39// attachment handle is only valid while |document| is open.
Jane Liu53aafa92017-07-12 19:55:02 -040040//
41// document - handle to a document.
42// index - the index of the requested embedded file.
Jane Liu18ae06d2017-07-18 10:15:16 -040043//
44// Returns the handle to the attachment object, or NULL on failure.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040045FPDF_EXPORT FPDF_ATTACHMENT FPDF_CALLCONV
46FPDFDoc_GetAttachment(FPDF_DOCUMENT document, int index);
Jane Liu18ae06d2017-07-18 10:15:16 -040047
48// Experimental API.
Jane Liuf63e8132017-07-25 18:11:27 -040049// Delete the embedded attachment at |index| in |document|. Note that this does
50// not remove the attachment data from the PDF file; it simply removes the
51// file's entry in the embedded files name tree so that it does not appear in
52// the attachment list. This behavior may change in the future.
53//
54// document - handle to a document.
55// index - the index of the embedded file to be deleted.
56//
57// Returns true if successful.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040058FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
59FPDFDoc_DeleteAttachment(FPDF_DOCUMENT document, int index);
Jane Liuf63e8132017-07-25 18:11:27 -040060
61// Experimental API.
Jane Liu18ae06d2017-07-18 10:15:16 -040062// Get the name of the |attachment| file. |buffer| is only modified if |buflen|
63// is longer than the length of the file name. On errors, |buffer| is unmodified
64// and the returned length is 0.
65//
66// attachment - handle to an attachment.
67// buffer - buffer for holding the file name, encoded in UTF16-LE.
68// buflen - length of the buffer.
Jane Liu53aafa92017-07-12 19:55:02 -040069//
70// Returns the length of the file name.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040071FPDF_EXPORT unsigned long FPDF_CALLCONV
Jane Liu18ae06d2017-07-18 10:15:16 -040072FPDFAttachment_GetName(FPDF_ATTACHMENT attachment,
73 void* buffer,
74 unsigned long buflen);
75
76// Experimental API.
77// Check if the params dictionary of |attachment| has |key| as a key.
78//
79// attachment - handle to an attachment.
Lei Zhangba14c0a2017-09-22 16:43:01 -070080// key - the key to look for, encoded in UTF-8.
Jane Liu18ae06d2017-07-18 10:15:16 -040081//
82// Returns true if |key| exists.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040083FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
Lei Zhangdf064df2017-08-31 02:33:27 -070084FPDFAttachment_HasKey(FPDF_ATTACHMENT attachment, FPDF_BYTESTRING key);
Jane Liu18ae06d2017-07-18 10:15:16 -040085
86// Experimental API.
87// Get the type of the value corresponding to |key| in the params dictionary of
88// the embedded |attachment|.
89//
90// attachment - handle to an attachment.
Lei Zhangba14c0a2017-09-22 16:43:01 -070091// key - the key to look for, encoded in UTF-8.
Jane Liu18ae06d2017-07-18 10:15:16 -040092//
93// Returns the type of the dictionary value.
Dan Sinclair00d2ad12017-08-10 14:13:02 -040094FPDF_EXPORT FPDF_OBJECT_TYPE FPDF_CALLCONV
Lei Zhangdf064df2017-08-31 02:33:27 -070095FPDFAttachment_GetValueType(FPDF_ATTACHMENT attachment, FPDF_BYTESTRING key);
Jane Liu18ae06d2017-07-18 10:15:16 -040096
97// Experimental API.
Jane Liu54a42142017-07-24 16:40:54 -040098// Set the string value corresponding to |key| in the params dictionary of the
99// embedded file |attachment|, overwriting the existing value if any. The value
100// type should be FPDF_OBJECT_STRING after this function call succeeds.
101//
102// attachment - handle to an attachment.
Lei Zhangba14c0a2017-09-22 16:43:01 -0700103// key - the key to the dictionary entry, encoded in UTF-8.
Jane Liu54a42142017-07-24 16:40:54 -0400104// value - the string value to be set, encoded in UTF16-LE.
105//
106// Returns true if successful.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400107FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
Jane Liu54a42142017-07-24 16:40:54 -0400108FPDFAttachment_SetStringValue(FPDF_ATTACHMENT attachment,
Lei Zhangdf064df2017-08-31 02:33:27 -0700109 FPDF_BYTESTRING key,
Jane Liu54a42142017-07-24 16:40:54 -0400110 FPDF_WIDESTRING value);
111
112// Experimental API.
Jane Liu18ae06d2017-07-18 10:15:16 -0400113// Get the string value corresponding to |key| in the params dictionary of the
114// embedded file |attachment|. |buffer| is only modified if |buflen| is longer
115// than the length of the string value. Note that if |key| does not exist in the
116// dictionary or if |key|'s corresponding value in the dictionary is not a
117// string (i.e. the value is not of type FPDF_OBJECT_STRING or
118// FPDF_OBJECT_NAME), then an empty string would be copied to |buffer| and the
119// return value would be 2. On other errors, nothing would be added to |buffer|
120// and the return value would be 0.
121//
122// attachment - handle to an attachment.
Lei Zhangba14c0a2017-09-22 16:43:01 -0700123// key - the key to the requested string value, encoded in UTF-8.
Jane Liu54a42142017-07-24 16:40:54 -0400124// buffer - buffer for holding the string value encoded in UTF16-LE.
Jane Liu18ae06d2017-07-18 10:15:16 -0400125// buflen - length of the buffer.
126//
127// Returns the length of the dictionary value string.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400128FPDF_EXPORT unsigned long FPDF_CALLCONV
Jane Liu18ae06d2017-07-18 10:15:16 -0400129FPDFAttachment_GetStringValue(FPDF_ATTACHMENT attachment,
Lei Zhangdf064df2017-08-31 02:33:27 -0700130 FPDF_BYTESTRING key,
Jane Liu18ae06d2017-07-18 10:15:16 -0400131 void* buffer,
132 unsigned long buflen);
133
134// Experimental API.
Jane Liu54a42142017-07-24 16:40:54 -0400135// Set the file data of |attachment|, overwriting the existing file data if any.
136// The creation date and checksum will be updated, while all other dictionary
137// entries will be deleted. Note that only contents with |len| smaller than
138// INT_MAX is supported.
139//
140// attachment - handle to an attachment.
141// contents - buffer holding the file data to be written in raw bytes.
142// len - length of file data.
143//
144// Returns true if successful.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400145FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
146FPDFAttachment_SetFile(FPDF_ATTACHMENT attachment,
147 FPDF_DOCUMENT document,
148 const void* contents,
149 const unsigned long len);
Jane Liu54a42142017-07-24 16:40:54 -0400150
151// Experimental API.
Jane Liu18ae06d2017-07-18 10:15:16 -0400152// Get the file data of |attachment|. |buffer| is only modified if |buflen| is
153// longer than the length of the file. On errors, |buffer| is unmodified and the
154// returned length is 0.
155//
156// attachment - handle to an attachment.
Jane Liu54a42142017-07-24 16:40:54 -0400157// buffer - buffer for holding the file data in raw bytes.
Jane Liu18ae06d2017-07-18 10:15:16 -0400158// buflen - length of the buffer.
159//
160// Returns the length of the file.
Dan Sinclair00d2ad12017-08-10 14:13:02 -0400161FPDF_EXPORT unsigned long FPDF_CALLCONV
Jane Liu18ae06d2017-07-18 10:15:16 -0400162FPDFAttachment_GetFile(FPDF_ATTACHMENT attachment,
163 void* buffer,
164 unsigned long buflen);
Jane Liu53aafa92017-07-12 19:55:02 -0400165
166#ifdef __cplusplus
167} // extern "C"
168#endif // __cplusplus
169
170#endif // PUBLIC_FPDF_ATTACHMENT_H_