diff options
author | Robin Watts <robin.watts@artifex.com> | 2014-03-19 19:04:50 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2014-03-19 19:04:50 +0000 |
commit | e4d36ce68e0467ac4702f717386934a44970f4e5 (patch) | |
tree | 758a9999434f03a4607d1f23e43d9a58828b6444 /source/pdf/pdf-write.c | |
parent | 441954b6fb378e3af72500653be5636c7ade29ee (diff) | |
download | mupdf-e4d36ce68e0467ac4702f717386934a44970f4e5.tar.xz |
Add routine to clean pdf content streams for pages.
New routine to filter the content streams for pages, xobjects,
type3 charprocs, patterns etc. The filtered streams are guaranteed
to be properly matched with q/Q's, and to not have changed the top
level ctm. Additionally we remove (some) repeated settings of
colors etc. This filtering can be extended to be smarter later.
The idea of this is to both repair after editing, and to leave the
streams in a form that can be easily appended to.
This is preparatory to work on Bates numbering and Watermarking.
Currently the streams produced are uncompressed.
Diffstat (limited to 'source/pdf/pdf-write.c')
-rw-r--r-- | source/pdf/pdf-write.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index b5894421..f218429d 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -51,6 +51,7 @@ struct pdf_write_options_s int do_expand; int do_garbage; int do_linear; + int do_clean; int *use_list; int *ofs_list; int *gen_list; @@ -2541,6 +2542,21 @@ static void complete_signatures(pdf_document *doc, pdf_write_options *opts, char } } +static void sanitise(pdf_document *doc) +{ + int n = pdf_count_pages(doc); + int i; + + for (i = 0; i < n; i++) + { + pdf_page *page = pdf_load_page(doc, i); + + pdf_clean_page_contents(doc, page, NULL); + + pdf_free_page(doc, page); + } +} + void pdf_write_document(pdf_document *doc, char *filename, fz_write_options *fz_opts) { int lastfree; @@ -2559,6 +2575,10 @@ void pdf_write_document(pdf_document *doc, char *filename, fz_write_options *fz_ doc->freeze_updates = 1; ctx = doc->ctx; + /* Sanitise the operator streams */ + if (fz_opts->do_clean) + sanitise(doc); + pdf_finish_edit(doc); presize_unsaved_signature_byteranges(doc); @@ -2585,6 +2605,7 @@ void pdf_write_document(pdf_document *doc, char *filename, fz_write_options *fz_ opts.do_garbage = fz_opts->do_garbage; opts.do_ascii = fz_opts->do_ascii; opts.do_linear = fz_opts->do_linear; + opts.do_clean = fz_opts->do_clean; opts.start = 0; opts.main_xref_offset = INT_MIN; /* We deliberately make these arrays long enough to cope with |