aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/test_many_nulls.cc
blob: 07e81afeff85c0cc03f9e48f8a00def8091569d7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#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;
}