document.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. #ifndef MUPDF_PDF_DOCUMENT_H
  2. #define MUPDF_PDF_DOCUMENT_H
  3. typedef struct pdf_lexbuf_s pdf_lexbuf;
  4. typedef struct pdf_lexbuf_large_s pdf_lexbuf_large;
  5. typedef struct pdf_xref_s pdf_xref;
  6. typedef struct pdf_crypt_s pdf_crypt;
  7. typedef struct pdf_ocg_descriptor_s pdf_ocg_descriptor;
  8. typedef struct pdf_portfolio_s pdf_portfolio;
  9. typedef struct pdf_page_s pdf_page;
  10. typedef struct pdf_annot_s pdf_annot;
  11. typedef struct pdf_widget_s pdf_widget;
  12. typedef struct pdf_hotspot_s pdf_hotspot;
  13. typedef struct pdf_js_s pdf_js;
  14. enum
  15. {
  16. PDF_LEXBUF_SMALL = 256,
  17. PDF_LEXBUF_LARGE = 65536
  18. };
  19. struct pdf_lexbuf_s
  20. {
  21. int size;
  22. int base_size;
  23. int len;
  24. fz_off_t i;
  25. float f;
  26. char *scratch;
  27. char buffer[PDF_LEXBUF_SMALL];
  28. };
  29. struct pdf_lexbuf_large_s
  30. {
  31. pdf_lexbuf base;
  32. char buffer[PDF_LEXBUF_LARGE - PDF_LEXBUF_SMALL];
  33. };
  34. struct pdf_hotspot_s
  35. {
  36. int num;
  37. int state;
  38. };
  39. /*
  40. Document event structures are mostly opaque to the app. Only the type
  41. is visible to the app.
  42. */
  43. typedef struct pdf_doc_event_s pdf_doc_event;
  44. /*
  45. pdf_doc_event_cb: the type of function via which the app receives
  46. document events.
  47. */
  48. typedef void (pdf_doc_event_cb)(fz_context *ctx, pdf_document *doc, pdf_doc_event *event, void *data);
  49. /*
  50. pdf_open_document: Open a PDF document.
  51. Open a PDF document by reading its cross reference table, so
  52. MuPDF can locate PDF objects inside the file. Upon an broken
  53. cross reference table or other parse errors MuPDF will restart
  54. parsing the file from the beginning to try to rebuild a
  55. (hopefully correct) cross reference table to allow further
  56. processing of the file.
  57. The returned pdf_document should be used when calling most
  58. other PDF functions. Note that it wraps the context, so those
  59. functions implicitly get access to the global state in
  60. context.
  61. filename: a path to a file as it would be given to open(2).
  62. */
  63. pdf_document *pdf_open_document(fz_context *ctx, const char *filename);
  64. /*
  65. pdf_open_document_with_stream: Opens a PDF document.
  66. Same as pdf_open_document, but takes a stream instead of a
  67. filename to locate the PDF document to open. Increments the
  68. reference count of the stream. See fz_open_file,
  69. fz_open_file_w or fz_open_fd for opening a stream, and
  70. fz_drop_stream for closing an open stream.
  71. */
  72. pdf_document *pdf_open_document_with_stream(fz_context *ctx, fz_stream *file);
  73. /*
  74. pdf_drop_document: Closes and frees an opened PDF document.
  75. The resource store in the context associated with pdf_document
  76. is emptied.
  77. Does not throw exceptions.
  78. */
  79. void pdf_drop_document(fz_context *ctx, pdf_document *doc);
  80. /*
  81. pdf_specifics: down-cast a fz_document to a pdf_document.
  82. Returns NULL if underlying document is not PDF
  83. */
  84. pdf_document *pdf_specifics(fz_context *ctx, fz_document *doc);
  85. /*
  86. pdf_document_from_fz_document,
  87. pdf_page_from_fz_page,
  88. pdf_annot_from_fz_annot:
  89. Down-cast generic fitz objects into pdf specific variants.
  90. Returns NULL if the objects are not from a PDF document.
  91. */
  92. pdf_document *pdf_document_from_fz_document(fz_context *ctx, fz_document *ptr);
  93. pdf_page *pdf_page_from_fz_page(fz_context *ctx, fz_page *ptr);
  94. pdf_annot *pdf_annot_from_fz_annot(fz_context *ctx, fz_annot *ptr);
  95. int pdf_needs_password(fz_context *ctx, pdf_document *doc);
  96. /*
  97. pdf_authenticate_password: Attempt to authenticate a
  98. password.
  99. Returns 0 for failure, non-zero for success.
  100. In the non-zero case:
  101. bit 0 set => no password required
  102. bit 1 set => user password authenticated
  103. bit 2 set => owner password authenticated
  104. */
  105. int pdf_authenticate_password(fz_context *ctx, pdf_document *doc, const char *pw);
  106. int pdf_has_permission(fz_context *ctx, pdf_document *doc, fz_permission p);
  107. int pdf_lookup_metadata(fz_context *ctx, pdf_document *doc, const char *key, char *ptr, int size);
  108. fz_outline *pdf_load_outline(fz_context *ctx, pdf_document *doc);
  109. /*
  110. pdf_count_layer_configs: Get the number of layer
  111. configurations defined in this document.
  112. doc: The document in question.
  113. */
  114. int pdf_count_layer_configs(fz_context *ctx, pdf_document *doc);
  115. typedef struct
  116. {
  117. const char *name;
  118. const char *creator;
  119. } pdf_layer_config;
  120. /*
  121. pdf_layer_config_info: Fetch the name (and
  122. optionally creator) of the given layer config.
  123. doc: The document in question.
  124. config_num: A value in the 0..n-1 range, where n is the
  125. value returned from pdf_count_layer_configs.
  126. info: Pointer to structure to fill in. Pointers within
  127. this structure may be set to NULL if no information is
  128. available.
  129. */
  130. void pdf_layer_config_info(fz_context *ctx, pdf_document *doc, int config_num, pdf_layer_config *info);
  131. /*
  132. pdf_select_layer_config: Set the current configuration.
  133. This updates the visibility of the optional content groups
  134. within the document.
  135. doc: The document in question.
  136. config_num: A value in the 0..n-1 range, where n is the
  137. value returned from pdf_count_layer_configs.
  138. */
  139. void pdf_select_layer_config(fz_context *ctx, pdf_document *doc, int config_num);
  140. /*
  141. pdf_count_layer_config_ui: Returns the number of entries in the
  142. 'UI' for this layer configuration.
  143. doc: The document in question.
  144. */
  145. int pdf_count_layer_config_ui(fz_context *ctx, pdf_document *doc);
  146. /*
  147. pdf_select_layer_ui: Select a checkbox/radiobox
  148. within the 'UI' for this layer configuration.
  149. Selecting a UI entry that is a radiobox may disable
  150. other UI entries.
  151. doc: The document in question.
  152. ui: A value in the 0..m-1 range, where m is the value
  153. returned by pdf_count_layer_config_ui.
  154. */
  155. void pdf_select_layer_config_ui(fz_context *ctx, pdf_document *doc, int ui);
  156. /*
  157. pdf_deselect_layer_ui: Select a checkbox/radiobox
  158. within the 'UI' for this layer configuration.
  159. doc: The document in question.
  160. ui: A value in the 0..m-1 range, where m is the value
  161. returned by pdf_count_layer_config_ui.
  162. */
  163. void pdf_deselect_layer_config_ui(fz_context *ctx, pdf_document *doc, int ui);
  164. /*
  165. pdf_toggle_layer_config_ui: Toggle a checkbox/radiobox
  166. within the 'UI' for this layer configuration.
  167. Toggling a UI entry that is a radiobox may disable
  168. other UI entries.
  169. doc: The document in question.
  170. ui: A value in the 0..m-1 range, where m is the value
  171. returned by pdf_count_layer_config_ui.
  172. */
  173. void pdf_toggle_layer_config_ui(fz_context *ctx, pdf_document *doc, int ui);
  174. typedef enum
  175. {
  176. PDF_LAYER_UI_LABEL = 0,
  177. PDF_LAYER_UI_CHECKBOX = 1,
  178. PDF_LAYER_UI_RADIOBOX = 2
  179. } pdf_layer_config_ui_type;
  180. typedef struct
  181. {
  182. const char *text;
  183. int depth;
  184. pdf_layer_config_ui_type type;
  185. int selected;
  186. int locked;
  187. } pdf_layer_config_ui;
  188. /*
  189. pdf_layer_config_ui_info: Get the info for a given
  190. entry in the layer config ui.
  191. doc: The document in question.
  192. ui: A value in the 0..m-1 range, where m is the value
  193. returned by pdf_count_layer_config_ui.
  194. info: Pointer to a structure to fill in with information
  195. about the requested ui entry.
  196. */
  197. void pdf_layer_config_ui_info(fz_context *ctx, pdf_document *doc, int ui, pdf_layer_config_ui *info);
  198. /*
  199. pdf_set_layer_config_as_default: Write the current layer
  200. config back into the document as the default state.
  201. */
  202. void pdf_set_layer_config_as_default(fz_context *ctx, pdf_document *doc);
  203. /*
  204. PDF portfolios (or collections) are embedded files. They can
  205. be thought of as tables of information, with an embedded
  206. file per row. For instance a PDF portfolio of an email box might
  207. contain:
  208. From To Cc Date
  209. message1.pdf ... ... ... ...
  210. message2.pdf ... ... ... ...
  211. etc. The details of the 'column headings' are known as the Schema.
  212. This includes the order to use for the headings.
  213. Each row in the table is a portfolio (or collection) entry.
  214. */
  215. /*
  216. pdf_count_portfolio_schema: Get the number of entries in the
  217. portfolio schema used in this document.
  218. doc: The document in question.
  219. */
  220. int pdf_count_portfolio_schema(fz_context *ctx, pdf_document *doc);
  221. typedef enum
  222. {
  223. PDF_SCHEMA_NUMBER,
  224. PDF_SCHEMA_SIZE,
  225. PDF_SCHEMA_TEXT,
  226. PDF_SCHEMA_DATE,
  227. PDF_SCHEMA_DESC,
  228. PDF_SCHEMA_MODDATE,
  229. PDF_SCHEMA_CREATIONDATE,
  230. PDF_SCHEMA_FILENAME,
  231. PDF_SCHEMA_UNKNOWN
  232. } pdf_portfolio_schema_type;
  233. typedef struct
  234. {
  235. pdf_portfolio_schema_type type;
  236. int visible;
  237. int editable;
  238. pdf_obj *name;
  239. } pdf_portfolio_schema;
  240. /*
  241. pdf_portfolio_schema_info: Fetch information about a given
  242. portfolio schema entry.
  243. doc: The document in question.
  244. entry: A value in the 0..n-1 range, where n is the
  245. value returned from pdf_count_portfolio_schema.
  246. info: Pointer to structure to fill in. Pointers within
  247. this structure may be set to NULL if no information is
  248. available.
  249. */
  250. void pdf_portfolio_schema_info(fz_context *ctx, pdf_document *doc, int entry, pdf_portfolio_schema *info);
  251. /*
  252. pdf_reorder_portfolio_schema: Reorder the portfolio schema.
  253. doc: The document in question.
  254. entry: A value in the 0..n-1 range, where n is the
  255. value returned from pdf_count_portfolio_schema - the
  256. position of the entry to move.
  257. new_pos: A value in the 0..n-1 range, where n is the
  258. value returned from pdf_count_portfolio_schema - the
  259. position to move the entry to.
  260. */
  261. void pdf_reorder_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, int new_pos);
  262. /*
  263. pdf_rename_portfolio_schema: rename a given portfolio
  264. schema entry.
  265. doc: The document in question.
  266. entry: The entry to renumber.
  267. name: The new name for the portfolio schema
  268. name_len: The byte length of the name.
  269. */
  270. void pdf_rename_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, const char *name, int name_len);
  271. /*
  272. pdf_delete_portfolio_schema: delete a given portfolio
  273. schema entry.
  274. doc: The document in question.
  275. entry: The entry to delete.
  276. */
  277. void pdf_delete_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry);
  278. /*
  279. pdf_add_portfolio_schema: Add a new portfolio schema
  280. entry.
  281. doc: The document in question.
  282. entry: The point in the ordering at which to insert the new
  283. schema entry.
  284. info: Details of the schema entry.
  285. */
  286. void pdf_add_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, const pdf_portfolio_schema *info);
  287. /*
  288. pdf_count_portfolio_entries: Get the number of portfolio entries
  289. in this document.
  290. doc: The document in question.
  291. */
  292. int pdf_count_portfolio_entries(fz_context *ctx, pdf_document *doc);
  293. /*
  294. pdf_portfolio_entry: Create a buffer containing
  295. a decoded portfolio entry.
  296. doc: The document in question.
  297. entry: A value in the 0..m-1 range, where m is the
  298. value returned from pdf_count_portfolio_entries.
  299. Returns a buffer containing the decoded portfolio
  300. entry. Ownership of the buffer passes to the caller.
  301. */
  302. fz_buffer *pdf_portfolio_entry(fz_context *ctx, pdf_document *doc, int entry);
  303. /*
  304. pdf_portfolio_entry_obj_name: Retrieve the object and
  305. name of a given portfolio entry.
  306. doc: The document in question.
  307. entry: A value in the 0..m-1 range, where m is the
  308. value returned from pdf_count_portfolio_entries.
  309. name: Pointer to a place to store the pointer to the
  310. object representing the name. This is a borrowed
  311. reference - do not drop it.
  312. Returns a pointer to the pdf_object representing the
  313. object. This is a borrowed reference - do not drop
  314. it.
  315. */
  316. pdf_obj *pdf_portfolio_entry_obj_name(fz_context *ctx, pdf_document *doc, int entry, pdf_obj **name);
  317. /*
  318. pdf_portfolio_entry_obj: Retrieve the object
  319. representing a given portfolio entry.
  320. doc: The document in question.
  321. entry: A value in the 0..m-1 range, where m is the
  322. value returned from pdf_count_portfolio_entries.
  323. Returns a pointer to the pdf_object representing the
  324. object. This is a borrowed reference - do not drop
  325. it.
  326. */
  327. pdf_obj *pdf_portfolio_entry_obj(fz_context *ctx, pdf_document *doc, int entry);
  328. /*
  329. pdf_portfolio_entry_name: Retrieve the name of
  330. a given portfolio entry.
  331. doc: The document in question.
  332. entry: A value in the 0..m-1 range, where m is the
  333. value returned from pdf_count_portfolio_entries.
  334. name: Pointer to a place to store the pointer to the
  335. object representing the name. This is a borrowed
  336. reference - do not drop it.
  337. Returns a pointer to the pdf_object representing the
  338. name of the entry. This is a borrowed reference - do not drop
  339. it.
  340. */
  341. pdf_obj *pdf_portfolio_entry_name(fz_context *ctx, pdf_document *doc, int entry);
  342. /*
  343. pdf_portfolio_entry_info: Fetch information about a given
  344. portfolio entry.
  345. doc: The document in question.
  346. entry: A value in the 0..m-1 range, where m is the
  347. value returned from pdf_count_portfolio_entries.
  348. info: Pointer to structure to fill in. Pointers within
  349. this structure may be set to NULL if no information is
  350. available.
  351. */
  352. pdf_obj *pdf_portfolio_entry_info(fz_context *ctx, pdf_document *doc, int entry, int schema_entry);
  353. /*
  354. pdf_add_portfolio_entry: Add a new portfolio entry.
  355. doc: The document in question.
  356. name: The name to use for this entry (as used in the
  357. PDF name tree for the collection).
  358. name_len: The byte length of name.
  359. desc: The description to use for this entry (as used
  360. in the 'Desc' entry in the Collection entry).
  361. desc_len: The byte length of desc.
  362. filename: The filename to use for this entry (as used
  363. in the 'F' entry in the collection entry).
  364. filename_len: The byte length of filename.
  365. unifilename: The filename to use for this entry (as used
  366. in the 'UF' entry in the collection entry).
  367. unifilename_len: The byte length of unifilename.
  368. buf: The buffer containing the embedded file to add.
  369. Returns the entry number for this new entry.
  370. */
  371. int pdf_add_portfolio_entry(fz_context *ctx, pdf_document *doc,
  372. const char *name, int name_len,
  373. const char *desc, int desc_len,
  374. const char *filename, int filename_len,
  375. const char *unifile, int unifile_len, fz_buffer *buf);
  376. /*
  377. pdf_set_portfolio_entry_info: Set part of the entry
  378. information for a given portfolio entry.
  379. doc: The document in question.
  380. entry: The portfolio entry to set information for.
  381. In the range 0..m-1, where m is the value returned
  382. from pdf_count_portfolio_entries.
  383. schema_entry: Which schema entry to set (in the
  384. range 0..n-1, where n is the value returned from
  385. pdf_count_portfolio_schema.
  386. data: The value to set.
  387. */
  388. void pdf_set_portfolio_entry_info(fz_context *ctx, pdf_document *doc, int entry, int schema_entry, pdf_obj *data);
  389. /*
  390. pdf_update_page: update a page for the sake of changes caused by a call
  391. to pdf_pass_event. pdf_update_page regenerates any appearance streams that
  392. are out of date, checks for cases where different appearance streams
  393. should be selected because of state changes, and records internally
  394. each annotation that has changed appearance. The list of changed annotations
  395. is then available via querying the annot->changed flag. Note that a call to
  396. pdf_pass_event for one page may lead to changes on any other, so an app
  397. should call pdf_update_page for every page it currently displays. Also
  398. it is important that the pdf_page object is the one used to last render
  399. the page. If instead the app were to drop the page and reload it then
  400. a call to pdf_update_page would not reliably be able to report all changed
  401. areas.
  402. */
  403. void pdf_update_page(fz_context *ctx, pdf_page *page);
  404. /*
  405. Determine whether changes have been made since the
  406. document was opened or last saved.
  407. */
  408. int pdf_has_unsaved_changes(fz_context *ctx, pdf_document *doc);
  409. typedef struct pdf_signer_s pdf_signer;
  410. /* Unsaved signature fields */
  411. typedef struct pdf_unsaved_sig_s pdf_unsaved_sig;
  412. struct pdf_unsaved_sig_s
  413. {
  414. pdf_obj *field;
  415. int byte_range_start;
  416. int byte_range_end;
  417. int contents_start;
  418. int contents_end;
  419. pdf_signer *signer;
  420. pdf_unsaved_sig *next;
  421. };
  422. typedef struct pdf_rev_page_map_s pdf_rev_page_map;
  423. struct pdf_rev_page_map_s
  424. {
  425. int page;
  426. int object;
  427. };
  428. struct pdf_document_s
  429. {
  430. fz_document super;
  431. fz_stream *file;
  432. int version;
  433. fz_off_t startxref;
  434. fz_off_t file_size;
  435. pdf_crypt *crypt;
  436. pdf_ocg_descriptor *ocg;
  437. pdf_portfolio *portfolio;
  438. pdf_hotspot hotspot;
  439. int max_xref_len;
  440. int num_xref_sections;
  441. int saved_num_xref_sections;
  442. int num_incremental_sections;
  443. int xref_base;
  444. int disallow_new_increments;
  445. pdf_xref *xref_sections;
  446. pdf_xref *saved_xref_sections;
  447. int *xref_index;
  448. int freeze_updates;
  449. int has_xref_streams;
  450. int page_count;
  451. pdf_rev_page_map *rev_page_map;
  452. int repair_attempted;
  453. /* State indicating which file parsing method we are using */
  454. int file_reading_linearly;
  455. fz_off_t file_length;
  456. pdf_obj *linear_obj; /* Linearized object (if used) */
  457. pdf_obj **linear_page_refs; /* Page objects for linear loading */
  458. int linear_page1_obj_num;
  459. /* The state for the pdf_progressive_advance parser */
  460. fz_off_t linear_pos;
  461. int linear_page_num;
  462. int hint_object_offset;
  463. int hint_object_length;
  464. int hints_loaded; /* Set to 1 after the hints loading has completed,
  465. * whether successful or not! */
  466. /* Page n references shared object references:
  467. * hint_shared_ref[i]
  468. * where
  469. * i = s to e-1
  470. * s = hint_page[n]->index
  471. * e = hint_page[n+1]->index
  472. * Shared object reference r accesses objects:
  473. * rs to re-1
  474. * where
  475. * rs = hint_shared[r]->number
  476. * re = hint_shared[r]->count + rs
  477. * These are guaranteed to lie within the region starting at
  478. * hint_shared[r]->offset of length hint_shared[r]->length
  479. */
  480. struct
  481. {
  482. int number; /* Page object number */
  483. fz_off_t offset; /* Offset of page object */
  484. fz_off_t index; /* Index into shared hint_shared_ref */
  485. } *hint_page;
  486. int *hint_shared_ref;
  487. struct
  488. {
  489. int number; /* Object number of first object */
  490. fz_off_t offset; /* Offset of first object */
  491. } *hint_shared;
  492. int hint_obj_offsets_max;
  493. fz_off_t *hint_obj_offsets;
  494. int resources_localised;
  495. pdf_lexbuf_large lexbuf;
  496. pdf_annot *focus;
  497. pdf_obj *focus_obj;
  498. pdf_js *js;
  499. int recalculating;
  500. int dirty;
  501. void (*update_appearance)(fz_context *ctx, pdf_document *doc, pdf_annot *annot);
  502. pdf_doc_event_cb *event_cb;
  503. void *event_cb_data;
  504. int num_type3_fonts;
  505. int max_type3_fonts;
  506. fz_font **type3_fonts;
  507. struct {
  508. fz_hash_table *images;
  509. fz_hash_table *fonts;
  510. } resources;
  511. int orphans_max;
  512. int orphans_count;
  513. pdf_obj **orphans;
  514. };
  515. /*
  516. PDF creation
  517. */
  518. /*
  519. pdf_create_document: Create a blank PDF document
  520. */
  521. pdf_document *pdf_create_document(fz_context *ctx);
  522. /*
  523. Deep copy objects between documents.
  524. */
  525. typedef struct pdf_graft_map_s pdf_graft_map;
  526. pdf_graft_map *pdf_new_graft_map(fz_context *ctx, pdf_document *src);
  527. void pdf_drop_graft_map(fz_context *ctx, pdf_graft_map *map);
  528. pdf_obj *pdf_graft_object(fz_context *ctx, pdf_document *dst, pdf_document *src, pdf_obj *obj, pdf_graft_map *map);
  529. /*
  530. pdf_page_write: Create a device that will record the
  531. graphical operations given to it into a sequence of
  532. pdf operations, together with a set of resources. This
  533. sequence/set pair can then be used as the basis for
  534. adding a page to the document (see pdf_add_page).
  535. doc: The document for which these are intended.
  536. mediabox: The bbox for the created page.
  537. presources: Pointer to a place to put the created
  538. resources dictionary.
  539. pcontents: Pointer to a place to put the created
  540. contents buffer.
  541. */
  542. fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, const fz_rect *mediabox, pdf_obj **presources, fz_buffer **pcontents);
  543. /*
  544. pdf_add_page: Create a pdf_obj within a document that
  545. represents a page, from a previously created resources
  546. dictionary and page content stream. This should then be
  547. inserted into the document using pdf_insert_page.
  548. After this call the page exists within the document
  549. structure, but is not actually ever displayed as it is
  550. not linked into the PDF page tree.
  551. doc: The document to which to add the page.
  552. mediabox: The mediabox for the page (should be identical
  553. to that used when creating the resources/contents).
  554. rotate: 0, 90, 180 or 270. The rotation to use for the
  555. page.
  556. resources: The resources dictionary for the new page
  557. (typically created by pdf_page_write).
  558. contents: The page contents for the new page (typically
  559. create by pdf_page_write).
  560. */
  561. pdf_obj *pdf_add_page(fz_context *ctx, pdf_document *doc, const fz_rect *mediabox, int rotate, pdf_obj *resources, fz_buffer *contents);
  562. /*
  563. pdf_insert_page: Insert a page previously created by
  564. pdf_add_page into the pages tree of the document.
  565. doc: The document to insert into.
  566. at: The page number to insert at. 0 inserts at the start.
  567. negative numbers, or INT_MAX insert at the end. Otherwise
  568. n inserts after page n.
  569. page: The page to insert.
  570. */
  571. void pdf_insert_page(fz_context *ctx, pdf_document *doc, int at, pdf_obj *page);
  572. /*
  573. pdf_delete_page: Delete a page from the page tree of
  574. a document. This does not remove the page contents
  575. or resources from the file.
  576. doc: The document to operate on.
  577. number: The page to remove (numbered from 0)
  578. */
  579. void pdf_delete_page(fz_context *ctx, pdf_document *doc, int number);
  580. /*
  581. pdf_delete_page_range: Delete a range of pages from the
  582. page tree of a document. This does not remove the page
  583. contents or resources from the file.
  584. doc: The document to operate on.
  585. start, end: The range of pages (numbered from 0)
  586. (inclusive, exclusive) to remove. If end is negative or
  587. greater than the number of pages in the document, it
  588. will be taken to be the end of the document.
  589. */
  590. void pdf_delete_page_range(fz_context *ctx, pdf_document *doc, int start, int end);
  591. /*
  592. pdf_finish_edit: Called after any editing operations
  593. on a document have completed, this will tidy up
  594. the document. For now this is restricted to
  595. rebalancing the page tree, but may be extended
  596. in the future.
  597. */
  598. void pdf_finish_edit(fz_context *ctx, pdf_document *doc);
  599. int pdf_recognize(fz_context *doc, const char *magic);
  600. typedef struct pdf_write_options_s pdf_write_options;
  601. /*
  602. In calls to fz_save_document, the following options structure can be used
  603. to control aspects of the writing process. This structure may grow
  604. in the future, and should be zero-filled to allow forwards compatibility.
  605. */
  606. struct pdf_write_options_s
  607. {
  608. int do_incremental; /* Write just the changed objects. */
  609. int do_pretty; /* Pretty-print dictionaries and arrays. */
  610. int do_ascii; /* ASCII hex encode binary streams. */
  611. int do_compress; /* Compress streams. */
  612. int do_compress_images; /* Compress (or leave compressed) image streams. */
  613. int do_compress_fonts; /* Compress (or leave compressed) font streams. */
  614. int do_decompress; /* Decompress streams (except when compressing images/fonts). */
  615. int do_garbage; /* Garbage collect objects before saving; 1=gc, 2=re-number, 3=de-duplicate. */
  616. int do_linear; /* Write linearised. */
  617. int do_clean; /* Sanitize content streams. */
  618. int continue_on_error; /* If set, errors are (optionally) counted and writing continues. */
  619. int *errors; /* Pointer to a place to store a count of errors */
  620. };
  621. /*
  622. Parse option string into a pdf_write_options struct.
  623. Matches the command line options to 'mutool clean':
  624. g: garbage collect
  625. d, i, f: expand all, fonts, images
  626. l: linearize
  627. a: ascii hex encode
  628. z: deflate
  629. s: sanitize content streams
  630. */
  631. pdf_write_options *pdf_parse_write_options(fz_context *ctx, pdf_write_options *opts, const char *args);
  632. /*
  633. pdf_has_unsaved_sigs: Returns true if there are digital signatures waiting to
  634. to updated on save.
  635. */
  636. int pdf_has_unsaved_sigs(fz_context *ctx, pdf_document *doc);
  637. /*
  638. pdf_write_document: Write out the document to an output stream with all changes finalised.
  639. This method will throw an error if pdf_has_unsaved_sigs.
  640. */
  641. void pdf_write_document(fz_context *ctx, pdf_document *doc, fz_output *out, pdf_write_options *opts);
  642. /*
  643. pdf_save_document: Write out the document to a file with all changes finalised.
  644. */
  645. void pdf_save_document(fz_context *ctx, pdf_document *doc, const char *filename, pdf_write_options *opts);
  646. /*
  647. pdf_can_be_saved_incrementally: Return true if the document can be saved
  648. incrementally. (e.g. it has not been repaired, and it is not encrypted)
  649. */
  650. int pdf_can_be_saved_incrementally(fz_context *ctx, pdf_document *doc);
  651. #endif