2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-16 17:45:09 +00:00
qpdf/qpdf/test_xref.cc

55 lines
1.5 KiB
C++
Raw Normal View History

2019-09-28 13:07:00 +00:00
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFObjGen.hh>
#include <qpdf/QPDFXRefEntry.hh>
#include <cstdlib>
2019-09-28 13:07:00 +00:00
#include <iostream>
#include <map>
#include <string>
int
main(int argc, char* argv[])
2019-09-28 13:07:00 +00:00
{
if (argc != 2) {
2019-09-28 13:07:00 +00:00
std::cerr << "usage: test_xref INPUT.pdf" << std::endl;
std::exit(2);
}
try {
2019-09-28 13:07:00 +00:00
QPDF qpdf;
qpdf.processFile(argv[1]);
std::map<QPDFObjGen, QPDFXRefEntry> xref = qpdf.getXRefTable();
2019-09-28 13:07:00 +00:00
for (auto const& iter: xref) {
std::cout << iter.first.getObj() << "/" << iter.first.getGen()
<< ", ";
switch (iter.second.getType()) {
case 0:
std::cout << "free entry" << std::endl;
2019-09-28 13:07:00 +00:00
break;
case 1:
std::cout << "uncompressed, offset = "
<< iter.second.getOffset() << " (0x" << std::hex
<< iter.second.getOffset() << std::dec << ")"
<< std::endl;
2019-09-28 13:07:00 +00:00
break;
case 2:
std::cout << "compressed, stream number = "
<< iter.second.getObjStreamNumber()
<< ", stream index = "
<< iter.second.getObjStreamIndex() << std::endl;
2019-09-28 13:07:00 +00:00
break;
default:
std::cerr << "unknown" << std::endl;
2019-09-28 13:07:00 +00:00
std::exit(2);
}
}
} catch (std::exception& e) {
2019-09-28 13:07:00 +00:00
std::cerr << e.what() << std::endl;
std::exit(2);
}
return 0;
}