mirror of
https://github.com/qpdf/qpdf.git
synced 2025-02-12 00:28:31 +00:00
A bug was fixed between qpdf 8.4.2 and 9.0.0 regarding this type of file (see #305 and #311), but it was necessary to retest after some major refactoring work at the lexical and parsing layers. This lays the groundwork for including this in performance benchmarks and in the qpdf test suite rather than having to keep a large, non-redistributable file around. 20 arrays of 20K nulls is plenty for performance memory testing and doesn't take too long to run. Compared to qpdf 8.4.2, in qpdf 11.0.0, the file generated here uses 3% of the RAM and runs over 4 times faster.
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
#include <qpdf/QPDF.hh>
|
|
#include <qpdf/QPDFObjectHandle.hh>
|
|
#include <qpdf/QPDFWriter.hh>
|
|
#include <qpdf/QUtil.hh>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
auto whoami = QUtil::getWhoami(argv[0]);
|
|
if (argc != 2) {
|
|
std::cerr << "Usage: " << whoami << " outfile.pdf" << std::endl;
|
|
exit(2);
|
|
}
|
|
char const* outfile = argv[1];
|
|
|
|
// Create a file with lots of arrays containing very large numbers
|
|
// of nulls. Prior to qpdf 9.0.0, qpdf had a lot of trouble with
|
|
// this kind of file. This program is used to generate a file that
|
|
// can be used in the test suite and performance benchmarking.
|
|
QPDF q;
|
|
q.emptyPDF();
|
|
auto null = QPDFObjectHandle::newNull();
|
|
auto top = "[]"_qpdf;
|
|
for (int i = 0; i < 20; ++i) {
|
|
auto inner = "[]"_qpdf;
|
|
for (int j = 0; j < 20000; ++j) {
|
|
inner.appendItem(null);
|
|
}
|
|
top.appendItem(inner);
|
|
}
|
|
q.getTrailer().replaceKey("/Nulls", q.makeIndirectObject(top));
|
|
auto page = "<< /Type /Page /MediaBox [0 0 612 792] >>"_qpdf;
|
|
page = q.makeIndirectObject(page);
|
|
q.getRoot().getKey("/Pages").getKey("/Kids").appendItem(page);
|
|
QPDFWriter w(q, outfile);
|
|
w.setObjectStreamMode(qpdf_o_generate);
|
|
w.setDeterministicID(true);
|
|
w.write();
|
|
return 0;
|
|
}
|