diff --git a/ChangeLog b/ChangeLog index 7b1f63c0..5570e04c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2018-08-12 Jay Berkenbilt + * qpdf command line: add --no-warn option to suppress issuing + warning messages. If there are any conditions that would have + caused warnings to be issued, the exit status is still 3. + * Rewrite the internals of Pl_Buffer to be much more efficient in use of memory at a very slight performance cost. The old implementation could cause memory usage to go out of control for diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 158bb993..f5365d19 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -61,6 +61,7 @@ struct Options split_pages(0), verbose(false), progress(false), + suppress_warnings(false), copy_encryption(false), encryption_file(0), encryption_file_password(0), @@ -125,6 +126,7 @@ struct Options int split_pages; bool verbose; bool progress; + bool suppress_warnings; bool copy_encryption; char const* encryption_file; char const* encryption_file_password; @@ -262,6 +264,7 @@ Basic Options\n\ --password=password specify a password for accessing encrypted files\n\ --verbose provide additional informational output\n\ --progress give progress indicators while writing output\n\ +--no-warn suppress warnings\n\ --linearize generated a linearized (web optimized) file\n\ --copy-encryption=file copy encryption parameters from specified file\n\ --encryption-file-password=password\n\ @@ -515,8 +518,9 @@ page content stream. This attempt will be made even if it is not a\n\ page content stream, in which case it will produce unusable results.\n\ \n\ Ordinarily, qpdf exits with a status of 0 on success or a status of 2\n\ -if any errors occurred. In --check mode, if there were warnings but not\n\ -errors, qpdf exits with a status of 3.\n\ +if any errors occurred. If there were warnings but not errors, qpdf\n\ +exits with a status of 3. If warnings would have been issued but --no-warn\n\ +was given, an exit status of 3 is still used.\n\ \n"; void usage(std::string const& msg) @@ -1676,6 +1680,10 @@ static void parse_options(int argc, char* argv[], Options& o) { o.progress = true; } + else if (strcmp(arg, "no-warn") == 0) + { + o.suppress_warnings = true; + } else if (strcmp(arg, "deterministic-id") == 0) { o.deterministic_id = true; @@ -1832,6 +1840,10 @@ static void set_qpdf_options(QPDF& pdf, Options& o) { pdf.setPasswordIsHexKey(true); } + if (o.suppress_warnings) + { + pdf.setSuppressWarnings(true); + } } static void do_check(QPDF& pdf, Options& o, int& exit_code) @@ -2607,9 +2619,14 @@ int main(int argc, char* argv[]) } if (! pdf.getWarnings().empty()) { - std::cerr << whoami << ": operation succeeded with warnings;" - << " resulting file may have some problems" << std::endl; - exit(EXIT_WARNING); + if (! o.suppress_warnings) + { + std::cerr << whoami << ": operation succeeded with warnings;" + << " resulting file may have some problems" + << std::endl; + } + // Still exit with warning code even if warnings were suppressed. + exit(EXIT_WARNING); } } catch (std::exception& e) diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index bab7ec1c..a091456c 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -1528,7 +1528,7 @@ my @badfiles = ("not a PDF file", # 1 "bad dictionary key", # 36 ); -$n_tests += @badfiles + 3; +$n_tests += @badfiles + 5; # Test 6 contains errors in the free table consistency, but we no # longer have any consistency check for this since it is not important @@ -1552,6 +1552,14 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i) $td->NORMALIZE_NEWLINES); } +$td->runtest("Suppress warnings", + {$td->COMMAND => "qpdf --no-warn bad14.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 3}); +$td->runtest("Suppress warnings with --check", + {$td->COMMAND => "qpdf --check --no-warn bad14.pdf"}, + {$td->FILE => "bad14-check-no-warn.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); $td->runtest("C API: errors", {$td->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"}, {$td->FILE => "c-read-errors.out", diff --git a/qpdf/qtest/qpdf/bad14-check-no-warn.out b/qpdf/qtest/qpdf/bad14-check-no-warn.out new file mode 100644 index 00000000..becfaedd --- /dev/null +++ b/qpdf/qtest/qpdf/bad14-check-no-warn.out @@ -0,0 +1,4 @@ +checking bad14.pdf +PDF Version: 1.3 +File is not encrypted +File is not linearized