2013-01-20 20:26:45 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#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>
|
2019-06-21 03:35:23 +00:00
|
|
|
#include <qpdf/QIntC.hh>
|
2013-01-20 20:26:45 +00:00
|
|
|
|
|
|
|
static char const* whoami = 0;
|
|
|
|
|
|
|
|
void usage()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
ParserCallbacks::handleObject(QPDFObjectHandle obj,
|
|
|
|
size_t offset, size_t length)
|
|
|
|
{
|
|
|
|
std::cout << obj.getTypeName() << ", offset=" << offset
|
|
|
|
<< ", length=" << length << ": ";
|
2013-01-20 20:26:45 +00:00
|
|
|
if (obj.isInlineImage())
|
|
|
|
{
|
2013-01-25 13:59:55 +00:00
|
|
|
std::cout << QUtil::hex_encode(obj.getInlineImageValue()) << std::endl;
|
2013-01-20 20:26:45 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << obj.unparse() << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ParserCallbacks::handleEOF()
|
|
|
|
{
|
|
|
|
std::cout << "-EOF-" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
whoami = QUtil::getWhoami(argv[0]);
|
|
|
|
|
|
|
|
// For libtool's sake....
|
|
|
|
if (strncmp(whoami, "lt-", 3) == 0)
|
|
|
|
{
|
2022-02-08 14:18:08 +00:00
|
|
|
whoami += 3;
|
2013-01-20 20:26:45 +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
|
|
|
|
|
|
|
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();
|
2019-06-21 03:35:23 +00:00
|
|
|
if ((pageno < 1) || (QIntC::to_size(pageno) > pages.size()))
|
2013-01-20 20:26:45 +00:00
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
2019-06-21 03:35:23 +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);
|
2013-01-20 20:26:45 +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;
|
|
|
|
}
|