Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
7638 views
1
#ifndef MUPDF_PDF_DOCUMENT_H
2
#define MUPDF_PDF_DOCUMENT_H
3
4
typedef struct pdf_lexbuf_s pdf_lexbuf;
5
typedef struct pdf_lexbuf_large_s pdf_lexbuf_large;
6
typedef struct pdf_xref_s pdf_xref;
7
typedef struct pdf_crypt_s pdf_crypt;
8
typedef struct pdf_ocg_descriptor_s pdf_ocg_descriptor;
9
10
typedef struct pdf_page_s pdf_page;
11
typedef struct pdf_annot_s pdf_annot;
12
typedef struct pdf_widget_s pdf_widget;
13
typedef struct pdf_hotspot_s pdf_hotspot;
14
typedef struct pdf_js_s pdf_js;
15
16
enum
17
{
18
PDF_LEXBUF_SMALL = 256,
19
PDF_LEXBUF_LARGE = 65536
20
};
21
22
struct pdf_lexbuf_s
23
{
24
int size;
25
int base_size;
26
int len;
27
int i;
28
float f;
29
char *scratch;
30
char buffer[PDF_LEXBUF_SMALL];
31
};
32
33
struct pdf_lexbuf_large_s
34
{
35
pdf_lexbuf base;
36
char buffer[PDF_LEXBUF_LARGE - PDF_LEXBUF_SMALL];
37
};
38
39
struct pdf_hotspot_s
40
{
41
int num;
42
int gen;
43
int state;
44
};
45
46
/*
47
Document event structures are mostly opaque to the app. Only the type
48
is visible to the app.
49
*/
50
typedef struct pdf_doc_event_s pdf_doc_event;
51
52
/*
53
pdf_doc_event_cb: the type of function via which the app receives
54
document events.
55
*/
56
typedef void (pdf_doc_event_cb)(fz_context *ctx, pdf_document *doc, pdf_doc_event *event, void *data);
57
58
/*
59
pdf_open_document: Open a PDF document.
60
61
Open a PDF document by reading its cross reference table, so
62
MuPDF can locate PDF objects inside the file. Upon an broken
63
cross reference table or other parse errors MuPDF will restart
64
parsing the file from the beginning to try to rebuild a
65
(hopefully correct) cross reference table to allow further
66
processing of the file.
67
68
The returned pdf_document should be used when calling most
69
other PDF functions. Note that it wraps the context, so those
70
functions implicitly get access to the global state in
71
context.
72
73
filename: a path to a file as it would be given to open(2).
74
*/
75
pdf_document *pdf_open_document(fz_context *ctx, const char *filename);
76
77
/*
78
pdf_open_document_with_stream: Opens a PDF document.
79
80
Same as pdf_open_document, but takes a stream instead of a
81
filename to locate the PDF document to open. Increments the
82
reference count of the stream. See fz_open_file,
83
fz_open_file_w or fz_open_fd for opening a stream, and
84
fz_drop_stream for closing an open stream.
85
*/
86
pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file);
87
88
/*
89
pdf_close_document: Closes and frees an opened PDF document.
90
91
The resource store in the context associated with pdf_document
92
is emptied.
93
94
Does not throw exceptions.
95
*/
96
void pdf_close_document(fz_context *ctx, pdf_document *doc);
97
98
/*
99
pdf_specific: down-cast an fz_document to a pdf_document.
100
Returns NULL if underlying document is not PDF
101
*/
102
pdf_document *pdf_specifics(fz_context *ctx, fz_document *doc);
103
104
int pdf_needs_password(fz_context *ctx, pdf_document *doc);
105
int pdf_authenticate_password(fz_context *ctx, pdf_document *doc, const char *pw);
106
107
int pdf_has_permission(fz_context *ctx, pdf_document *doc, fz_permission p);
108
int pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *ptr, int size);
109
110
fz_outline *pdf_load_outline(fz_context *ctx, pdf_document *doc);
111
112
typedef struct pdf_ocg_entry_s pdf_ocg_entry;
113
114
struct pdf_ocg_entry_s
115
{
116
int num;
117
int gen;
118
int state;
119
};
120
121
struct pdf_ocg_descriptor_s
122
{
123
int len;
124
pdf_ocg_entry *ocgs;
125
pdf_obj *intent;
126
};
127
128
/*
129
pdf_update_page: update a page for the sake of changes caused by a call
130
to pdf_pass_event. pdf_update_page regenerates any appearance streams that
131
are out of date, checks for cases where different appearance streams
132
should be selected because of state changes, and records internally
133
each annotation that has changed appearance. The list of changed annotations
134
is then available via pdf_poll_changed_annot. Note that a call to
135
pdf_pass_event for one page may lead to changes on any other, so an app
136
should call pdf_update_page for every page it currently displays. Also
137
it is important that the pdf_page object is the one used to last render
138
the page. If instead the app were to drop the page and reload it then
139
a call to pdf_update_page would not reliably be able to report all changed
140
areas.
141
*/
142
void pdf_update_page(fz_context *ctx, pdf_document *doc, pdf_page *page);
143
144
/*
145
Determine whether changes have been made since the
146
document was opened or last saved.
147
*/
148
int pdf_has_unsaved_changes(fz_context *ctx, pdf_document *doc);
149
150
typedef struct pdf_signer_s pdf_signer;
151
152
/* Unsaved signature fields */
153
typedef struct pdf_unsaved_sig_s pdf_unsaved_sig;
154
155
struct pdf_unsaved_sig_s
156
{
157
pdf_obj *field;
158
int byte_range_start;
159
int byte_range_end;
160
int contents_start;
161
int contents_end;
162
pdf_signer *signer;
163
pdf_unsaved_sig *next;
164
};
165
166
struct pdf_document_s
167
{
168
fz_document super;
169
170
fz_stream *file;
171
172
int version;
173
int startxref;
174
int file_size;
175
pdf_crypt *crypt;
176
pdf_ocg_descriptor *ocg;
177
pdf_hotspot hotspot;
178
179
int max_xref_len;
180
int num_xref_sections;
181
pdf_xref *xref_sections;
182
int *xref_index;
183
int xref_altered;
184
int freeze_updates;
185
int has_xref_streams;
186
187
int page_count;
188
189
int repair_attempted;
190
191
/* State indicating which file parsing method we are using */
192
int file_reading_linearly;
193
int file_length;
194
195
pdf_obj *linear_obj; /* Linearized object (if used) */
196
pdf_obj **linear_page_refs; /* Page objects for linear loading */
197
int linear_page1_obj_num;
198
199
/* The state for the pdf_progressive_advance parser */
200
int linear_pos;
201
int linear_page_num;
202
203
int hint_object_offset;
204
int hint_object_length;
205
int hints_loaded; /* Set to 1 after the hints loading has completed,
206
* whether successful or not! */
207
/* Page n references shared object references:
208
* hint_shared_ref[i]
209
* where
210
* i = s to e-1
211
* s = hint_page[n]->index
212
* e = hint_page[n+1]->index
213
* Shared object reference r accesses objects:
214
* rs to re-1
215
* where
216
* rs = hint_shared[r]->number
217
* re = hint_shared[r]->count + rs
218
* These are guaranteed to lie within the region starting at
219
* hint_shared[r]->offset of length hint_shared[r]->length
220
*/
221
struct
222
{
223
int number; /* Page object number */
224
int offset; /* Offset of page object */
225
int index; /* Index into shared hint_shared_ref */
226
} *hint_page;
227
int *hint_shared_ref;
228
struct
229
{
230
int number; /* Object number of first object */
231
int offset; /* Offset of first object */
232
} *hint_shared;
233
int hint_obj_offsets_max;
234
int *hint_obj_offsets;
235
236
int resources_localised;
237
238
pdf_lexbuf_large lexbuf;
239
240
pdf_annot *focus;
241
pdf_obj *focus_obj;
242
243
pdf_js *js;
244
void (*drop_js)(pdf_js *js);
245
int recalculating;
246
int dirty;
247
pdf_unsaved_sig *unsaved_sigs;
248
249
void (*update_appearance)(fz_context *ctx, pdf_document *doc, pdf_annot *annot);
250
251
pdf_doc_event_cb *event_cb;
252
void *event_cb_data;
253
254
int num_type3_fonts;
255
int max_type3_fonts;
256
fz_font **type3_fonts;
257
};
258
259
/*
260
PDF creation
261
*/
262
263
/*
264
pdf_create_document: Create a blank PDF document
265
*/
266
pdf_document *pdf_create_document(fz_context *ctx);
267
268
pdf_page *pdf_create_page(fz_context *ctx, pdf_document *doc, fz_rect rect, int res, int rotate);
269
270
void pdf_insert_page(fz_context *ctx, pdf_document *doc, pdf_page *page, int at);
271
272
void pdf_delete_page(fz_context *ctx, pdf_document *doc, int number);
273
274
void pdf_delete_page_range(fz_context *ctx, pdf_document *doc, int start, int end);
275
276
fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, pdf_page *page);
277
278
void pdf_finish_edit(fz_context *ctx, pdf_document *doc);
279
280
int pdf_recognize(fz_context *doc, const char *magic);
281
282
#endif
283
284