diff options
Diffstat (limited to 'examples/pdf-parse-content.cc')
-rw-r--r-- | examples/pdf-parse-content.cc | 36 |
1 files changed, 15 insertions, 21 deletions
diff --git a/examples/pdf-parse-content.cc b/examples/pdf-parse-content.cc index dbe3a451..f1f7ab55 100644 --- a/examples/pdf-parse-content.cc +++ b/examples/pdf-parse-content.cc @@ -1,16 +1,17 @@ #include <iostream> -#include <string.h> #include <stdlib.h> +#include <string.h> +#include <qpdf/QIntC.hh> #include <qpdf/QPDF.hh> #include <qpdf/QPDFPageDocumentHelper.hh> #include <qpdf/QPDFPageObjectHelper.hh> #include <qpdf/QUtil.hh> -#include <qpdf/QIntC.hh> static char const* whoami = 0; -void usage() +void +usage() { std::cerr << "Usage: " << whoami << " filename page-number" << std::endl << "Prints a dump of the objects in the content streams" @@ -38,17 +39,14 @@ ParserCallbacks::contentSize(size_t size) } void -ParserCallbacks::handleObject(QPDFObjectHandle obj, - size_t offset, size_t length) +ParserCallbacks::handleObject( + QPDFObjectHandle obj, size_t offset, size_t length) { std::cout << obj.getTypeName() << ", offset=" << offset << ", length=" << length << ": "; - if (obj.isInlineImage()) - { + if (obj.isInlineImage()) { std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl; - } - else - { + } else { std::cout << obj.unparse() << std::endl; } } @@ -59,34 +57,30 @@ ParserCallbacks::handleEOF() std::cout << "-EOF-" << std::endl; } -int main(int argc, char* argv[]) +int +main(int argc, char* argv[]) { whoami = QUtil::getWhoami(argv[0]); - if (argc != 3) - { + if (argc != 3) { usage(); } char const* filename = argv[1]; int pageno = QUtil::string_to_int(argv[2]); - try - { + try { QPDF pdf; pdf.processFile(filename); std::vector<QPDFPageObjectHelper> pages = QPDFPageDocumentHelper(pdf).getAllPages(); - if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) - { + if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) { usage(); } - QPDFPageObjectHelper& page = pages.at(QIntC::to_size(pageno-1)); + QPDFPageObjectHelper& page = pages.at(QIntC::to_size(pageno - 1)); ParserCallbacks cb; page.parseContents(&cb); - } - catch (std::exception& e) - { + } catch (std::exception& e) { std::cerr << whoami << ": " << e.what() << std::endl; exit(2); } |