diff options
-rw-r--r-- | include/mupdf/pdf/document.h | 6 | ||||
-rw-r--r-- | platform/android/viewer/jni/mupdf.c | 2 | ||||
-rw-r--r-- | platform/x11/pdfapp.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-write.c | 11 |
4 files changed, 19 insertions, 2 deletions
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h index f8ef6bfb..857f2d58 100644 --- a/include/mupdf/pdf/document.h +++ b/include/mupdf/pdf/document.h @@ -413,4 +413,10 @@ void pdf_parse_write_options(fz_context *ctx, pdf_write_options *opts, const cha */ void pdf_save_document(fz_context *ctx, pdf_document *doc, const char *filename, pdf_write_options *opts); +/* + pdf_can_be_saved_incrementally: Return true if the document can be saved + incrementally. (e.g. it has not been repaired, and it is not encrypted) +*/ +int pdf_can_be_saved_incrementally(fz_context *ctx, pdf_document *doc); + #endif diff --git a/platform/android/viewer/jni/mupdf.c b/platform/android/viewer/jni/mupdf.c index f9d6042b..451671c7 100644 --- a/platform/android/viewer/jni/mupdf.c +++ b/platform/android/viewer/jni/mupdf.c @@ -2600,7 +2600,7 @@ JNI_FN(MuPDFCore_saveInternal)(JNIEnv * env, jobject thiz) char *tmp; pdf_write_options opts = { 0 }; - opts.do_incremental = 1; + opts.do_incremental = pdf_can_be_saved_incrementally(ctx, idoc); tmp = tmp_path(glo->current_path); if (tmp) diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index fd1f6a1a..9d1debbb 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -529,7 +529,7 @@ static int pdfapp_save(pdfapp_t *app) { pdf_write_options opts = { 0 }; - opts.do_incremental = 1; + opts.do_incremental = pdf_can_be_saved_incrementally(app->ctx, idoc); if (strcmp(buf, app->docpath) != 0) { diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index ade277ce..87c31926 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -2804,6 +2804,15 @@ void pdf_parse_write_options(fz_context *ctx, pdf_write_options *opts, const cha } } +int pdf_can_be_saved_incrementally(fz_context *ctx, pdf_document *doc) +{ + if (doc->repair_attempted) + return 0; + if (doc->crypt != NULL) + return 0; + return 1; +} + void pdf_save_document(fz_context *ctx, pdf_document *doc, const char *filename, pdf_write_options *in_opts) { pdf_write_options opts_defaults = { 0 }; @@ -2819,6 +2828,8 @@ void pdf_save_document(fz_context *ctx, pdf_document *doc, const char *filename, if (!in_opts) in_opts = &opts_defaults; + if (in_opts->do_incremental && doc->repair_attempted) + fz_throw(ctx, FZ_ERROR_GENERIC, "Can't do incremental writes on a repaired file"); if (in_opts->do_incremental && in_opts->do_garbage) fz_throw(ctx, FZ_ERROR_GENERIC, "Can't do incremental writes with garbage collection"); if (in_opts->do_incremental && in_opts->do_linear) |