2013-01-20 20:26:45 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <stdlib.h>
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <string.h>
|
2013-01-20 20:26:45 +00:00
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <qpdf/QIntC.hh>
|
2013-01-20 20:26:45 +00:00
|
|
|
#include <qpdf/QPDF.hh>
|
2018-06-18 19:06:51 +00:00
|
|
|
#include <qpdf/QPDFPageDocumentHelper.hh>
|
|
|
|
#include <qpdf/QPDFPageObjectHelper.hh>
|
2013-01-20 20:26:45 +00:00
|
|
|
#include <qpdf/QUtil.hh>
|
|
|
|
|
|
|
|
static char const* whoami = 0;
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
void
|
|
|
|
usage()
|
2013-01-20 20:26:45 +00:00
|
|
|
{
|
|
|
|
std::cerr << "Usage: " << whoami << " filename page-number" << std::endl
|
2022-02-08 14:18:08 +00:00
|
|
|
<< "Prints a dump of the objects in the content streams"
|
2013-01-20 20:26:45 +00:00
|
|
|
<< " of the given page." << std::endl
|
|
|
|
<< "Pages are numbered from 1." << std::endl;
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ParserCallbacks()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-22 23:16:25 +00:00
|
|
|
virtual void contentSize(size_t);
|
|
|
|
virtual void handleObject(QPDFObjectHandle, size_t offset, size_t length);
|
2013-01-20 20:26:45 +00:00
|
|
|
virtual void handleEOF();
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2019-08-22 23:16:25 +00:00
|
|
|
ParserCallbacks::contentSize(size_t size)
|
2013-01-20 20:26:45 +00:00
|
|
|
{
|
2019-08-22 23:16:25 +00:00
|
|
|
std::cout << "content size: " << size << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-04-02 21:14:10 +00:00
|
|
|
ParserCallbacks::handleObject(
|
|
|
|
QPDFObjectHandle obj, size_t offset, size_t length)
|
2019-08-22 23:16:25 +00:00
|
|
|
{
|
|
|
|
std::cout << obj.getTypeName() << ", offset=" << offset
|
|
|
|
<< ", length=" << length << ": ";
|
2022-04-02 21:14:10 +00:00
|
|
|
if (obj.isInlineImage()) {
|
2013-01-25 13:59:55 +00:00
|
|
|
std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl;
|
2022-04-02 21:14:10 +00:00
|
|
|
} else {
|
2013-01-20 20:26:45 +00:00
|
|
|
std::cout << obj.unparse() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ParserCallbacks::handleEOF()
|
|
|
|
{
|
|
|
|
std::cout << "-EOF-" << std::endl;
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
2013-01-20 20:26:45 +00:00
|
|
|
{
|
|
|
|
whoami = QUtil::getWhoami(argv[0]);
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
if (argc != 3) {
|
2022-02-08 14:18:08 +00:00
|
|
|
usage();
|
2013-01-20 20:26:45 +00:00
|
|
|
}
|
|
|
|
char const* filename = argv[1];
|
2017-08-29 16:27:59 +00:00
|
|
|
int pageno = QUtil::string_to_int(argv[2]);
|
2013-01-20 20:26:45 +00:00
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
try {
|
2022-02-08 14:18:08 +00:00
|
|
|
QPDF pdf;
|
|
|
|
pdf.processFile(filename);
|
2018-06-18 19:06:51 +00:00
|
|
|
std::vector<QPDFPageObjectHelper> pages =
|
|
|
|
QPDFPageDocumentHelper(pdf).getAllPages();
|
2022-04-02 21:14:10 +00:00
|
|
|
if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size())) {
|
2013-01-20 20:26:45 +00:00
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
QPDFPageObjectHelper& page = pages.at(QIntC::to_size(pageno - 1));
|
2013-01-20 20:26:45 +00:00
|
|
|
ParserCallbacks cb;
|
2021-01-02 19:05:17 +00:00
|
|
|
page.parseContents(&cb);
|
2022-04-02 21:14:10 +00:00
|
|
|
} catch (std::exception& e) {
|
2022-02-08 14:18:08 +00:00
|
|
|
std::cerr << whoami << ": " << e.what() << std::endl;
|
|
|
|
exit(2);
|
2013-01-20 20:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|