From f4a365df3f7709192ec6052832e857d2832ae47f Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 12 Apr 2016 19:42:19 +0100 Subject: Update mutool clean sanitize to clean annotations too. --- source/pdf/pdf-clean.c | 21 +++++++++++++++++++++ source/pdf/pdf-interpret.c | 2 +- source/pdf/pdf-write.c | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'source/pdf') diff --git a/source/pdf/pdf-clean.c b/source/pdf/pdf-clean.c index 2c8ade73..ecadc7f2 100644 --- a/source/pdf/pdf-clean.c +++ b/source/pdf/pdf-clean.c @@ -287,3 +287,24 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, fz_rethrow_message(ctx, "Failed while cleaning page"); } } + +void pdf_clean_annot_contents(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_cookie *cookie, pdf_page_contents_process_fn *proc_fn, void *proc_arg, int ascii) +{ + pdf_obj *ap; + int i, n; + + ap = pdf_dict_get(ctx, annot->obj, PDF_NAME_AP); + if (ap == NULL) + return; + + n = pdf_dict_len(ctx, ap); + for (i = 0; i < n; i++) + { + pdf_obj *v = pdf_dict_get_val(ctx, ap, i); + + if (v == NULL) + continue; + + pdf_clean_stream_object(ctx, doc, v, NULL, cookie, 1, 1); + } +} diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index 3a386614..cff3f197 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -1258,7 +1258,7 @@ pdf_process_annot(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_p proc->op_cm(ctx, proc, annot->matrix.a, annot->matrix.b, annot->matrix.c, annot->matrix.d, annot->matrix.e, annot->matrix.f); - proc->op_Do_form(ctx, proc, "Annot", annot->ap, page->resources); + proc->op_Do_form(ctx, proc, NULL, annot->ap, page->resources); proc->op_Q(ctx, proc); } } diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index 388a5820..8e686218 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -2656,8 +2656,15 @@ static void sanitize(fz_context *ctx, pdf_document *doc, int ascii) for (i = 0; i < n; i++) { + pdf_annot *annot; pdf_page *page = pdf_load_page(ctx, doc, i); pdf_clean_page_contents(ctx, doc, page, NULL, NULL, NULL, ascii); + + for (annot = pdf_first_annot(ctx, page); annot != NULL; annot = pdf_next_annot(ctx, annot)) + { + pdf_clean_annot_contents(ctx, doc, annot, NULL, NULL, NULL, ascii); + } + fz_drop_page(ctx, &page->super); } } -- cgit v1.2.3