diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/pdfapp.c | 4 | ||||
-rw-r--r-- | apps/pdfclean.c | 5 | ||||
-rw-r--r-- | apps/pdfdraw.c | 6 | ||||
-rw-r--r-- | apps/pdfextract.c | 5 | ||||
-rw-r--r-- | apps/pdfinfo.c | 5 | ||||
-rw-r--r-- | apps/pdfshow.c | 35 |
6 files changed, 41 insertions, 19 deletions
diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 5b839eb1..3ad71c9a 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -113,7 +113,7 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd) fz_try(ctx) { file = fz_open_fd(ctx, fd); - app->xref = pdf_open_xref_with_stream(file, NULL); + app->xref = pdf_open_xref_with_stream(file); fz_close(file); } fz_catch(ctx) @@ -132,7 +132,7 @@ static void pdfapp_open_pdf(pdfapp_t *app, char *filename, int fd) { password = winpassword(app, filename); if (!password) - exit(1); + pdfapp_error(app, "Needs a password."); okay = pdf_authenticate_password(app->xref, password); if (!okay) pdfapp_warn(app, "Invalid password."); diff --git a/apps/pdfclean.c b/apps/pdfclean.c index 0f3474ce..82eb7c03 100644 --- a/apps/pdfclean.c +++ b/apps/pdfclean.c @@ -775,7 +775,10 @@ int main(int argc, char **argv) exit(1); } - xref = pdf_open_xref(ctx, infile, password); + xref = pdf_open_xref(ctx, infile); + if (pdf_needs_password(xref)) + if (!pdf_authenticate_password(xref, password)) + fz_throw(ctx, "cannot authenticate password: %s\n", infile); out = fopen(outfile, "wb"); if (!out) diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index d811df07..893b5b2b 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -445,13 +445,17 @@ int main(int argc, char **argv) fz_try(ctx) { - xref = pdf_open_xref(ctx, filename, password); + xref = pdf_open_xref(ctx, filename); } fz_catch(ctx) { fz_throw(ctx, "cannot open document: %s", filename); } + if (pdf_needs_password(xref)) + if (!pdf_authenticate_password(xref, password)) + fz_throw(ctx, "cannot authenticate password: %s", filename); + if (showxml) printf("<document name=\"%s\">\n", filename); diff --git a/apps/pdfextract.c b/apps/pdfextract.c index 0e87cf9f..f69fd751 100644 --- a/apps/pdfextract.c +++ b/apps/pdfextract.c @@ -189,7 +189,10 @@ int main(int argc, char **argv) exit(1); } - xref = pdf_open_xref(ctx, infile, password); + xref = pdf_open_xref(ctx, infile); + if (pdf_needs_password(xref)) + if (!pdf_authenticate_password(xref, password)) + fz_throw(ctx, "cannot authenticate password: %s\n", infile); if (fz_optind == argc) { diff --git a/apps/pdfinfo.c b/apps/pdfinfo.c index a38e4f09..47f26c18 100644 --- a/apps/pdfinfo.c +++ b/apps/pdfinfo.c @@ -993,7 +993,10 @@ int main(int argc, char **argv) filename = argv[fz_optind]; printf("%s:\n", filename); - xref = pdf_open_xref(ctx, filename, password); + xref = pdf_open_xref(ctx, filename); + if (pdf_needs_password(xref)) + if (!pdf_authenticate_password(xref, password)) + fz_throw(ctx, "cannot authenticate password: %s\n", filename); pagecount = pdf_count_pages(xref); showglobalinfo(); diff --git a/apps/pdfshow.c b/apps/pdfshow.c index a84e962b..2fbfdc2f 100644 --- a/apps/pdfshow.c +++ b/apps/pdfshow.c @@ -205,26 +205,35 @@ int main(int argc, char **argv) exit(1); } - xref = pdf_open_xref(ctx, filename, password); + fz_var(xref); + fz_try(ctx) + { + xref = pdf_open_xref(ctx, filename); + if (pdf_needs_password(xref)) + if (!pdf_authenticate_password(xref, password)) + fz_throw(ctx, "cannot authenticate password: %s", filename); - if (fz_optind == argc) - showtrailer(); + if (fz_optind == argc) + showtrailer(); - while (fz_optind < argc) - { - switch (argv[fz_optind][0]) + while (fz_optind < argc) { - case 't': showtrailer(); break; - case 'x': showxref(); break; - case 'p': showpagetree(); break; - case 'g': showgrep(filename); break; - default: showobject(atoi(argv[fz_optind]), 0); break; + switch (argv[fz_optind][0]) + { + case 't': showtrailer(); break; + case 'x': showxref(); break; + case 'p': showpagetree(); break; + case 'g': showgrep(filename); break; + default: showobject(atoi(argv[fz_optind]), 0); break; + } + fz_optind++; } - fz_optind++; + } + fz_catch(ctx) + { } pdf_free_xref(xref); - fz_flush_warnings(ctx); fz_free_context(ctx); return 0; } |