Add the ability for pdfium_test to use FPDF_LoadMemDocument().
Add a --mem-document switch that forces pdfium_test to load
FPDF_DOCUMENTs with FPDF_LoadMemDocument() instead of
FPDFAvail_GetDocument() and FPDF_LoadCustomDocument().
Change-Id: I9faed21c0b74d8377b840fdbcc794b0a7b1abfaf
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/57692
Commit-Queue: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 442ad34..e4ba85f 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -99,6 +99,7 @@
bool show_config = false;
bool show_metadata = false;
bool send_events = false;
+ bool use_load_mem_document = false;
bool render_oneshot = false;
bool save_attachments = false;
bool save_images = false;
@@ -343,6 +344,8 @@
options->show_metadata = true;
} else if (cur_arg == "--send-events") {
options->send_events = true;
+ } else if (cur_arg == "--mem-document") {
+ options->use_load_mem_document = true;
} else if (cur_arg == "--render-oneshot") {
options->render_oneshot = true;
} else if (cur_arg == "--save-attachments") {
@@ -755,28 +758,33 @@
ScopedFPDFDocument doc;
bool is_linearized = false;
- if (FPDFAvail_IsLinearized(pdf_avail.get()) == PDF_LINEARIZED) {
- int avail_status = PDF_DATA_NOTAVAIL;
- doc.reset(FPDFAvail_GetDocument(pdf_avail.get(), nullptr));
- if (doc) {
- while (avail_status == PDF_DATA_NOTAVAIL)
- avail_status = FPDFAvail_IsDocAvail(pdf_avail.get(), &hints);
-
- if (avail_status == PDF_DATA_ERROR) {
- fprintf(stderr, "Unknown error in checking if doc was available.\n");
- return;
- }
- avail_status = FPDFAvail_IsFormAvail(pdf_avail.get(), &hints);
- if (avail_status == PDF_FORM_ERROR || avail_status == PDF_FORM_NOTAVAIL) {
- fprintf(stderr,
- "Error %d was returned in checking if form was available.\n",
- avail_status);
- return;
- }
- is_linearized = true;
- }
+ if (options.use_load_mem_document) {
+ doc.reset(FPDF_LoadMemDocument(buf, len, nullptr));
} else {
- doc.reset(FPDF_LoadCustomDocument(&file_access, nullptr));
+ if (FPDFAvail_IsLinearized(pdf_avail.get()) == PDF_LINEARIZED) {
+ int avail_status = PDF_DATA_NOTAVAIL;
+ doc.reset(FPDFAvail_GetDocument(pdf_avail.get(), nullptr));
+ if (doc) {
+ while (avail_status == PDF_DATA_NOTAVAIL)
+ avail_status = FPDFAvail_IsDocAvail(pdf_avail.get(), &hints);
+
+ if (avail_status == PDF_DATA_ERROR) {
+ fprintf(stderr, "Unknown error in checking if doc was available.\n");
+ return;
+ }
+ avail_status = FPDFAvail_IsFormAvail(pdf_avail.get(), &hints);
+ if (avail_status == PDF_FORM_ERROR ||
+ avail_status == PDF_FORM_NOTAVAIL) {
+ fprintf(stderr,
+ "Error %d was returned in checking if form was available.\n",
+ avail_status);
+ return;
+ }
+ is_linearized = true;
+ }
+ } else {
+ doc.reset(FPDF_LoadCustomDocument(&file_access, nullptr));
+ }
}
if (!doc) {
@@ -912,6 +920,7 @@
" --show-pageinfo - print information about pages\n"
" --show-structure - print the structure elements from the document\n"
" --send-events - send input described by .evt file\n"
+ " --mem-document - load document with FPDF_LoadMemDocument()\n"
" --render-oneshot - render image without using progressive renderer\n"
" --save-attachments - write embedded attachments "
"<pdf-name>.attachment.<attachment-name>\n"