From 6afe83978fe1d310e8a41774c33052d880f2f524 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 30 Jan 2018 21:39:38 -0500 Subject: [PATCH] Switch from parseContentStream to parsePageContents --- ChangeLog | 5 +++++ examples/pdf-parse-content.cc | 3 +-- qpdf/qpdf.cc | 4 +--- qpdf/qtest/qpdf/content-stream-errors.out | 6 +++--- qpdf/qtest/qpdf/eof-in-inline-image.out | 2 +- qpdf/qtest/qpdf/split-content-stream-errors.out | 2 +- qpdf/test_driver.cc | 3 +-- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index b29e6548..fd323e44 100644 --- a/ChangeLog +++ b/ChangeLog @@ -57,6 +57,11 @@ problems are encountered as the error messages can include information about which page the streams come from. + * Update content stream parsing example + (examples/pdf-parse-content.cc) to use new + QPDFObjectHandle::parsePageContents() method in favor of the older + QPDFObjectHandle::parseContentStream() method. + 2018-02-04 Jay Berkenbilt * Add QPDFWriter::setLinearizationPass1Filename method and diff --git a/examples/pdf-parse-content.cc b/examples/pdf-parse-content.cc index a16b0bd3..620c1bb6 100644 --- a/examples/pdf-parse-content.cc +++ b/examples/pdf-parse-content.cc @@ -75,9 +75,8 @@ int main(int argc, char* argv[]) } QPDFObjectHandle page = pages.at(pageno-1); - QPDFObjectHandle contents = page.getKey("/Contents"); ParserCallbacks cb; - QPDFObjectHandle::parseContentStream(contents, &cb); + page.parsePageContents(&cb); } catch (std::exception& e) { diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc index 1c56a345..bf5d7078 100644 --- a/qpdf/qpdf.cc +++ b/qpdf/qpdf.cc @@ -1769,9 +1769,7 @@ static void do_check(QPDF& pdf, Options& o, int& exit_code) ++pageno; try { - QPDFObjectHandle::parseContentStream( - (*iter).getKey("/Contents"), - &discard_contents); + (*iter).parsePageContents(&discard_contents); } catch (QPDFExc& e) { diff --git a/qpdf/qtest/qpdf/content-stream-errors.out b/qpdf/qtest/qpdf/content-stream-errors.out index d36d61b3..7a4dc944 100644 --- a/qpdf/qtest/qpdf/content-stream-errors.out +++ b/qpdf/qtest/qpdf/content-stream-errors.out @@ -2,6 +2,6 @@ checking content-stream-errors.pdf PDF Version: 1.3 File is not encrypted File is not linearized -page 1: content stream objects 7 0 (content, file position 52): parse error while reading object -page 3: content stream objects 15 0 (stream data, file position 117): EOF found while reading inline image -page 4: content stream objects 19 0 (content, file position 53): parse error while reading object +page 1: page object 3 0 stream 7 0 (content, file position 52): parse error while reading object +page 3: page object 5 0 stream 15 0 (stream data, file position 117): EOF found while reading inline image +page 4: page object 6 0 stream 19 0 (content, file position 53): parse error while reading object diff --git a/qpdf/qtest/qpdf/eof-in-inline-image.out b/qpdf/qtest/qpdf/eof-in-inline-image.out index cb2acf97..a79406fc 100644 --- a/qpdf/qtest/qpdf/eof-in-inline-image.out +++ b/qpdf/qtest/qpdf/eof-in-inline-image.out @@ -22,4 +22,4 @@ name: /Fl name: /DP dictionary: << /Columns 1 /Predictor 15 >> operator: ID -content stream objects 4 0 (stream data, file position 139): EOF found while reading inline image +page object 3 0 stream 4 0 (stream data, file position 139): EOF found while reading inline image diff --git a/qpdf/qtest/qpdf/split-content-stream-errors.out b/qpdf/qtest/qpdf/split-content-stream-errors.out index fbfe020d..ec4e5dea 100644 --- a/qpdf/qtest/qpdf/split-content-stream-errors.out +++ b/qpdf/qtest/qpdf/split-content-stream-errors.out @@ -4,6 +4,6 @@ File is not encrypted File is not linearized WARNING: split-content-stream-errors.pdf (file position 557): error decoding stream data for object 6 0: LZWDecoder: bad code received WARNING: split-content-stream-errors.pdf (file position 557): stream will be re-processed without filtering to avoid data loss -WARNING: content stream objects (item index 0 (from 0)): ignoring non-stream in an array of streams +WARNING: page object 3 0 (item index 0 (from 0)): ignoring non-stream in an array of streams WARNING: split-content-stream-errors.pdf (file position 557): error decoding stream data for object 6 0: LZWDecoder: bad code received WARNING: content stream (content stream object 6 0): errors while decoding content stream diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index 2f99c3f5..001e6dfb 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -1296,9 +1296,8 @@ void runtest(int n, char const* filename1, char const* arg2) iter != pages.end(); ++iter) { QPDFObjectHandle page = *iter; - QPDFObjectHandle contents = page.getKey("/Contents"); ParserCallbacks cb; - QPDFObjectHandle::parseContentStream(contents, &cb); + page.parsePageContents(&cb); } } else if (n == 38)