@@ -3150,7 +3150,28 @@ void refresh_link_table(fz_context *ctx, pdf_page *page)
31503150#define ANNOT_LE_Slash 9
31513151
31523152//----------------------------------------------------------------------------
3153- // return character string for line end style
3153+ // annotation field (widget) types
3154+ //----------------------------------------------------------------------------
3155+ #define ANNOT_WG_NOT_WIDGET -1
3156+ #define ANNOT_WG_PUSHBUTTON 0
3157+ #define ANNOT_WG_CHECKBOX 1
3158+ #define ANNOT_WG_RADIOBUTTON 2
3159+ #define ANNOT_WG_TEXT 3
3160+ #define ANNOT_WG_LISTBOX 4
3161+ #define ANNOT_WG_COMBOBOX 5
3162+ #define ANNOT_WG_SIGNATURE 6
3163+ 
3164+ //----------------------------------------------------------------------------
3165+ // annotation text widget subtypes
3166+ //----------------------------------------------------------------------------
3167+ #define ANNOT_WG_TEXT_UNRESTRAINED 0
3168+ #define ANNOT_WG_TEXT_NUMBER 1
3169+ #define ANNOT_WG_TEXT_SPECIAL 2
3170+ #define ANNOT_WG_TEXT_DATE 3
3171+ #define ANNOT_WG_TEXT_TIME 4
3172+ 
3173+ //----------------------------------------------------------------------------
3174+ // return string for line end style
31543175//----------------------------------------------------------------------------
31553176char *annot_le_style_str(int type)
31563177{
@@ -3171,7 +3192,7 @@ char *annot_le_style_str(int type)
31713192}
31723193
31733194//----------------------------------------------------------------------------
3174- // return character  name of annotation type
3195+ // return string  name of annotation type
31753196//----------------------------------------------------------------------------
31763197char *annot_type_str(int type)
31773198{
@@ -4265,6 +4286,29 @@ int JM_FindEmbedded(fz_context *ctx, PyObject *id, pdf_document *pdf)
42654286    return i;
42664287}
42674288
4289+ //-----------------------------------------------------------------------------
4290+ // perform some cleaning if we have embeddedfiles
4291+ //-----------------------------------------------------------------------------
4292+ void JM_embedded_clean(fz_context *ctx, pdf_document *pdf)
4293+ {
4294+     pdf_obj *root = pdf_dict_get(ctx, pdf_trailer(ctx, pdf), PDF_NAME_Root);
4295+     pdf_obj *efiles = pdf_dict_getl(ctx, root, PDF_NAME_Names,
4296+                                     PDF_NAME_EmbeddedFiles, NULL);
4297+     if (efiles)         // we have embedded files
4298+     {   // make sure they are displayed
4299+         pdf_dict_put_name(ctx, root, PDF_NAME_PageMode, "UseAttachments");
4300+         // remove the limits entry: seems to be a MuPDF bug
4301+         pdf_dict_del(ctx, efiles, PDF_NAME_Limits);
4302+     }
4303+ 
4304+     // also remove an empty /Collection entry
4305+     pdf_obj *coll = pdf_dict_get(ctx, root, PDF_NAME_Collection);
4306+     if (coll && pdf_dict_len(ctx, coll) == 0)
4307+         pdf_dict_del(ctx, root, PDF_NAME_Collection);
4308+     return;
4309+ 
4310+ }
4311+ 
42684312
42694313//----------------------------------------------------------------------------
42704314// Helpers for document page selection - main logic was imported
@@ -5795,6 +5839,7 @@ SWIGINTERN PyObject *fz_document_s_save(struct fz_document_s *self,char *filenam
57955839                if ((incremental) && (fz_needs_password(gctx, self)))
57965840                    THROWMSG("decrypted file - save to new");
57975841                pdf_finish_edit(gctx, pdf);
5842+                 JM_embedded_clean(gctx, pdf);
57985843                pdf_save_document(gctx, pdf, filename, &opts);
57995844                pdf->dirty = 0;
58005845                }
@@ -5829,6 +5874,7 @@ SWIGINTERN PyObject *fz_document_s_write(struct fz_document_s *self,int garbage,
58295874                if (fz_count_pages(gctx, self) < 1)
58305875                    THROWMSG("document has zero pages");
58315876                pdf_finish_edit(gctx, pdf);
5877+                 JM_embedded_clean(gctx, pdf);
58325878                res = fz_new_buffer(gctx, 1024);
58335879                out = fz_new_output_with_buffer(gctx, res);
58345880                pdf_write_document(gctx, pdf, out, &opts);
0 commit comments