2019-09-28 13:07:00 +00:00
|
|
|
#include <qpdf/QPDF.hh>
|
|
|
|
#include <qpdf/QPDFObjGen.hh>
|
|
|
|
#include <qpdf/QPDFXRefEntry.hh>
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
#include <cstdlib>
|
2019-09-28 13:07:00 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
2019-09-28 13:07:00 +00:00
|
|
|
{
|
2022-04-02 21:14:10 +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);
|
|
|
|
}
|
|
|
|
|
2022-04-02 21:14:10 +00:00
|
|
|
try {
|
2019-09-28 13:07:00 +00:00
|
|
|
QPDF qpdf;
|
|
|
|
qpdf.processFile(argv[1]);
|
|
|
|
|
2022-05-21 14:18:15 +00:00
|
|
|
for (auto const& iter: qpdf.getXRefTable()) {
|
2022-04-30 17:23:18 +00:00
|
|
|
std::cout << iter.first.getObj() << "/" << iter.first.getGen()
|
2022-04-02 21:14:10 +00:00
|
|
|
<< ", ";
|
2022-04-30 17:23:18 +00:00
|
|
|
switch (iter.second.getType()) {
|
2022-04-02 21:14:10 +00:00
|
|
|
case 0:
|
|
|
|
std::cout << "free entry" << std::endl;
|
2019-09-28 13:07:00 +00:00
|
|
|
break;
|
2022-04-02 21:14:10 +00:00
|
|
|
case 1:
|
|
|
|
std::cout << "uncompressed, offset = "
|
2022-04-30 17:23:18 +00:00
|
|
|
<< iter.second.getOffset() << " (0x" << std::hex
|
|
|
|
<< iter.second.getOffset() << std::dec << ")"
|
2022-04-02 21:14:10 +00:00
|
|
|
<< std::endl;
|
2019-09-28 13:07:00 +00:00
|
|
|
break;
|
2022-04-02 21:14:10 +00:00
|
|
|
case 2:
|
|
|
|
std::cout << "compressed, stream number = "
|
2022-04-30 17:23:18 +00:00
|
|
|
<< iter.second.getObjStreamNumber()
|
2022-04-02 21:14:10 +00:00
|
|
|
<< ", stream index = "
|
2022-04-30 17:23:18 +00:00
|
|
|
<< iter.second.getObjStreamIndex() << std::endl;
|
2019-09-28 13:07:00 +00:00
|
|
|
break;
|
2022-04-02 21:14:10 +00:00
|
|
|
default:
|
|
|
|
std::cerr << "unknown" << std::endl;
|
2019-09-28 13:07:00 +00:00
|
|
|
std::exit(2);
|
|
|
|
}
|
|
|
|
}
|
2022-04-02 21:14:10 +00:00
|
|
|
} catch (std::exception& e) {
|
2019-09-28 13:07:00 +00:00
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
std::exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|