| Index: samples/pdfium_test.cc
|
| diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
|
| index ac6073aa2e8a6a51a54c340c30056b310a256eef..bb8d2a10e45a6efe9d88fc5fc10500931561ae5e 100644
|
| --- a/samples/pdfium_test.cc
|
| +++ b/samples/pdfium_test.cc
|
| @@ -77,6 +77,7 @@ struct Options {
|
| std::string exe_path;
|
| std::string bin_directory;
|
| std::string font_directory;
|
| + std::string password;
|
| // 0-based page numbers to be rendered.
|
| int first_page;
|
| int last_page;
|
| @@ -473,6 +474,13 @@ bool ParseCommandLine(const std::vector<std::string>& args,
|
| return false;
|
| }
|
| options->scale_factor_as_string = cur_arg.substr(8);
|
| + } else if (cur_arg.size() > 27 &&
|
| + cur_arg.compare(0, 27, "--compromise-this-password=") == 0) {
|
| + if (!options->password.empty()) {
|
| + fprintf(stderr, "Duplicate --compromise-this-password argument\n");
|
| + return false;
|
| + }
|
| + options->password = cur_arg.substr(27);
|
| } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--pages=") == 0) {
|
| if (options->pages) {
|
| fprintf(stderr, "Duplicate --pages argument\n");
|
| @@ -722,8 +730,12 @@ void RenderPdf(const std::string& name,
|
| FPDF_AVAIL pdf_avail = FPDFAvail_Create(&file_avail, &file_access);
|
| std::unique_ptr<void, AvailDeleter> scoped_pdf_avail_deleter(pdf_avail);
|
|
|
| + const char* password = nullptr;
|
| + if (!options.password.empty())
|
| + password = options.password.c_str();
|
| +
|
| if (FPDFAvail_IsLinearized(pdf_avail) == PDF_LINEARIZED) {
|
| - doc = FPDFAvail_GetDocument(pdf_avail, nullptr);
|
| + doc = FPDFAvail_GetDocument(pdf_avail, password);
|
| if (doc) {
|
| while (nRet == PDF_DATA_NOTAVAIL)
|
| nRet = FPDFAvail_IsDocAvail(pdf_avail, &hints);
|
| @@ -744,7 +756,7 @@ void RenderPdf(const std::string& name,
|
| bIsLinearized = true;
|
| }
|
| } else {
|
| - doc = FPDF_LoadCustomDocument(&file_access, nullptr);
|
| + doc = FPDF_LoadCustomDocument(&file_access, password);
|
| }
|
|
|
| if (!doc) {
|
| @@ -862,6 +874,8 @@ static const char kUsageString[] =
|
| " --font-dir=<path> - override path to external fonts\n"
|
| " --scale=<number> - scale output size by number (e.g. 0.5)\n"
|
| " --pages=<number>(-<number>) - only render the given 0-based page(s)\n"
|
| + " --compromise-this-password=<string> - password protected document.\n"
|
| + " (unsafe since cmd line usage compromises password, testing only)\n"
|
| #ifdef _WIN32
|
| " --bmp - write page images <pdf-name>.<page-number>.bmp\n"
|
| " --emf - write page meta files <pdf-name>.<page-number>.emf\n"
|
|
|