void pdf_update_xobject_contents(pdf_document *doc, pdf_xobject *form, fz_buffer *buffer) { pdf_dict_dels(form->contents, "Filter"); pdf_dict_puts_drop(form->contents, "Length", pdf_new_int(doc, buffer->len)); pdf_update_stream(doc, pdf_to_num(form->contents), buffer); form->iteration ++; }
void pdfout_page_labels_set (fz_context *ctx, pdf_document *doc, pdfout_data *labels) { if (labels) check_page_labels (ctx, labels); pdf_obj *root = pdf_dict_get (ctx, pdf_trailer (ctx, doc), PDF_NAME_Root); if (root == NULL) pdfout_throw (ctx, "no document catalog, cannot set/unset page labels"); if (labels == NULL) { /* Remove page labels. */ pdf_dict_dels (ctx, root, "PageLabels"); return; } int num = pdfout_data_array_len (ctx, labels); pdf_obj *array_obj = pdf_new_array (ctx, doc, 2 * num); for (int i = 0; i < num; ++i) { pdfout_data *hash = pdfout_data_array_get (ctx, labels, i); int page; pdf_obj *dict_obj = hash_to_pdf_dict (ctx, doc, hash, &page); pdf_obj *page_obj = pdf_new_int (ctx, doc, page); pdf_array_push_drop (ctx, array_obj, page_obj); pdf_array_push_drop (ctx, array_obj, dict_obj); } pdf_obj *labels_obj = pdf_new_dict (ctx, doc, 1); pdf_dict_puts_drop (ctx, labels_obj, "Nums", array_obj); pdf_dict_puts_drop (ctx, root, "PageLabels", labels_obj); }
void pdf_update_xobject_contents(pdf_document *xref, pdf_xobject *form, fz_buffer *buffer) { fz_context *ctx = xref->ctx; pdf_obj *len = NULL; fz_var(len); fz_try(ctx) { len = pdf_new_int(ctx, buffer->len); pdf_dict_dels(form->contents, "Filter"); pdf_dict_puts(form->contents, "Length", len); pdf_update_stream(xref, pdf_to_num(form->contents), buffer); } fz_always(ctx) { pdf_drop_obj(len); } fz_catch(ctx) { fz_rethrow(ctx); } }
/* When resetting or submitting a form, the fields to act upon are defined by an array of either field references or field names, plus a flag determining whether to act upon the fields in the array, or all fields other than those in the array. specified_fields interprets this information and produces the array of fields to be acted upon. */ static pdf_obj *specified_fields(pdf_document *doc, pdf_obj *fields, int exclude) { fz_context *ctx = doc->ctx; pdf_obj *form = pdf_dict_getp(pdf_trailer(doc), "Root/AcroForm/Fields"); int i, n; pdf_obj *result = pdf_new_array(doc, 0); pdf_obj *nil = NULL; fz_var(nil); fz_try(ctx) { /* The 'fields' array not being present signals that all fields * should be acted upon, so handle it using the exclude case - excluding none */ if (exclude || !fields) { /* mark the fields we don't want to act upon */ nil = pdf_new_null(doc); n = pdf_array_len(fields); for (i = 0; i < n; i++) { pdf_obj *field = pdf_array_get(fields, i); if (pdf_is_string(field)) field = pdf_lookup_field(form, pdf_to_str_buf(field)); if (field) pdf_dict_puts(field, "Exclude", nil); } /* Act upon all unmarked fields */ n = pdf_array_len(form); for (i = 0; i < n; i++) add_field_hierarchy_to_array(result, pdf_array_get(form, i)); /* Unmark the marked fields */ n = pdf_array_len(fields); for (i = 0; i < n; i++) { pdf_obj *field = pdf_array_get(fields, i); if (pdf_is_string(field)) field = pdf_lookup_field(form, pdf_to_str_buf(field)); if (field) pdf_dict_dels(field, "Exclude"); } } else { n = pdf_array_len(fields); for (i = 0; i < n; i++) { pdf_obj *field = pdf_array_get(fields, i); if (pdf_is_string(field)) field = pdf_lookup_field(form, pdf_to_str_buf(field)); if (field) add_field_hierarchy_to_array(result, field); } } } fz_always(ctx) { pdf_drop_obj(nil); } fz_catch(ctx) { pdf_drop_obj(result); fz_rethrow(ctx); } return result; }
static void reset_field(pdf_document *doc, pdf_obj *field) { fz_context *ctx = doc->ctx; /* Set V to DV whereever DV is present, and delete V where DV is not. * FIXME: we assume for now that V has not been set unequal * to DV higher in the hierarchy than "field". * * At the bottom of the hierarchy we may find widget annotations * that aren't also fields, but DV and V will not be present in their * dictionaries, and attempts to remove V will be harmless. */ pdf_obj *dv = pdf_dict_gets(field, "DV"); pdf_obj *kids = pdf_dict_gets(field, "Kids"); if (dv) pdf_dict_puts(field, "V", dv); else pdf_dict_dels(field, "V"); if (kids == NULL) { /* The leaves of the tree are widget annotations * In some cases we need to update the appearance state; * in others we need to mark the field as dirty so that * the appearance stream will be regenerated. */ switch (pdf_field_type(doc, field)) { case PDF_WIDGET_TYPE_RADIOBUTTON: case PDF_WIDGET_TYPE_CHECKBOX: { pdf_obj *leafv = pdf_get_inheritable(doc, field, "V"); if (leafv) pdf_keep_obj(leafv); else leafv = pdf_new_name(doc, "Off"); fz_try(ctx) { pdf_dict_puts(field, "AS", leafv); } fz_always(ctx) { pdf_drop_obj(leafv); } fz_catch(ctx) { fz_rethrow(ctx); } } break; case PDF_WIDGET_TYPE_PUSHBUTTON: break; default: pdf_field_mark_dirty(doc, field); break; } } doc->dirty = 1; }
void pdf_update_xobject_contents(pdf_document *xref, pdf_xobject *form, fz_buffer *buffer) { pdf_dict_dels(form->contents, "Filter"); pdf_update_stream(xref, pdf_to_num(form->contents), buffer); }