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
|
|
|
|
<< "Prints a dump of the objects in the content streams"
|
|
|
|
<< " of the given page." << std::endl
|
|
|
|
<< "Pages are numbered from 1." << std::endl;
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ParserCallbacks: public QPDFObjectHandle::ParserCallbacks
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ParserCallbacks()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void handleObject(QPDFObjectHandle);
|
|
|
|
virtual void handleEOF();
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ParserCallbacks::handleObject(QPDFObjectHandle obj)
|
|
|
|
{
|
2013-01-22 14:57:07 +00:00
|
|
|
std::cout << obj.getTypeName() << ": ";
|
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)
|
|
|
|
{
|
|
|
|
whoami += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc != 3)
|
|
|
|
{
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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;
|
2018-01-31 02:39:38 +00:00
|
|
|
page.parsePageContents(&cb);
|
2013-01-20 20:26:45 +00:00
|
|
|
}
|
|
|
|
catch (std::exception& e)
|
|
|
|
{
|
|
|
|
std::cerr << whoami << ": " << e.what() << std::endl;
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|