File: c02.tex

package info (click to toggle)
cpdf 2.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,140 kB
  • sloc: ml: 35,825; makefile: 66; sh: 49
file content (311 lines) | stat: -rw-r--r-- 10,806 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* CHAPTER 1. Basics */

/*
 * cpdf_fromFile(filename, userpw) loads a PDF file from a given file. Supply
 * a user password (possibly blank) in case the file is encrypted. It won't be
 * decrypted, but sometimes the password is needed just to load the file.
 */
int cpdf_fromFile(const char[], const char[]);

/*
 * cpdf_fromFileLazy(pdf, userpw) loads a PDF from a file, doing only minimal
 * parsing. The objects will be read and parsed when they are actually
 * needed. Use this when the whole file won't be required. Also supply a user
 * password (possibly blank) in case the file is encrypted. It won't be
 * decrypted, but sometimes the password is needed just to load the file.
 */
int cpdf_fromFileLazy(const char[], const char[]);

/*
 * cpdf_fromMemory(data, length, userpw) loads a file from memory, given a
 * pointer and a length, and the user password.
 */
int cpdf_fromMemory(void *, int, const char[]);

/*
 * cpdf_fromMemory(data, length, userpw) loads a file from memory, given a
 * pointer and a length, and the user password, but lazily like
 * cpdf_fromFileLazy.
 */
int cpdf_fromMemoryLazy(void *, int, const char[]);

/* Remove a PDF from memory, given its number. */
void cpdf_deletePdf(int);

/*
 * Calling cpdf_replacePdf(a, b) places PDF b under number a. Number b is no
 * longer available.
 */
void cpdf_replacePdf(int, int);

/*
 * To enumerate the list of currently allocated PDFs, call
 * cpdf_startEnumeratePDFs which gives the number, n, of PDFs allocated, then
 * cpdf_enumeratePDFsInfo and cpdf_enumeratePDFsKey with index numbers from
 * 0...(n - 1). Call cpdf_endEnumeratePDFs to clean up.
 */
int cpdf_startEnumeratePDFs(void);
int cpdf_enumeratePDFsKey(int);
char *cpdf_enumeratePDFsInfo(int);
void cpdf_endEnumeratePDFs(void);

/* Convert a figure in centimetres to points (72 points to 1 inch) */
double cpdf_ptOfCm(double);

/* Convert a figure in millimetres to points (72 points to 1 inch) */
double cpdf_ptOfMm(double);

/* Convert a figure in inches to points (72 points to 1 inch) */
double cpdf_ptOfIn(double);

/* Convert a figure in points to centimetres (72 points to 1 inch) */
double cpdf_cmOfPt(double);

/* Convert a figure in points to millimetres (72 points to 1 inch) */
double cpdf_mmOfPt(double);

/* Convert a figure in points to inches (72 points to 1 inch) */
double cpdf_inOfPt(double);

/*
 * A page range is a list of page numbers used to restrict operations to
 * certain pages. A page specification is a textual description of a page
 * range, such as "1-12,18-end". Here is the syntax:
 *
 * o A range must contain no spaces.
 *
 * o A dash (-) defines ranges, e.g. 1-5 or 6-3.
 *
 * o A comma (,) allows one to specify several ranges, e.g. 1-2,4-5.
 *
 * o The word end represents the last page number.
 *
 * o The words odd and even can be used in place of or at the end of a page
 * range to restrict to just the odd or even pages.
 *
 * o The words portrait and landscape can be used in place of or at the end of
 * a page range to restrict to just those pages which are portrait or
 * landscape. Note that the meaning of "portrait" and "landscape" does not
 * take account of any viewing rotation in place (use cpdf_upright first, if
 * required). A page with equal width and height is considered neither
 * portrait nor landscape.
 *
 * o The word reverse is the same as end-1.
 *
 * o The word all is the same as 1-end.
 *
 * o A tilde (~) defines a page number counting from the end of the document
 * rather than the beginning. Page ~1 is the last page, ~2 the penultimate
 * page etc.
 */

/*
 * cpdf_parsePagespec(pdf, range) parses a page specification with reference
 * to a given PDF (the PDF is supplied so that page ranges which reference
 * pages which do not exist are rejected).
 */
int cpdf_parsePagespec(int, const char[]);

/*
 * cpdf_validatePagespec(range) validates a page specification so far as is
 * possible in the absence of the actual document. Result is true if valid.
 */
int cpdf_validatePagespec(const char[]);

/*
 * cpdf_stringOfPagespec(pdf, range) builds a page specification from a page
 * range. For example, the range containing 1,2,3,6,7,8 in a document of 8
 * pages might yield "1-3,6-end"
 */
char *cpdf_stringOfPagespec(int, int);

/* cpdf_blankRange() creates a range with no pages in. */
int cpdf_blankRange(void);

/* cpdf_deleteRange(range) deletes a range. */
void cpdf_deleteRange(int);

/*
 * cpdf_range(from, to) builds a range from one page to another inclusive. For
 * example, cpdf_range(3,7) gives the range 3,4,5,6,7
 */
int cpdf_range(int, int);

/* cpdf_all(pdf) is the range containing all the pages in a given document. */
int cpdf_all(int);

/*
 * cpdf_even(range) makes a range which contains just the even pages of
 * another range.
 */
int cpdf_even(int);

/*
 * cpdf_odd(range) makes a range which contains just the odd pages of another
 * range.
 */
int cpdf_odd(int);

/*
 * cpdf_rangeUnion(a, b) makes the union of two ranges giving a range
 * containing the pages in range a and range b.
 */
int cpdf_rangeUnion(int, int);

/*
 * cpdf_difference(a, b) makes the difference of two ranges, giving a range
 * containing all the pages in a except for those which are also in b.
 */
int cpdf_difference(int, int);

/* cpdf_removeDuplicates(range) deduplicates a range, making a new one. */
int cpdf_removeDuplicates(int);

/* cpdf_rangeLength gives the number of pages in a range. */
int cpdf_rangeLength(int);

/*
 * cpdf_rangeGet(range, n) gets the page number at position n in a range,
 * where n runs from 0 to rangeLength - 1.
 */
int cpdf_rangeGet(int, int);

/*
 * cpdf_rangeAdd(range, page) adds the page to a range, if it is not already
 * there.
 */
int cpdf_rangeAdd(int, int);

/*
 * cpdf_isInRange(range, page) returns true if the page is in the range,
 * false otherwise.
 */
int cpdf_isInRange(int, int);

/* cpdf_pages(pdf) returns the number of pages in a PDF. */
int cpdf_pages(int);

/*
 * cpdf_pagesFast(password, filename) returns the number of pages in a given
 * PDF, with given user encryption password. It tries to do this as fast as
 * possible, without loading the whole file.
 */
int cpdf_pagesFast(const char[], const char[]);

/*
 * cpdf_toFile (pdf, filename, linearize, make_id) writes the file to a given
 * filename. If linearize is true, it will be linearized if a linearizer is
 * available. If make_id is true, it will be given a new ID.
 *
 * NB: Unlike with the command line tool, cpdf, streams decompressed during
 * processing will not automatically be compressed when writing. Call
 * cpdf_compress() first.
 */
void cpdf_toFile(int, const char[], int, int);

/*
 * cpdf_toFileExt (pdf, filename, linearize, make_id, preserve_objstm,
 * generate_objstm, compress_objstm) writes the file to a given filename. If
 * make_id is true, it will be given a new ID.  If preserve_objstm is true,
 * existing object streams will be preserved. If generate_objstm is true,
 * object streams will be generated even if not originally present. If
 * compress_objstm is true, object streams will be compressed (what we
 * usually want). WARNING: the pdf argument will be invalid after this call,
 * and should be discarded.
 */
void cpdf_toFileExt(int, const char[], int, int, int, int, int);

/*
 * cpdf_toFileMemory (pdf, linearize, make_id, sizse) writes a PDF file it
 * and returns the buffer. The buffer length is filled in.
 *
 * NB: Unlike with the command line tool, cpdf, streams decompressed during
 * processing will not automatically be compressed when writing. Call
 * cpdf_compress() first.
 */
void *cpdf_toMemory(int, int, int, int *);

/*
 * cpdf_isEncrypted(pdf) returns true if a documented is encrypted, false
 * otherwise.
 */
int cpdf_isEncrypted(int);

/*
 * cpdf_decryptPdf(pdf, userpw) attempts to decrypt a PDF using the given
 * user password. The error code is non-zero if the decryption fails.
 */
void cpdf_decryptPdf(int, const char[]);

/*
 * cpdf_decryptPdfOwner(pdf, ownerpw) attempts to decrypt a PDF using the
 * given owner password. The error code is non-zero if the decryption fails.
 */
void cpdf_decryptPdfOwner(int, const char[]);

/*
 * File permissions. These are inverted, in the sense that the presence of
 * one of them indicates a restriction.
 */
enum cpdf_permission {
  cpdf_noEdit,     /* Cannot edit the document */
  cpdf_noPrint,    /* Cannot print the document */
  cpdf_noCopy,     /* Cannot copy the document */
  cpdf_noAnnot,    /* Cannot annotate the document */
  cpdf_noForms,    /* Cannot edit forms in the document */
  cpdf_noExtract,  /* Cannot extract information */
  cpdf_noAssemble, /* Cannot assemble into a bigger document */
  cpdf_noHqPrint   /* Cannot print high quality */
};

/*
 * Encryption methods. Suffixes 'false' and 'true' indicates lack of or
 * presence of encryption for XMP metadata streams.
 */
enum cpdf_encryptionMethod {
  cpdf_pdf40bit,          /* 40 bit RC4 encryption */
  cpdf_pdf128bit,         /* 128 bit RC4 encryption */
  cpdf_aes128bitfalse,    /* 128 bit AES encryption, do not encrypt
                           * metadata. */
  cpdf_aes128bittrue,     /* 128 bit AES encryption, encrypt metadata */
  cpdf_aes256bitfalse,    /* Deprecated. Do not use for new files */
  cpdf_aes256bittrue,     /* Deprecated. Do not use for new files */
  cpdf_aes256bitisofalse, /* 256 bit AES encryption, do not encrypt
                           * metadata. */
  cpdf_aes256bitisotrue   /* 256 bit AES encryption, encrypt metadata */
};

/*
 * cpdf_toFileEncrypted(pdf, encryption_method, permissions,
 * permission_length, owner_password, user password, linearize, makeid,
 * filename) writes a file as encrypted.
 */
void cpdf_toFileEncrypted(int, int, int *, int, const char[], const char[], int,
                          int, const char[]);

/*
 * cpdf_toFileEncryptedExt(pdf, encryption_method, permissions,
 * permission_length, owner_password, user_password, linearize, makeid,
 * preserve_objstm, generate_objstm, compress_objstm, filename) WARNING: the
 * pdf argument will be invalid after this call, and should be discarded.
 */
void cpdf_toFileEncryptedExt(int, int, int *, int, const char[], const char[],
                             int, int, int, int, int, const char[]);

/*
 * cpdf_hasPermission(pdf, permission) returns true if the given permission
 * (restriction) is present.
 */
int cpdf_hasPermission(int, enum cpdf_permission);

/*
 * cpdf_encryptionKind(pdf) return the encryption method currently in use on
 * a document.
 */
enum cpdf_encryptionMethod cpdf_encryptionKind(int);

/* cpdf_loadFont(name, filename) loads a TrueType font from the given file
 * name, and names it. It may then be used when adding text or drawing, using
 * the name in place of a standard font name. */
void cpdf_loadFont(char *, char *);