summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornpm <npm@chromium.org>2016-11-14 09:14:52 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-14 09:14:52 -0800
commite3c731526c0464822758a2a8b3a9ca9527ce9272 (patch)
treed3b8a96924e99b810e1931be176e02095d9db37d
parentc64b76c97c7f469ebd4126f314badceeb8a78b8b (diff)
downloadpdfium-chromium/2920.tar.xz
Add --pages option in pdfium_test so it renders only some of the pages.chromium/2920
The --pages option is set up to be 0-indexed. --pages=<number> will render the specific page. --pages=<number>-<number> will render the range of pages given. Review-Url: https://codereview.chromium.org/2495333002
-rw-r--r--samples/pdfium_test.cc30
1 files changed, 28 insertions, 2 deletions
diff --git a/samples/pdfium_test.cc b/samples/pdfium_test.cc
index 9bbd771780..f291c558a8 100644
--- a/samples/pdfium_test.cc
+++ b/samples/pdfium_test.cc
@@ -64,15 +64,21 @@ enum OutputFormat {
struct Options {
Options()
- : show_config(false), send_events(false), output_format(OUTPUT_NONE) {}
+ : show_config(false),
+ send_events(false),
+ pages(false),
+ output_format(OUTPUT_NONE) {}
bool show_config;
bool send_events;
+ bool pages;
OutputFormat output_format;
std::string scale_factor_as_string;
std::string exe_path;
std::string bin_directory;
std::string font_directory;
+ int firstPage;
+ int lastPage;
};
struct FPDF_FORMFILLINFO_PDFiumTest : public FPDF_FORMFILLINFO {
@@ -466,6 +472,23 @@ bool ParseCommandLine(const std::vector<std::string>& args,
return false;
}
options->scale_factor_as_string = cur_arg.substr(8);
+ } else if (cur_arg.size() > 8 && cur_arg.compare(0, 8, "--pages=") == 0) {
+ if (options->pages) {
+ fprintf(stderr, "Duplicate --pages argument\n");
+ return false;
+ }
+ options->pages = true;
+ const std::string pagesstring = cur_arg.substr(8);
+ size_t firstdash = pagesstring.find("-");
+ if (firstdash == std::string::npos) {
+ std::stringstream(pagesstring) >> options->firstPage;
+ options->lastPage = options->firstPage;
+ } else {
+ std::stringstream(pagesstring.substr(0, firstdash)) >>
+ options->firstPage;
+ std::stringstream(pagesstring.substr(firstdash + 1)) >>
+ options->lastPage;
+ }
} else if (cur_arg.size() >= 2 && cur_arg[0] == '-' && cur_arg[1] == '-') {
fprintf(stderr, "Unrecognized argument %s\n", cur_arg.c_str());
return false;
@@ -777,7 +800,9 @@ void RenderPdf(const std::string& name,
int page_count = FPDF_GetPageCount(doc);
int rendered_pages = 0;
int bad_pages = 0;
- for (int i = 0; i < page_count; ++i) {
+ int firstPage = options.pages ? options.firstPage : 0;
+ int lastPage = options.pages ? options.lastPage + 1 : page_count;
+ for (int i = firstPage; i < lastPage; ++i) {
if (bIsLinearized) {
nRet = PDF_DATA_NOTAVAIL;
while (nRet == PDF_DATA_NOTAVAIL)
@@ -835,6 +860,7 @@ static const char kUsageString[] =
" --bin-dir=<path> - override path to v8 external data\n"
" --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 page(s)\n"
#ifdef _WIN32
" --bmp - write page images <pdf-name>.<page-number>.bmp\n"
" --emf - write page meta files <pdf-name>.<page-number>.emf\n"