File: qpdf-manual.html

package info (click to toggle)
qpdf 8.0.2-2~bpo9%2B1
  • links: PTS
  • area: main
  • in suites: stretch-backports
  • size: 20,056 kB
  • sloc: cpp: 29,209; perl: 6,102; xml: 5,043; sh: 3,932; ansic: 2,743; makefile: 92
file content (3136 lines) | stat: -rw-r--r-- 218,540 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>QPDF Manual</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /></head><body><div class="book"><div class="titlepage"><div><div><h1 class="title"><a id="idm1"></a>QPDF Manual</h1></div><div><h2 class="subtitle">For QPDF Version 8.0.2, March 6, 2018</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Jay</span> <span class="surname">Berkenbilt</span></h3></div></div><div><p class="copyright">Copyright © 2005–2018 Jay Berkenbilt</p></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="preface"><a href="#acknowledgments">General Information</a></span></dt><dt><span class="chapter"><a href="#ref.overview">1. What is QPDF?</a></span></dt><dt><span class="chapter"><a href="#ref.installing">2. Building and Installing QPDF</a></span></dt><dd><dl><dt><span class="sect1"><a href="#ref.prerequisites">2.1. System Requirements</a></span></dt><dt><span class="sect1"><a href="#ref.building">2.2. Build Instructions</a></span></dt></dl></dd><dt><span class="chapter"><a href="#ref.using">3. Running QPDF</a></span></dt><dd><dl><dt><span class="sect1"><a href="#ref.invocation">3.1. Basic Invocation</a></span></dt><dt><span class="sect1"><a href="#ref.basic-options">3.2. Basic Options</a></span></dt><dt><span class="sect1"><a href="#ref.encryption-options">3.3. Encryption Options</a></span></dt><dt><span class="sect1"><a href="#ref.page-selection">3.4. Page Selection Options</a></span></dt><dt><span class="sect1"><a href="#ref.advanced-parsing">3.5. Advanced Parsing Options</a></span></dt><dt><span class="sect1"><a href="#ref.advanced-transformation">3.6. Advanced Transformation Options</a></span></dt><dt><span class="sect1"><a href="#ref.testing-options">3.7. Testing, Inspection, and Debugging Options</a></span></dt></dl></dd><dt><span class="chapter"><a href="#ref.qdf">4. QDF Mode</a></span></dt><dt><span class="chapter"><a href="#ref.using-library">5. Using the QPDF Library</a></span></dt><dt><span class="chapter"><a href="#ref.design">6. Design and Library Notes</a></span></dt><dd><dl><dt><span class="sect1"><a href="#ref.design.intro">6.1. Introduction</a></span></dt><dt><span class="sect1"><a href="#ref.design-goals">6.2. Design Goals</a></span></dt><dt><span class="sect1"><a href="#ref.casting">6.3. Casting Policy</a></span></dt><dt><span class="sect1"><a href="#ref.encryption">6.4. Encryption</a></span></dt><dt><span class="sect1"><a href="#ref.random-numbers">6.5. Random Number Generation</a></span></dt><dt><span class="sect1"><a href="#ref.adding-and-remove-pages">6.6. Adding and Removing Pages</a></span></dt><dt><span class="sect1"><a href="#ref.reserved-objects">6.7. Reserving Object Numbers</a></span></dt><dt><span class="sect1"><a href="#ref.foreign-objects">6.8. Copying Objects From Other PDF Files</a></span></dt><dt><span class="sect1"><a href="#ref.rewriting">6.9. Writing PDF Files</a></span></dt><dt><span class="sect1"><a href="#ref.filtered-streams">6.10. Filtered Streams</a></span></dt></dl></dd><dt><span class="chapter"><a href="#ref.linearization">7. Linearization</a></span></dt><dd><dl><dt><span class="sect1"><a href="#ref.linearization-strategy">7.1. Basic Strategy for Linearization</a></span></dt><dt><span class="sect1"><a href="#ref.linearized.preparation">7.2. Preparing For Linearization</a></span></dt><dt><span class="sect1"><a href="#ref.optimization">7.3. Optimization</a></span></dt><dt><span class="sect1"><a href="#ref.linearization.writing">7.4. Writing Linearized Files</a></span></dt><dt><span class="sect1"><a href="#ref.linearization-data">7.5. Calculating Linearization Data</a></span></dt><dt><span class="sect1"><a href="#ref.linearization-issues">7.6. Known Issues with Linearization</a></span></dt><dt><span class="sect1"><a href="#ref.linearization-debugging">7.7. Debugging Note</a></span></dt></dl></dd><dt><span class="chapter"><a href="#ref.object-and-xref-streams">8. Object and Cross-Reference Streams</a></span></dt><dd><dl><dt><span class="sect1"><a href="#ref.object-streams">8.1. Object Streams</a></span></dt><dt><span class="sect1"><a href="#ref.xref-streams">8.2. Cross-Reference Streams</a></span></dt><dd><dl><dt><span class="sect2"><a href="#ref.xref-stream-data">8.2.1. Cross-Reference Stream Data</a></span></dt></dl></dd><dt><span class="sect1"><a href="#ref.object-streams-linearization">8.3. Implications for Linearized Files</a></span></dt><dt><span class="sect1"><a href="#ref.object-stream-implementation">8.4. Implementation Notes</a></span></dt></dl></dd><dt><span class="appendix"><a href="#ref.release-notes">A. Release Notes</a></span></dt><dt><span class="appendix"><a href="#ref.upgrading-to-2.1">B. Upgrading from 2.0 to 2.1</a></span></dt><dt><span class="appendix"><a href="#ref.upgrading-to-3.0">C. Upgrading to 3.0</a></span></dt><dt><span class="appendix"><a href="#ref.upgrading-to-4.0">D. Upgrading to 4.0</a></span></dt></dl></div><div class="preface"><div class="titlepage"><div><div><h1 class="title"><a id="acknowledgments"></a>General Information</h1></div></div></div><p>
   QPDF is a program that does structural, content-preserving
   transformations on PDF files.  QPDF's website is located at <a class="ulink" href="http://qpdf.sourceforge.net/" target="_top">http://qpdf.sourceforge.net/</a>.
   QPDF's source code is hosted on github at <a class="ulink" href="https://github.com/qpdf/qpdf" target="_top">https://github.com/qpdf/qpdf</a>.
  </p><p>
   QPDF is licensed under <a class="ulink" href="http://www.apache.org/licenses/LICENSE-2.0" target="_top">the Apache
   License, Version 2.0</a> (the "License"). Unless required by
   applicable law or agreed to in writing, software distributed under
   the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
   OR CONDITIONS OF ANY KIND, either express or implied. See the
   License for the specific language governing permissions and
   limitations under the License.
  </p><p>
   Versions of qpdf prior to version 7 were released under the terms
   of <a class="ulink" href="https://opensource.org/licenses/Artistic-2.0" target="_top">the
   Artistic License, version 2.0</a>. At your option, you may
   continue to consider qpdf to be licensed under those terms. The
   Apache License 2.0 permits everything that the Artistic License 2.0
   permits but is slightly less restrictive. Allowing the Artistic
   License to continue being used is primary to help people who may
   have to get specific approval to use qpdf in their products.
  </p><p>
   QPDF is intentionally released with a permissive license. However,
   if there is some reason that the licensing terms don't work for
   your requirements, please feel free to contact the copyright holder
   to make other arrangements.
  </p><p>
   QPDF was originally created in 2001 and modified periodically
   between 2001 and 2005 during my employment at <a class="ulink" href="http://www.apexcovantage.com" target="_top">Apex CoVantage</a>.  Upon my
   departure from Apex, the company graciously allowed me to take
   ownership of the software and continue maintaining as an open
   source project, a decision for which I am very grateful.  I have
   made considerable enhancements to it since that time.  I feel
   fortunate to have worked for people who would make such a decision.
   This work would not have been possible without their support.
  </p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.overview"></a>Chapter 1. What is QPDF?</h1></div></div></div><p>
   QPDF is a program that does structural, content-preserving
   transformations on PDF files.  It could have been called something
   like <span class="emphasis"><em>pdf-to-pdf</em></span>.  It also provides many useful
   capabilities to developers of PDF-producing software or for people
   who just want to look at the innards of a PDF file to learn more
   about how they work.
  </p><p>
   With QPDF, it is possible to copy objects from one PDF file into
   another and to manipulate the list of pages in a PDF file.  This
   makes it possible to merge and split PDF files.  The QPDF library
   also makes it possible for you to create PDF files from scratch.
   In this mode, you are responsible for supplying all the contents of
   the file, while the QPDF library takes care off all the syntactical
   representation of the objects, creation of cross references tables
   and, if you use them, object streams, encryption, linearization,
   and other syntactic details.  You are still responsible for
   generating PDF content on your own.
  </p><p>
   QPDF has been designed with very few external dependencies, and it
   is intentionally very lightweight.  QPDF is
   <span class="emphasis"><em>not</em></span> a PDF content creation library, a PDF
   viewer, or a program capable of converting PDF into other formats.
   In particular, QPDF knows nothing about the semantics of PDF
   content streams.  If you are looking for something that can do
   that, you should look elsewhere.  However, once you have a valid
   PDF file, QPDF can be used to transform that file in ways perhaps
   your original PDF creation can't handle.  For example, many
   programs generate simple PDF files but can't password-protect them,
   web-optimize them, or perform other transformations of that type.
  </p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.installing"></a>Chapter 2. Building and Installing QPDF</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#ref.prerequisites">2.1. System Requirements</a></span></dt><dt><span class="sect1"><a href="#ref.building">2.2. Build Instructions</a></span></dt></dl></div><p>
   This chapter describes how to build and install qpdf.  Please see
   also the <code class="filename">README.md</code> and
   <code class="filename">INSTALL</code> files in the source distribution.
  </p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.prerequisites"></a>2.1. System Requirements</h2></div></div></div><p>
    The qpdf package has few external dependencies. In order to build
    qpdf, the following packages are required:
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       zlib: <a class="ulink" href="http://www.zlib.net/" target="_top">http://www.zlib.net/</a>
      </p></li><li class="listitem"><p>
       jpeg: <a class="ulink" href="http://www.ijg.org/files/" target="_top">http://www.ijg.org/files/</a>
       or <a class="ulink" href="https://libjpeg-turbo.org/" target="_top">https://libjpeg-turbo.org/</a>
      </p></li><li class="listitem"><p>
       gnu make 3.81 or newer: <a class="ulink" href="http://www.gnu.org/software/make" target="_top">http://www.gnu.org/software/make</a>
      </p></li><li class="listitem"><p>
       perl version 5.8 or newer:
       <a class="ulink" href="http://www.perl.org/" target="_top">http://www.perl.org/</a>;
       required for <span class="command"><strong>fix-qdf</strong></span> and the test suite.
      </p></li><li class="listitem"><p>
       GNU diffutils (any version): <a class="ulink" href="http://www.gnu.org/software/diffutils/" target="_top">http://www.gnu.org/software/diffutils/</a>
       is required to run the test suite.  Note that this is the
       version of diff present on virtually all GNU/Linux systems.
       This is required because the test suite uses <span class="command"><strong>diff
       -u</strong></span>.
      </p></li><li class="listitem"><p>
       A C++ compiler that works well with STL and has the <span class="type">long
       long</span> type. Most modern C++ compilers should fit the bill
       fine. QPDF is tested with gcc, clang, and Microsoft Visual C++.
      </p></li></ul></div><p>
   </p><p>
    Part of qpdf's test suite does comparisons of the contents PDF
    files by converting them images and comparing the images.  The
    image comparison tests are disabled by default.  Those tests are
    not required for determining correctness of a qpdf build if you
    have not modified the code since the test suite also contains
    expected output files that are compared literally.  The image
    comparison tests provide an extra check to make sure that any
    content transformations don't break the rendering of pages.
    Transformations that affect the content streams themselves are off
    by default and are only provided to help developers look into the
    contents of PDF files.  If you are making deep changes to the
    library that cause changes in the contents of the files that qpdf
    generates, then you should enable the image comparison tests.
    Enable them by running <span class="command"><strong>configure</strong></span> with the
    <code class="option">--enable-test-compare-images</code> flag.  If you enable
    this, the following additional requirements are required by the
    test suite.  Note that in no case are these items required to use
    qpdf.
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       libtiff: <a class="ulink" href="http://www.remotesensing.org/libtiff/" target="_top">http://www.remotesensing.org/libtiff/</a>
      </p></li><li class="listitem"><p>
       GhostScript version 8.60 or newer: <a class="ulink" href="http://www.ghostscript.com" target="_top">http://www.ghostscript.com</a>
      </p></li></ul></div><p>
    If you do not enable this, then you do not need to have tiff and
    ghostscript.
   </p><p>
    If Adobe Reader is installed as <span class="command"><strong>acroread</strong></span>, some
    additional test cases will be enabled.  These test cases simply
    verify that Adobe Reader can open the files that qpdf creates.
    They require version 8.0 or newer to pass.  However, in order to
    avoid having qpdf depend on non-free (as in liberty) software, the
    test suite will still pass without Adobe reader, and the test
    suite still exercises the full functionality of the software.
   </p><p>
    Pre-built documentation is distributed with qpdf, so you should
    generally not need to rebuild the documentation.  In order to
    build the documentation from its docbook sources, you need the
    docbook XML style sheets (<a class="ulink" href="http://downloads.sourceforge.net/docbook/" target="_top">http://downloads.sourceforge.net/docbook/</a>).
    To build the PDF version of the documentation, you need Apache fop
    (<a class="ulink" href="http://xml.apache.org/fop/" target="_top">http://xml.apache.org/fop/</a>)
    version 0.94 or higher.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.building"></a>2.2. Build Instructions</h2></div></div></div><p>
    Building qpdf on UNIX is generally just a matter of running

    </p><pre class="programlisting">./configure
make
</pre><p>
    You can also run <span class="command"><strong>make check</strong></span> to run the test
    suite and <span class="command"><strong>make install</strong></span> to install.  Please run
    <span class="command"><strong>./configure --help</strong></span> for options on what can be
    configured.  You can also set the value of
    <code class="varname">DESTDIR</code> during installation to install to a
    temporary location, as is common with many open source packages.
    Please see also the <code class="filename">README.md</code> and
    <code class="filename">INSTALL</code> files in the source distribution.
   </p><p>
    Building on Windows is a little bit more complicated.  For
    details, please see <code class="filename">README-windows.md</code> in the
    source distribution.  You can also download a binary distribution
    for Windows.  There is a port of qpdf to Visual C++ version 6 in
    the <code class="filename">contrib</code> area generously contributed by
    Jian Ma.  This is also discussed in more detail in
    <code class="filename">README-windows.md</code>.
   </p><p>
    There are some other things you can do with the build.  Although
    qpdf uses <span class="application">autoconf</span>, it does not use
    <span class="application">automake</span> but instead uses a
    hand-crafted non-recursive Makefile that requires gnu make.  If
    you're really interested, please read the comments in the
    top-level <code class="filename">Makefile</code>.
   </p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.using"></a>Chapter 3. Running QPDF</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#ref.invocation">3.1. Basic Invocation</a></span></dt><dt><span class="sect1"><a href="#ref.basic-options">3.2. Basic Options</a></span></dt><dt><span class="sect1"><a href="#ref.encryption-options">3.3. Encryption Options</a></span></dt><dt><span class="sect1"><a href="#ref.page-selection">3.4. Page Selection Options</a></span></dt><dt><span class="sect1"><a href="#ref.advanced-parsing">3.5. Advanced Parsing Options</a></span></dt><dt><span class="sect1"><a href="#ref.advanced-transformation">3.6. Advanced Transformation Options</a></span></dt><dt><span class="sect1"><a href="#ref.testing-options">3.7. Testing, Inspection, and Debugging Options</a></span></dt></dl></div><p>
   This chapter describes how to run the qpdf program from the command
   line.
  </p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.invocation"></a>3.1. Basic Invocation</h2></div></div></div><p>
    When running qpdf, the basic invocation is as follows:

    </p><pre class="programlisting"><span class="command"><strong>qpdf</strong></span><code class="option"> [ <em class="replaceable"><code>options</code></em> ] <em class="replaceable"><code>infilename</code></em> [ <em class="replaceable"><code>outfilename</code></em> ]</code>
</pre><p>
    This converts PDF file <code class="option">infilename</code> to PDF file
    <code class="option">outfilename</code>.  The output file is functionally
    identical to the input file but may have been structurally
    reorganized.  Also, orphaned objects will be removed from the
    file.  Many transformations are available as controlled by the
    options below.  In place of <code class="option">infilename</code>, the
    parameter <code class="option">--empty</code> may be specified.  This causes
    qpdf to use a dummy input file that contains zero pages.  The only
    normal use case for using <code class="option">--empty</code> would be if you
    were going to add pages from another source, as discussed in <a class="xref" href="#ref.page-selection" title="3.4. Page Selection Options">Section 3.4, “Page Selection Options”</a>.
   </p><p>
    If <code class="option">@filename</code> appears anywhere in the
    command-line, it will be read line by line, and each line will be
    treated as a command-line argument. The <code class="option">@-</code> option
    allows arguments to be read from standard input. This allows qpdf
    to be invoked with an arbitrary number of arbitrarily long
    arguments. It is also very useful for avoiding having to pass
    passwords on the command line.
   </p><p>
    <code class="option">outfilename</code> does not have to be seekable, even
    when generating linearized files.  Specifying
    “<code class="option">-</code>” as <code class="option">outfilename</code>
    means to write to standard output.  However, you can't specify the
    same file as both the input and the output because qpdf reads data
    from the input file as it writes to the output file. QPDF attempts
    to detect this case and fail without overwriting the output file.
   </p><p>
    Most options require an output file, but some testing or
    inspection commands do not.  These are specifically noted.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.basic-options"></a>3.2. Basic Options</h2></div></div></div><p>
    The following options are the most common ones and perform
    commonly needed transformations.
    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--password=password</code></span></dt><dd><p>
        Specifies a password for accessing encrypted files.
       </p></dd><dt><span class="term"><code class="option">--verbose</code></span></dt><dd><p>
        Increase verbosity of output. For now, this just prints some
        indication of any file that it creates.
       </p></dd><dt><span class="term"><code class="option">--linearize</code></span></dt><dd><p>
        Causes generation of a linearized (web-optimized) output file.
       </p></dd><dt><span class="term"><code class="option">--copy-encryption=file</code></span></dt><dd><p>
        Encrypt the file using the same encryption parameters,
        including user and owner password, as the specified file.  Use
        <code class="option">--encrypt-file-password</code> to specify a password
        if one is needed to open this file.  Note that copying the
        encryption parameters from a file also copies the first half
        of <code class="literal">/ID</code> from the file since this is part of
        the encryption parameters.
       </p></dd><dt><span class="term"><code class="option">--encrypt-file-password=password</code></span></dt><dd><p>
        If the file specified with <code class="option">--copy-encryption</code>
        requires a password, specify the password using this option.
        Note that only one of the user or owner password is required.
        Both passwords will be preserved since QPDF does not
        distinguish between the two passwords.  It is possible to
        preserve encryption parameters, including the owner password,
        from a file even if you don't know the file's owner password.
       </p></dd><dt><span class="term"><code class="option">--encrypt options --</code></span></dt><dd><p>
        Causes generation an encrypted output file.  Please see <a class="xref" href="#ref.encryption-options" title="3.3. Encryption Options">Section 3.3, “Encryption Options”</a> for details on how to
        specify encryption parameters.
       </p></dd><dt><span class="term"><code class="option">--decrypt</code></span></dt><dd><p>
        Removes any encryption on the file.  A password must be
        supplied if the file is password protected.
       </p></dd><dt><span class="term"><code class="option">--password-is-hex-key</code></span></dt><dd><p>
        Overrides the usual computation/retrieval of the PDF file's
        encryption key from user/owner password with an explicit
        specification of the encryption key. When this option is
        specified, the argument to the <code class="option">--password</code>
        option is interpreted as a hexadecimal-encoded key value. This
        only applies to the password used to open the main input file.
        It does not apply to other files opened by
        <code class="option">--pages</code> or other options or to files being
        written.
       </p><p>
        Most users will never have a need for this option, and no
        standard viewers support this mode of operation, but it can be
        useful for forensic or investigatory purposes. For example, if
        a PDF file is encrypted with an unknown password, a
        brute-force attack using the key directly is sometimes more
        efficient than one using the password. Also, if a file is
        heavily damaged, it may be possible to derive the encryption
        key and recover parts of the file using it directly. To expose
        the encryption key used by an encrypted file that you can open
        normally, use the <code class="option">--show-encryption-key</code>
        option.
       </p></dd><dt><span class="term"><code class="option">--rotate=[+|-]angle:page-range</code></span></dt><dd><p>
        Apply rotation to specified pages. The
        <code class="option">page-range</code> portion of the option value has
        the same format as page ranges in <a class="xref" href="#ref.page-selection" title="3.4. Page Selection Options">Section 3.4, “Page Selection Options”</a>. The <code class="option">angle</code>
        portion of the parameter may be either 90, 180, or 270. If
        preceded by <code class="option">+</code> or <code class="option">-</code>, the
        angle is added to or subtracted from the specified pages'
        original rotations. Otherwise the pages' rotations are set to
        the exact value. For example, the command <span class="command"><strong>qpdf in.pdf
        out.pdf --rotate=+90:2,4,6 --rotate=180:7-8</strong></span> would
        rotate pages 2, 4, and 6 90 degrees clockwise from their
        original rotation and force the rotation of pages 7 through 9
        to 180 degrees regardless of their original rotation.
       </p></dd><dt><span class="term"><code class="option">--pages options --</code></span></dt><dd><p>
        Select specific pages from one or more input files.  See <a class="xref" href="#ref.page-selection" title="3.4. Page Selection Options">Section 3.4, “Page Selection Options”</a> for details on how to do page
        selection (splitting and merging).
       </p></dd><dt><span class="term"><code class="option">--split-pages=[n]</code></span></dt><dd><p>
        Write each group of <code class="option">n</code> pages to a separate
        output file. If <code class="option">n</code> is not specified, create
        single pages. Output file names are generated as follows:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
           If the string <code class="literal">%d</code> appears in the output
           file name, it is replaced with a range of zero-padded page
           numbers starting from 1.
          </p></li><li class="listitem"><p>
           Otherwise, if the output file name ends in
           <code class="filename">.pdf</code> (case insensitive), a zero-padded
           page range, preceded by a dash, is inserted before the file
           extension.
          </p></li><li class="listitem"><p>
           Otherwise, the file name is appended with a zero-padded
           page range preceded by a dash.
          </p></li></ul></div><p>
       </p><p>
        Page ranges are a single number in the case of single-page
        groups or two numbers separated by a dash otherwise.
        For example, if <code class="filename">infile.pdf</code> has 12 pages
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
           <span class="command"><strong>qpdf --split-pages infile.pdf %d-out</strong></span>
           would generate files <code class="filename">01-out</code> through
           <code class="filename">12-out</code>
          </p></li><li class="listitem"><p>
           <span class="command"><strong>qpdf --split-pages=2 infile.pdf
           outfile.pdf</strong></span> would generate files
           <code class="filename">outfile-01-02.pdf</code> through
           <code class="filename">outfile-11-12.pdf</code>
          </p></li><li class="listitem"><p>
           <span class="command"><strong>qpdf --split-pages infile.pdf
           something.else</strong></span> would generate files
           <code class="filename">something.else-01</code> through
           <code class="filename">something.else-12</code>
          </p></li></ul></div><p>
       </p><p>
        Note that outlines, threads, and other global features of the
        original PDF file are not preserved. For each page of output,
        this option creates an empty PDF and copies a single page from
        the output into it. If you require the global data, you will
        have to run <span class="command"><strong>qpdf</strong></span> with the
        <code class="option">--pages</code> option once for each file. Using
        <code class="option">--split-pages</code> is much faster if you don't
        require the global data.
       </p></dd></dl></div><p>
   </p><p>
    Password-protected files may be opened by specifying a password.
    By default, qpdf will preserve any encryption data associated with
    a file.  If <code class="option">--decrypt</code> is specified, qpdf will
    attempt to remove any encryption information.  If
    <code class="option">--encrypt</code> is specified, qpdf will replace the
    document's encryption parameters with whatever is specified.
   </p><p>
    Note that qpdf does not obey encryption restrictions already
    imposed on the file.  Doing so would be meaningless since qpdf can
    be used to remove encryption from the file entirely.  This
    functionality is not intended to be used for bypassing copyright
    restrictions or other restrictions placed on files by their
    producers.
   </p><p>
    In all cases where qpdf allows specification of a password, care
    must be taken if the password contains characters that fall
    outside of the 7-bit US-ASCII character range to ensure that the
    exact correct byte sequence is provided.  It is possible that a
    future version of qpdf may handle this more gracefully.  For
    example, if a password was encrypted using a password that was
    encoded in ISO-8859-1 and your terminal is configured to use
    UTF-8, the password you supply may not work properly.  There are
    various approaches to handling this.  For example, if you are
    using Linux and have the iconv executable installed, you could
    pass <code class="option">--password=`echo <em class="replaceable"><code>password</code></em>
    | iconv -t iso-8859-1`</code> to qpdf where
    <em class="replaceable"><code>password</code></em> is a password specified in
    your terminal's locale. A detailed discussion of this is out of
    scope for this manual, but just be aware of this issue if you have
    trouble with a password that contains 8-bit characters.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.encryption-options"></a>3.3. Encryption Options</h2></div></div></div><p>
    To change the encryption parameters of a file, use the --encrypt
    flag.  The syntax is

    </p><pre class="programlisting"><code class="option">--encrypt <em class="replaceable"><code>user-password</code></em> <em class="replaceable"><code>owner-password</code></em> <em class="replaceable"><code>key-length</code></em> [ <em class="replaceable"><code>restrictions</code></em> ] --</code>
</pre><p>
    Note that “<code class="option">--</code>” terminates parsing of
    encryption flags and must be present even if no restrictions are
    present.
   </p><p>
    Either or both of the user password and the owner password may be
    empty strings.
   </p><p>
    The value for
    <code class="option"><em class="replaceable"><code>key-length</code></em></code> may be 40,
    128, or 256.  The restriction flags are dependent upon key length.
    When no additional restrictions are given, the default is to be
    fully permissive.
   </p><p>
    If <code class="option"><em class="replaceable"><code>key-length</code></em></code> is 40,
    the following restriction options are available:
    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--print=[yn]</code></span></dt><dd><p>
        Determines whether or not to allow printing.
       </p></dd><dt><span class="term"><code class="option">--modify=[yn]</code></span></dt><dd><p>
        Determines whether or not to allow document modification.
       </p></dd><dt><span class="term"><code class="option">--extract=[yn]</code></span></dt><dd><p>
        Determines whether or not to allow text/image extraction.
       </p></dd><dt><span class="term"><code class="option">--annotate=[yn]</code></span></dt><dd><p>
        Determines whether or not to allow comments and form fill-in
        and signing.
       </p></dd></dl></div><p>
    If <code class="option"><em class="replaceable"><code>key-length</code></em></code> is 128,
    the following restriction options are available:
    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--accessibility=[yn]</code></span></dt><dd><p>
        Determines whether or not to allow accessibility to visually
        impaired.
       </p></dd><dt><span class="term"><code class="option">--extract=[yn]</code></span></dt><dd><p>
        Determines whether or not to allow text/graphic extraction.
       </p></dd><dt><span class="term"><code class="option">--print=<em class="replaceable"><code>print-opt</code></em></code></span></dt><dd><p>
        Controls printing access.
        <code class="option"><em class="replaceable"><code>print-opt</code></em></code> may be
        one of the following:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
           <code class="option">full</code>: allow full printing
          </p></li><li class="listitem"><p>
           <code class="option">low</code>: allow low-resolution printing only
          </p></li><li class="listitem"><p>
           <code class="option">none</code>: disallow printing
          </p></li></ul></div><p>
       </p></dd><dt><span class="term"><code class="option">--modify=<em class="replaceable"><code>modify-opt</code></em></code></span></dt><dd><p>
        Controls modify access.
        <code class="option"><em class="replaceable"><code>modify-opt</code></em></code> may be
        one of the following, each of which implies all the options
        that follow it:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
           <code class="option">all</code>: allow full document modification
          </p></li><li class="listitem"><p>
           <code class="option">annotate</code>: allow comment authoring and form operations
          </p></li><li class="listitem"><p>
           <code class="option">form</code>: allow form field fill-in and signing
          </p></li><li class="listitem"><p>
           <code class="option">assembly</code>: allow document assembly only
          </p></li><li class="listitem"><p>
           <code class="option">none</code>: allow no modifications
          </p></li></ul></div><p>
       </p></dd><dt><span class="term"><code class="option">--cleartext-metadata</code></span></dt><dd><p>
        If specified, any metadata stream in the document will be left
        unencrypted even if the rest of the document is encrypted.
        This also forces the PDF version to be at least 1.5.
       </p></dd><dt><span class="term"><code class="option">--use-aes=[yn]</code></span></dt><dd><p>
        If <code class="option">--use-aes=y</code> is specified, AES encryption
        will be used instead of RC4 encryption.  This forces the PDF
        version to be at least 1.6.
       </p></dd><dt><span class="term"><code class="option">--force-V4</code></span></dt><dd><p>
        Use of this option forces the <code class="literal">/V</code> and
        <code class="literal">/R</code> parameters in the document's encryption
        dictionary to be set to the value <code class="literal">4</code>.  As
        qpdf will automatically do this when required, there is no
        reason to ever use this option.  It exists primarily for use
        in testing qpdf itself.  This option also forces the PDF
        version to be at least 1.5.
       </p></dd></dl></div><p>
    If <code class="option"><em class="replaceable"><code>key-length</code></em></code> is 256,
    the minimum PDF version is 1.7 with extension level 8, and the
    AES-based encryption format used is the PDF 2.0 encryption method
    supported by Acrobat X.  the same options are available as with
    128 bits with the following exceptions:
    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--use-aes</code></span></dt><dd><p>
        This option is not available with 256-bit keys.  AES is always
        used with 256-bit encryption keys.
       </p></dd><dt><span class="term"><code class="option">--force-V4</code></span></dt><dd><p>
        This option is not available with 256 keys.
       </p></dd><dt><span class="term"><code class="option">--force-R5</code></span></dt><dd><p>
        If specified, qpdf sets the minimum version to 1.7 at
        extension level 3 and writes the deprecated encryption format
        used by Acrobat version IX.  This option should not be used in
        practice to generate PDF files that will be in general use,
        but it can be useful to generate files if you are trying to
        test proper support in another application for PDF files
        encrypted in this way.
       </p></dd></dl></div><p>
    The default for each permission option is to be fully permissive.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.page-selection"></a>3.4. Page Selection Options</h2></div></div></div><p>
    Starting with qpdf 3.0, it is possible to split and merge PDF
    files by selecting pages from one or more input files.  Whatever
    file is given as the primary input file is used as the starting
    point, but its pages are replaced with pages as specified.

    </p><pre class="programlisting"><code class="option">--pages <em class="replaceable"><code>input-file</code></em> [ <em class="replaceable"><code>--password=password</code></em> ] [ <em class="replaceable"><code>page-range</code></em> ] [ ... ] --</code>
</pre><p>
    Multiple input files may be specified.  Each one is given as the
    name of the input file, an optional password (if required to open
    the file), and the range of pages.  Note that
    “<code class="option">--</code>” terminates parsing of page
    selection flags.
   </p><p>
    For each file that pages should be taken from, specify the file, a
    password needed to open the file (if any), and a page range.  The
    password needs to be given only once per file.  If any of the
    input files are the same as the primary input file or the file
    used to copy encryption parameters (if specified), you do not need
    to repeat the password here.  The same file can be repeated
    multiple times.  If a file that is repeated has a password, the
    password only has to be given the first time.  All non-page data
    (info, outlines, page numbers, etc.) are taken from the primary
    input file.  To discard these, use <code class="option">--empty</code> as the
    primary input.
   </p><p>
    Starting with qpdf 5.0.0, it is possible to omit the page range.
    If qpdf sees a value in the place where it expects a page range
    and that value is not a valid range but is a valid file name, qpdf
    will implicitly use the range <code class="literal">1-z</code>, meaning that
    it will include all pages in the file.  This makes it possible to
    easily combine all pages in a set of files with a command like
    <span class="command"><strong>qpdf --empty out.pdf --pages *.pdf --</strong></span>.
   </p><p>
    It is not presently possible to specify the same page from the
    same file directly more than once, but you can make this work by
    specifying two different paths to the same file (such as by
    putting <code class="filename">./</code> somewhere in the path).  This can
    also be used if you want to repeat a page from one of the input
    files in the output file.  This may be made more convenient in a
    future version of qpdf if there is enough demand for this feature.
   </p><p>
    The page range is a set of numbers separated by commas, ranges of
    numbers separated dashes, or combinations of those. The character
    “z” represents the last page. A number preceded by an
    “r” indicates to count from the end, so
    <code class="literal">r3-r1</code> would be the last three pages of the
    document. Pages can appear in any order. Ranges can appear with a
    high number followed by a low number, which causes the pages to
    appear in reverse. Repeating a number will cause an error, but you
    can use the workaround discussed above should you really want to
    include the same page twice.
   </p><p>
    Example page ranges:
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       <code class="literal">1,3,5-9,15-12</code>: pages 1, 3, 5, 6, 7, 8,
       9, 15, 14, 13, and 12 in that order.
      </p></li><li class="listitem"><p>
       <code class="literal">z-1</code>: all pages in the document in reverse
      </p></li><li class="listitem"><p>
       <code class="literal">r3-r1</code>: the last three pages of the document
      </p></li><li class="listitem"><p>
       <code class="literal">r1-r3</code>: the last three pages of the document
       in reverse order
      </p></li></ul></div><p>
   </p><p>
    Note that qpdf doesn't presently do anything special about other
    constructs in a PDF file that may know about pages, so semantics
    of splitting and merging vary across features.  For example, the
    document's outlines (bookmarks) point to actual page objects, so
    if you select some pages and not others, bookmarks that point to
    pages that are in the output file will work, and remaining
    bookmarks will not work.  On the other hand, page labels (page
    numbers specified in the file) are just sequential, so page labels
    will be messed up in the output file.  A future version of
    <span class="command"><strong>qpdf</strong></span> may do a better job at handling these
    issues.  (Note that the qpdf library already contains all of the
    APIs required in order to implement this in your own application
    if you need it.)  In the mean time, you can always use
    <code class="option">--empty</code> as the primary input file to avoid
    copying all of that from the first file.  For example, to take
    pages 1 through 5 from a <code class="filename">infile.pdf</code> while
    preserving all metadata associated with that file, you could use

    </p><pre class="programlisting"><span class="command"><strong>qpdf</strong></span> <code class="option">infile.pdf --pages infile.pdf 1-5 -- outfile.pdf</code>
</pre><p>
    If you wanted pages 1 through 5 from
    <code class="filename">infile.pdf</code> but you wanted the rest of the
    metadata to be dropped, you could instead run

    </p><pre class="programlisting"><span class="command"><strong>qpdf</strong></span> <code class="option">--empty --pages infile.pdf 1-5 -- outfile.pdf</code>
</pre><p>
    If you wanted to take pages 1–5 from
    <code class="filename">file1.pdf</code> and pages 11–15 from
    <code class="filename">file2.pdf</code> in reverse, you would run

    </p><pre class="programlisting"><span class="command"><strong>qpdf</strong></span> <code class="option">file1.pdf --pages file1.pdf 1-5 file2.pdf 15-11 -- outfile.pdf</code>
</pre><p>
    If, for some reason, you wanted to take the first page of an
    encrypted file called <code class="filename">encrypted.pdf</code> with
    password <code class="literal">pass</code> and repeat it twice in an output
    file, and if you wanted to drop metadata (like page numbers and
    outlines) but preserve encryption, you would use

    </p><pre class="programlisting"><span class="command"><strong>qpdf</strong></span> <code class="option">--empty --copy-encryption=encrypted.pdf --encryption-file-password=pass
--pages encrypted.pdf --password=pass 1 ./encrypted.pdf --password=pass 1 --
outfile.pdf</code>
</pre><p>
    Note that we had to specify the password all three times because
    giving a password as <code class="option">--encryption-file-password</code>
    doesn't count for page selection, and as far as qpdf is concerned,
    <code class="filename">encrypted.pdf</code> and
    <code class="filename">./encrypted.pdf</code> are separated files.  These
    are all corner cases that most users should hopefully never have
    to be bothered with.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.advanced-parsing"></a>3.5. Advanced Parsing Options</h2></div></div></div><p>
    These options control aspects of how qpdf reads PDF files. Mostly
    these are of use to people who are working with damaged files.
    There is little reason to use these options unless you are trying
    to solve specific problems. The following options are available:
    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--suppress-recovery</code></span></dt><dd><p>
        Prevents qpdf from attempting to recover damaged files.
       </p></dd><dt><span class="term"><code class="option">--ignore-xref-streams</code></span></dt><dd><p>
        Tells qpdf to ignore any cross-reference streams.
       </p></dd></dl></div><p>
   </p><p>
    Ordinarily, qpdf will attempt to recover from certain types of
    errors in PDF files.  These include errors in the cross-reference
    table, certain types of object numbering errors, and certain types
    of stream length errors.  Sometimes, qpdf may think it has
    recovered but may not have actually recovered, so care should be
    taken when using this option as some data loss is possible.  The
    <code class="option">--suppress-recovery</code> option will prevent qpdf from
    attempting recovery.  In this case, it will fail on the first
    error that it encounters.
   </p><p>
    Ordinarily, qpdf reads cross-reference streams when they are
    present in a PDF file.  If <code class="option">--ignore-xref-streams</code>
    is specified, qpdf will ignore any cross-reference streams for
    hybrid PDF files.  The purpose of hybrid files is to make some
    content available to viewers that are not aware of cross-reference
    streams.  It is almost never desirable to ignore them.  The only
    time when you might want to use this feature is if you are testing
    creation of hybrid PDF files and wish to see how a PDF consumer
    that doesn't understand object and cross-reference streams would
    interpret such a file.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.advanced-transformation"></a>3.6. Advanced Transformation Options</h2></div></div></div><p>
    These transformation options control fine points of how qpdf
    creates the output file.  Mostly these are of use only to people
    who are very familiar with the PDF file format or who are PDF
    developers.  The following options are available:
    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--compress-streams=<em class="replaceable"><code>[yn]</code></em></code></span></dt><dd><p>
        By default, or with <code class="option">--compress-streams=y</code>,
        qpdf will compress any stream with no other filters applied to
        it with the <code class="literal">/FlateDecode</code> filter when it
        writes it. To suppress this behavior and preserve uncompressed
        streams as uncompressed, use
        <code class="option">--compress-streams=n</code>.
       </p></dd><dt><span class="term"><code class="option">--decode-level=<em class="replaceable"><code>option</code></em></code></span></dt><dd><p>
        Controls which streams qpdf tries to decode. The default is
        <code class="option">generalized</code>. The following options are
        available:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
           <code class="option">none</code>: do not attempt to decode any streams
          </p></li><li class="listitem"><p>
           <code class="option">generalized</code>: decode streams filtered with
           supported generalized filters: <code class="option">/LZWDecode</code>,
           <code class="option">/FlateDecode</code>,
           <code class="option">/ASCII85Decode</code>, and
           <code class="option">/ASCIIHexDecode</code>. We define generalized
           filters as those to be used for general-purpose compression
           or encoding, as opposed to filters specifically designed
           for image data.
          </p></li><li class="listitem"><p>
           <code class="option">specialized</code>: in addition to generalized,
           decode streams with supported non-lossy specialized
           filters; currently this is just <code class="option">/RunLengthDecode</code>
          </p></li><li class="listitem"><p>
           <code class="option">all</code>: in addition to generalized and
           specialized, decode streams with supported lossy filters;
           currently this is just <code class="option">/DCTDecode</code> (JPEG)
          </p></li></ul></div><p>
       </p></dd><dt><span class="term"><code class="option">--stream-data=<em class="replaceable"><code>option</code></em></code></span></dt><dd><p>
        Controls transformation of stream data. This option predates
        the <code class="option">--compress-streams</code> and
        <code class="option">--decode-level</code> options. Those options can be
        used to achieve the same affect with more control. The value
        of <code class="option"><em class="replaceable"><code>option</code></em></code> may be
        one of the following:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
           <code class="option">compress</code>: recompress stream data when
           possible (default); equivalent to
           <code class="option">--compress-streams=y</code>
           <code class="option">--decode-level=generalized</code>
          </p></li><li class="listitem"><p>
           <code class="option">preserve</code>: leave all stream data as is;
           equivalent to <code class="option">--compress-streams=n</code>
           <code class="option">--decode-level=none</code>
          </p></li><li class="listitem"><p>
           <code class="option">uncompress</code>: uncompress stream data
           compressed with generalized filters when possible;
           equivalent to <code class="option">--compress-streams=n</code>
           <code class="option">--decode-level=generalized</code>
          </p></li></ul></div><p>
       </p></dd><dt><span class="term"><code class="option">--normalize-content=[yn]</code></span></dt><dd><p>
        Enables or disables normalization of content streams. Content
        normalization is enabled by default in QDF mode. Please see
        <a class="xref" href="#ref.qdf" title="Chapter 4. QDF Mode">Chapter 4, <em>QDF Mode</em></a> for additional discussion of QDF
        mode.
       </p></dd><dt><span class="term"><code class="option">--object-streams=<em class="replaceable"><code>mode</code></em></code></span></dt><dd><p>
        Controls handling of object streams.  The value of
        <code class="option"><em class="replaceable"><code>mode</code></em></code> may be one of
        the following:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
           <code class="option">preserve</code>: preserve original object streams
           (default)
          </p></li><li class="listitem"><p>
           <code class="option">disable</code>: don't write any object streams
          </p></li><li class="listitem"><p>
           <code class="option">generate</code>: use object streams wherever
           possible
          </p></li></ul></div><p>
       </p></dd><dt><span class="term"><code class="option">--preserve-unreferenced</code></span></dt><dd><p>
        Tells qpdf to preserve objects that are not referenced when
        writing the file. Ordinarily any object that is not referenced
        in a traversal of the document from the trailer dictionary
        will be discarded. This may be useful in working with some
        damaged files or inspecting files with known unreferenced
        objects.
       </p><p>
        This flag is ignored for linearized files and has the effect
        of causing objects in the new file to be written in order by
        object ID from the original file. This does not mean that
        object numbers will be the same since qpdf may create stream
        lengths as direct or indirect differently from the original
        file, and the original file may have gaps in its numbering.
       </p></dd><dt><span class="term"><code class="option">--newline-before-endstream</code></span></dt><dd><p>
        Tells qpdf to insert a newline before the
        <code class="literal">endstream</code> keyword, not counted in the
        length, after any stream content even if the last character of
        the stream was a newline. This may result in two newlines in
        some cases. This is a requirement of PDF/A. While qpdf doesn't
        specifically know how to generate PDF/A-compliant PDFs, this
        at least prevents it from removing compliance on already
        compliant files.
       </p></dd><dt><span class="term"><code class="option">--linearize-pass1=<em class="replaceable"><code>file</code></em></code></span></dt><dd><p>
        Write the first pass of linearization to the named file. The
        resulting file is not a valid PDF file. This option is useful
        only for debugging <code class="classname">QPDFWriter</code>'s
        linearization code. When qpdf linearizes files, it writes the
        file in two passes, using the first pass to calculate sizes
        and offsets that are required for hint tables and the
        linearization dictionary. Ordinarily, the first pass is
        discarded. This option enables it to be captured.
       </p></dd><dt><span class="term"><code class="option">--coalesce-contents</code></span></dt><dd><p>
        When a page's contents are split across multiple streams, this
        option causes qpdf to combine them into a single stream. Use
        of this option is never necessary for ordinary usage, but it
        can help when working with some files in some cases. For
        example, some PDF writers split page contents into small
        streams at arbitrary points that may fall in the middle of
        lexical tokens within the content, and some PDF readers may
        get confused on such files. If you use qpdf to coalesce the
        content streams, such readers may be able to work with the
        file more easily. This can also be combined with QDF mode or
        content normalization to make it easier to look at all of a
        page's contents at once.
       </p></dd><dt><span class="term"><code class="option">--qdf</code></span></dt><dd><p>
        Turns on QDF mode.  For additional information on QDF, please
        see <a class="xref" href="#ref.qdf" title="Chapter 4. QDF Mode">Chapter 4, <em>QDF Mode</em></a>.
       </p></dd><dt><span class="term"><code class="option">--min-version=<em class="replaceable"><code>version</code></em></code></span></dt><dd><p>
        Forces the PDF version of the output file to be at least
        <em class="replaceable"><code>version</code></em>.  In other words, if the
        input file has a lower version than the specified version, the
        specified version will be used.  If the input file has a
        higher version, the input file's original version will be
        used.  It is seldom necessary to use this option since qpdf
        will automatically increase the version as needed when adding
        features that require newer PDF readers.
       </p><p>
        The version number may be expressed in the form
        <em class="replaceable"><code>major.minor.extension-level</code></em>, in
        which case the version is interpreted as
        <em class="replaceable"><code>major.minor</code></em> at extension level
        <em class="replaceable"><code>extension-level</code></em>.  For example,
        version <code class="literal">1.7.8</code> represents version 1.7 at
        extension level 8.  Note that minimal syntax checking is done
        on the command line.
       </p></dd><dt><span class="term"><code class="option">--force-version=<em class="replaceable"><code>version</code></em></code></span></dt><dd><p>
        This option forces the PDF version to be the exact version
        specified <span class="emphasis"><em>even when the file may have content that
        is not supported in that version</em></span>.  The version
        number is interpreted in the same way as with
        <code class="option">--min-version</code> so that extension levels can be
        set.  In some cases, forcing the output file's PDF version to
        be lower than that of the input file will cause qpdf to
        disable certain features of the document.  Specifically,
        256-bit keys are disabled if the version is less than 1.7 with
        extension level 8 (except R5 is disabled if less than 1.7 with
        extension level 3), AES encryption is disabled if the version
        is less than 1.6, cleartext metadata and object streams are
        disabled if less than 1.5, 128-bit encryption keys are
        disabled if less than 1.4, and all encryption is disabled if
        less than 1.3.  Even with these precautions, qpdf won't be
        able to do things like eliminate use of newer image
        compression schemes, transparency groups, or other features
        that may have been added in more recent versions of PDF.
       </p><p>
        As a general rule, with the exception of big structural things
        like the use of object streams or AES encryption, PDF viewers
        are supposed to ignore features in files that they don't
        support from newer versions.  This means that forcing the
        version to a lower version may make it possible to open your
        PDF file with an older version, though bear in mind that some
        of the original document's functionality may be lost.
       </p></dd></dl></div><p>
   </p><p>
    By default, when a stream is encoded using non-lossy filters that
    qpdf understands and is not already compressed using a good
    compression scheme, qpdf will uncompress and recompress streams.
    Assuming proper filter implements, this is safe and generally
    results in smaller files.  This behavior may also be explicitly
    requested with <code class="option">--stream-data=compress</code>.
   </p><p>
    When <code class="option">--normalize-content=y</code> is specified, qpdf
    will attempt to normalize whitespace and newlines in page content
    streams.  This is generally safe but could, in some cases, cause
    damage to the content streams.  This option is intended for people
    who wish to study PDF content streams or to debug PDF content.
    You should not use this for “production” PDF files.
   </p><p>
    This paragraph discusses edge cases of content normalization that
    are not of concern to most users and are not relevant when content
    normalization is not enabled. When normalizing content, if qpdf
    runs into any lexical errors, it will print a warning indicating
    that content may be damaged. The only situation in which qpdf is
    known to cause damage during content normalization is when a
    page's contents are split across multiple streams and streams are
    split in the middle of a lexical token such as a string, name, or
    inline image. There may be some pathological cases in which qpdf
    could damage content without noticing this, such as if the partial
    tokens at the end of one stream and the beginning of the next
    stream are both valid, but usually qpdf will be able to detect
    this case. For slightly increased safety, you can specify
    <code class="option">--coalesce-contents</code> in addition to
    <code class="option">--normalize-content</code> or <code class="option">--qdf</code>.
    This will cause qpdf to combine all the content streams into one,
    thus recombining any split tokens. However doing this will prevent
    you from being able to see the original layout of the content
    streams. If you must inspect the original content streams in an
    uncompressed format, you can always run with <code class="option">--qdf
    --normalize-content=n</code> for a QDF file without content
    normalization, or alternatively
    <code class="option">--stream-data=uncompress</code> for a regular non-QDF
    mode file with uncompressed streams. These will both uncompress
    all the streams but will not attempt to normalize content. Please
    note that if you are using content normalization or QDF mode for
    the purpose of manually inspecting files, you don't have to care
    about this.
   </p><p>
    Object streams, also known as compressed objects, were introduced
    into the PDF specification at version 1.5, corresponding to
    Acrobat 6.  Some older PDF viewers may not support files with
    object streams.  qpdf can be used to transform files with object
    streams to files without object streams or vice versa.  As
    mentioned above, there are three object stream modes:
    <code class="option">preserve</code>, <code class="option">disable</code>, and
    <code class="option">generate</code>.
   </p><p>
    In <code class="option">preserve</code> mode, the relationship to objects and
    the streams that contain them is preserved from the original file.
    In <code class="option">disable</code> mode, all objects are written as
    regular, uncompressed objects.  The resulting file should be
    readable by older PDF viewers.  (Of course, the content of the
    files may include features not supported by older viewers, but at
    least the structure will be supported.)  In
    <code class="option">generate</code> mode, qpdf will create its own object
    streams.  This will usually result in more compact PDF files,
    though they may not be readable by older viewers.  In this mode,
    qpdf will also make sure the PDF version number in the header is
    at least 1.5.
   </p><p>
    The <code class="option">--qdf</code> flag turns on QDF mode, which changes
    some of the defaults described above.  Specifically, in QDF mode,
    by default, stream data is uncompressed, content streams are
    normalized, and encryption is removed.  These defaults can still
    be overridden by specifying the appropriate options as described
    above.  Additionally, in QDF mode, stream lengths are stored as
    indirect objects, objects are laid out in a less efficient but
    more readable fashion, and the documents are interspersed with
    comments that make it easier for the user to find things and also
    make it possible for <span class="command"><strong>fix-qdf</strong></span> to work properly.
    QDF mode is intended for people, mostly developers, who wish to
    inspect or modify PDF files in a text editor.  For details, please
    see <a class="xref" href="#ref.qdf" title="Chapter 4. QDF Mode">Chapter 4, <em>QDF Mode</em></a>.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.testing-options"></a>3.7. Testing, Inspection, and Debugging Options</h2></div></div></div><p>
    These options can be useful for digging into PDF files or for use
    in automated test suites for software that uses the qpdf library.
    When any of the options in this section are specified, no output
    file should be given.  The following options are available:
    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">--deterministic-id</code></span></dt><dd><p>
        Causes generation of a deterministic value for /ID. This
        prevents use of timestamp and output file name information in
        the /ID generation. Instead, at some slight additional runtime
        cost, the /ID field is generated to include a digest of the
        significant parts of the content of the output PDF file. This
        means that a given qpdf operation should generate the same /ID
        each time it is run, which can be useful when caching results
        or for generation of some test data. Use of this flag is not
        compatible with creation of encrypted files.
       </p></dd><dt><span class="term"><code class="option">--static-id</code></span></dt><dd><p>
        Causes generation of a fixed value for /ID. This is intended
        for testing only. Never use it for production files. If you
        are trying to get the same /ID each time for a given file and
        you are not generating encrypted files, consider using the
        <code class="option">--deterministic-id</code> option.
       </p></dd><dt><span class="term"><code class="option">--static-aes-iv</code></span></dt><dd><p>
        Causes use of a static initialization vector for AES-CBC.
        This is intended for testing only so that output files can be
        reproducible.  Never use it for production files.  This option
        in particular is not secure since it significantly weakens the
        encryption.
       </p></dd><dt><span class="term"><code class="option">--no-original-object-ids</code></span></dt><dd><p>
        Suppresses inclusion of original object ID comments in QDF
        files.  This can be useful when generating QDF files for test
        purposes, particularly when comparing them to determine
        whether two PDF files have identical content.
       </p></dd><dt><span class="term"><code class="option">--show-encryption</code></span></dt><dd><p>
        Shows document encryption parameters.  Also shows the
        document's user password if the owner password is given.
       </p></dd><dt><span class="term"><code class="option">--show-encryption-key</code></span></dt><dd><p>
        When encryption information is being displayed, as when
        <code class="option">--check</code> or <code class="option">--show-encryption</code>
        is given, display the computed or retrieved encryption key as
        a hexadecimal string. This value is not ordinarily useful to
        users, but it can be used as the argument to
        <code class="option">--password</code> if the
        <code class="option">--password-is-hex-key</code> is specified. Note
        that, when PDF files are encrypted, passwords and other
        metadata are used only to compute an encryption key, and the
        encryption key is what is actually used for encryption. This
        enables retrieval of that key.
       </p></dd><dt><span class="term"><code class="option">--check-linearization</code></span></dt><dd><p>
        Checks file integrity and linearization status.
       </p></dd><dt><span class="term"><code class="option">--show-linearization</code></span></dt><dd><p>
        Checks and displays all data in the linearization hint tables.
       </p></dd><dt><span class="term"><code class="option">--show-xref</code></span></dt><dd><p>
        Shows the contents of the cross-reference table in a
        human-readable form.  This is especially useful for files with
        cross-reference streams which are stored in a binary format.
       </p></dd><dt><span class="term"><code class="option">--show-object=obj[,gen]</code></span></dt><dd><p>
        Show the contents of the given object.  This is especially
        useful for inspecting objects that are inside of object
        streams (also known as “compressed objects”).
       </p></dd><dt><span class="term"><code class="option">--raw-stream-data</code></span></dt><dd><p>
        When used along with the <code class="option">--show-object</code>
        option, if the object is a stream, shows the raw stream data
        instead of object's contents.
       </p></dd><dt><span class="term"><code class="option">--filtered-stream-data</code></span></dt><dd><p>
        When used along with the <code class="option">--show-object</code>
        option, if the object is a stream, shows the filtered stream
        data instead of object's contents.  If the stream is filtered
        using filters that qpdf does not support, an error will be
        issued.
       </p></dd><dt><span class="term"><code class="option">--show-npages</code></span></dt><dd><p>
        Prints the number of pages in the input file on a line by
        itself.  Since the number of pages appears by itself on a
        line, this option can be useful for scripting if you need to
        know the number of pages in a file.
       </p></dd><dt><span class="term"><code class="option">--show-pages</code></span></dt><dd><p>
        Shows the object and generation number for each page
        dictionary object and for each content stream associated with
        the page.  Having this information makes it more convenient to
        inspect objects from a particular page.
       </p></dd><dt><span class="term"><code class="option">--with-images</code></span></dt><dd><p>
        When used along with <code class="option">--show-pages</code>, also shows
        the object and generation numbers for the image objects on
        each page.  (At present, information about images in shared
        resource dictionaries are not output by this command.  This is
        discussed in a comment in the source code.)
       </p></dd><dt><span class="term"><code class="option">--check</code></span></dt><dd><p>
        Checks file structure and well as encryption, linearization,
        and encoding of stream data.  A file for which
        <code class="option">--check</code> reports no errors may still have
        errors in stream data content but should otherwise be
        structurally sound.  If <code class="option">--check</code> any errors,
        qpdf will exit with a status of 2.  There are some recoverable
        conditions that <code class="option">--check</code> detects.  These are
        issued as warnings instead of errors.  If qpdf finds no errors
        but finds warnings, it will exit with a status of 3 (as of
        version 2.0.4). When <code class="option">--check</code> is combined
        with other options, checks are always performed before any
        other options are processed. For erroneous files,
        <code class="option">--check</code> will cause qpdf to attempt to
        recover, after which other options are effectively operating
        on the recovered file. Combining <code class="option">--check</code> with
        other options in this way can be useful for manually
        recovering severely damaged files.
       </p></dd></dl></div><p>
   </p><p>
    The <code class="option">--raw-stream-data</code> and
    <code class="option">--filtered-stream-data</code> options are ignored unless
    <code class="option">--show-object</code> is given.  Either of these options
    will cause the stream data to be written to standard output.  In
    order to avoid commingling of stream data with other output, it is
    recommend that these objects not be combined with other
    test/inspection options.
   </p><p>
    If <code class="option">--filtered-stream-data</code> is given and
    <code class="option">--normalize-content=y</code> is also given, qpdf will
    attempt to normalize the stream data as if it is a page content
    stream.  This attempt will be made even if it is not a page
    content stream, in which case it will produce unusable results.
   </p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.qdf"></a>Chapter 4. QDF Mode</h1></div></div></div><p>
   In QDF mode, qpdf creates PDF files in what we call <em class="firstterm">QDF
   form</em>.  A PDF file in QDF form, sometimes called a QDF
   file, is a completely valid PDF file that has
   <code class="literal">%QDF-1.0</code> as its third line (after the pdf header
   and binary characters) and has certain other characteristics.  The
   purpose of QDF form is to make it possible to edit PDF files, with
   some restrictions, in an ordinary text editor.  This can be very
   useful for experimenting with different PDF constructs or for
   making one-off edits to PDF files (though there are other reasons
   why this may not always work).
  </p><p>
   It is ordinarily very difficult to edit PDF files in a text editor
   for two reasons: most meaningful data in PDF files is compressed,
   and PDF files are full of offset and length information that makes
   it hard to add or remove data.  A QDF file is organized in a manner
   such that, if edits are kept within certain constraints, the
   <span class="command"><strong>fix-qdf</strong></span> program, distributed with qpdf, is able
   to restore edited files to a correct state.  The
   <span class="command"><strong>fix-qdf</strong></span> program takes no command-line
   arguments.  It reads a possibly edited QDF file from standard input
   and writes a repaired file to standard output.
  </p><p>
   The following attributes characterize a QDF file:
   </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
      All objects appear in numerical order in the PDF file, including
      when objects appear in object streams.
     </p></li><li class="listitem"><p>
      Objects are printed in an easy-to-read format, and all line
      endings are normalized to UNIX line endings.
     </p></li><li class="listitem"><p>
      Unless specifically overridden, streams appear uncompressed
      (when qpdf supports the filters and they are compressed with a
      non-lossy compression scheme), and most content streams are
      normalized (line endings are converted to just a UNIX-style
      linefeeds).
     </p></li><li class="listitem"><p>
      All streams lengths are represented as indirect objects, and the
      stream length object is always the next object after the stream.
      If the stream data does not end with a newline, an extra newline
      is inserted, and a special comment appears after the stream
      indicating that this has been done.
     </p></li><li class="listitem"><p>
      If the PDF file contains object streams, if object stream
      <span class="emphasis"><em>n</em></span> contains <span class="emphasis"><em>k</em></span> objects,
      those objects are numbered from <span class="emphasis"><em>n+1</em></span> through
      <span class="emphasis"><em>n+k</em></span>, and the object number/offset pairs
      appear on a separate line for each object.  Additionally, each
      object in the object stream is preceded by a comment indicating
      its object number and index.  This makes it very easy to find
      objects in object streams.
     </p></li><li class="listitem"><p>
      All beginnings of objects, <code class="literal">stream</code> tokens,
      <code class="literal">endstream</code> tokens, and
      <code class="literal">endobj</code> tokens appear on lines by themselves.
      A blank line follows every <code class="literal">endobj</code> token.
     </p></li><li class="listitem"><p>
      If there is a cross-reference stream, it is unfiltered.
     </p></li><li class="listitem"><p>
      Page dictionaries and page content streams are marked with
      special comments that make them easy to find.
     </p></li><li class="listitem"><p>
      Comments precede each object indicating the object number of the
      corresponding object in the original file.
     </p></li></ul></div><p>
  </p><p>
   When editing a QDF file, any edits can be made as long as the above
   constraints are maintained.  This means that you can freely edit a
   page's content without worrying about messing up the QDF file.  It
   is also possible to add new objects so long as those objects are
   added after the last object in the file or subsequent objects are
   renumbered.  If a QDF file has object streams in it, you can always
   add the new objects before the xref stream and then change the
   number of the xref stream, since nothing generally ever references
   it by number.
  </p><p>
   It is not generally practical to remove objects from QDF files
   without messing up object numbering, but if you remove all
   references to an object, you can run qpdf on the file (after
   running <span class="command"><strong>fix-qdf</strong></span>), and qpdf will omit the
   now-orphaned object.
  </p><p>
   When <span class="command"><strong>fix-qdf</strong></span> is run, it goes through the file
   and recomputes the following parts of the file:
   </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
      the <code class="literal">/N</code>, <code class="literal">/W</code>, and
      <code class="literal">/First</code> keys of all object stream dictionaries
     </p></li><li class="listitem"><p>
      the pairs of numbers representing object numbers and offsets of
      objects in object streams
     </p></li><li class="listitem"><p>
      all stream lengths
     </p></li><li class="listitem"><p>
      the cross-reference table or cross-reference stream
     </p></li><li class="listitem"><p>
      the offset to the cross-reference table or cross-reference
      stream following the <code class="literal">startxref</code> token
     </p></li></ul></div><p>
  </p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.using-library"></a>Chapter 5. Using the QPDF Library</h1></div></div></div><p>
    The source tree for the qpdf package has an
    <code class="filename">examples</code> directory that contains a few
    example programs.  The <code class="filename">qpdf/qpdf.cc</code> source
    file also serves as a useful example since it exercises almost all
    of the qpdf library's public interface.  The best source of
    documentation on the library itself is reading comments in
    <code class="filename">include/qpdf/QPDF.hh</code>,
    <code class="filename">include/qpdf/QPDFWriter.hh</code>, and
    <code class="filename">include/qpdf/QPDFObjectHandle.hh</code>.
   </p><p>
    All header files are installed in the <code class="filename">include/qpdf</code> directory.  It
    is recommend that you use <code class="literal">#include
    &lt;qpdf/QPDF.hh&gt;</code> rather than adding
    <code class="filename">include/qpdf</code> to your include path.
   </p><p>
    When linking against the qpdf static library, you may also need to
    specify <code class="literal">-lz -ljpeg</code> on your link command. If
    your system understands how to read libtool
    <code class="filename">.la</code> files, this may not be necessary.
   </p><p>
    The qpdf library is safe to use in a multithreaded program, but no
    individual <span class="type">QPDF</span> object instance (including
    <span class="type">QPDF</span>, <span class="type">QPDFObjectHandle</span>, or
    <span class="type">QPDFWriter</span>) can be used in more than one thread at a
    time.  Multiple threads may simultaneously work with different
    instances of these and all other QPDF objects.
   </p></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.design"></a>Chapter 6. Design and Library Notes</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#ref.design.intro">6.1. Introduction</a></span></dt><dt><span class="sect1"><a href="#ref.design-goals">6.2. Design Goals</a></span></dt><dt><span class="sect1"><a href="#ref.casting">6.3. Casting Policy</a></span></dt><dt><span class="sect1"><a href="#ref.encryption">6.4. Encryption</a></span></dt><dt><span class="sect1"><a href="#ref.random-numbers">6.5. Random Number Generation</a></span></dt><dt><span class="sect1"><a href="#ref.adding-and-remove-pages">6.6. Adding and Removing Pages</a></span></dt><dt><span class="sect1"><a href="#ref.reserved-objects">6.7. Reserving Object Numbers</a></span></dt><dt><span class="sect1"><a href="#ref.foreign-objects">6.8. Copying Objects From Other PDF Files</a></span></dt><dt><span class="sect1"><a href="#ref.rewriting">6.9. Writing PDF Files</a></span></dt><dt><span class="sect1"><a href="#ref.filtered-streams">6.10. Filtered Streams</a></span></dt></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.design.intro"></a>6.1. Introduction</h2></div></div></div><p>
    This section was written prior to the implementation of the qpdf
    package and was subsequently modified to reflect the
    implementation.  In some cases, for purposes of explanation, it
    may differ slightly from the actual implementation.  As always,
    the source code and test suite are authoritative.  Even if there
    are some errors, this document should serve as a road map to
    understanding how this code works.
   </p><p>
    In general, one should adhere strictly to a specification when
    writing but be liberal in reading.  This way, the product of our
    software will be accepted by the widest range of other programs,
    and we will accept the widest range of input files.  This library
    attempts to conform to that philosophy whenever possible but also
    aims to provide strict checking for people who want to validate
    PDF files.  If you don't want to see warnings and are trying to
    write something that is tolerant, you can call
    <code class="literal">setSuppressWarnings(true)</code>.  If you want to fail
    on the first error, you can call
    <code class="literal">setAttemptRecovery(false)</code>.  The default
    behavior is to generating warnings for recoverable problems.  Note
    that recovery will not always produce the desired results even if
    it is able to get through the file.  Unlike most other PDF files
    that produce generic warnings such as “This file is
    damaged,”, qpdf generally issues a detailed error message
    that would be most useful to a PDF developer.  This is by design
    as there seems to be a shortage of PDF validation tools out
    there.  (This was, in fact, one of the major motivations behind
    the initial creation of qpdf.)
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.design-goals"></a>6.2. Design Goals</h2></div></div></div><p>
    The QPDF package includes support for reading and rewriting PDF
    files.  It aims to hide from the user details involving object
    locations, modified (appended) PDF files, the
    directness/indirectness of objects, and stream filters including
    encryption.  It does not aim to hide knowledge of the object
    hierarchy or content stream contents.  Put another way, a user of
    the qpdf library is expected to have knowledge about how PDF files
    work, but is not expected to have to keep track of bookkeeping
    details such as file positions.
   </p><p>
    A user of the library never has to care whether an object is
    direct or indirect.  All access to objects deals with this
    transparently.  All memory management details are also handled by
    the library.
   </p><p>
    The <code class="classname">PointerHolder</code> object is used internally
    by the library to deal with memory management.  This is basically
    a smart pointer object very similar in spirit to the Boost
    library's <code class="classname">shared_ptr</code> object, but predating
    it by several years.  This library also makes use of a technique
    for giving fine-grained access to methods in one class to other
    classes by using public subclasses with friends and only private
    members that in turn call private methods of the containing class.
    See <code class="classname">QPDFObjectHandle::Factory</code> as an
    example.
   </p><p>
    The top-level qpdf class is <code class="classname">QPDF</code>.  A
    <code class="classname">QPDF</code> object represents a PDF file.  The
    library provides methods for both accessing and mutating PDF
    files.
   </p><p>
    <code class="classname">QPDFObject</code> is the basic PDF Object class.
    It is an abstract base class from which are derived classes for
    each type of PDF object.  Clients do not interact with Objects
    directly but instead interact with
    <code class="classname">QPDFObjectHandle</code>.
   </p><p>
    <code class="classname">QPDFObjectHandle</code> contains
    <code class="classname">PointerHolder&lt;QPDFObject&gt;</code> and
    includes accessor methods that are type-safe proxies to the
    methods of the derived object classes as well as methods for
    querying object types.  They can be passed around by value,
    copied, stored in containers, etc. with very low overhead.
    Instances of <code class="classname">QPDFObjectHandle</code> always
    contain a reference back to the <code class="classname">QPDF</code> object
    from which they were created.  A
    <code class="classname">QPDFObjectHandle</code> may be direct or indirect.
    If indirect, the <code class="classname">QPDFObject</code> the
    <code class="classname">PointerHolder</code> initially points to is a null
    pointer.  In this case, the first attempt to access the underlying
    <code class="classname">QPDFObject</code> will result in the
    <code class="classname">QPDFObject</code> being resolved via a call to the
    referenced <code class="classname">QPDF</code> instance.  This makes it
    essentially impossible to make coding errors in which certain
    things will work for some PDF files and not for others based on
    which objects are direct and which objects are indirect.
   </p><p>
    Instances of <code class="classname">QPDFObjectHandle</code> can be
    directly created and modified using static factory methods in the
    <code class="classname">QPDFObjectHandle</code> class. There are factory
    methods for each type of object as well as a convenience method
    <code class="function">QPDFObjectHandle::parse</code> that creates an
    object from a string representation of the object.  Existing
    instances of <code class="classname">QPDFObjectHandle</code> can also be
    modified in several ways.  See comments in
    <code class="filename">QPDFObjectHandle.hh</code> for details.
   </p><p>
    When the <code class="classname">QPDF</code> class creates a new object,
    it dynamically allocates the appropriate type of
    <code class="classname">QPDFObject</code> and immediately hands the
    pointer to an instance of <code class="classname">QPDFObjectHandle</code>.
    The parser reads a token from the current file position.  If the
    token is a not either a dictionary or array opener, an object is
    immediately constructed from the single token and the parser
    returns.  Otherwise, the parser is invoked recursively in a
    special mode in which it accumulates objects until it finds a
    balancing closer.  During this process, the
    “<code class="literal">R</code>” keyword is recognized and an
    indirect <code class="classname">QPDFObjectHandle</code> may be
    constructed.
   </p><p>
    The <code class="function">QPDF::resolve()</code> method, which is used to
    resolve an indirect object, may be invoked from the
    <code class="classname">QPDFObjectHandle</code> class.  It first checks a
    cache to see whether this object has already been read.  If not,
    it reads the object from the PDF file and caches it.  It the
    returns the resulting <code class="classname">QPDFObjectHandle</code>.
    The calling object handle then replaces its
    <code class="classname">PointerHolder&lt;QDFObject&gt;</code> with the one
    from the newly returned <code class="classname">QPDFObjectHandle</code>.
    In this way, only a single copy of any direct object need exist
    and clients can access objects transparently without knowing
    caring whether they are direct or indirect objects.  Additionally,
    no object is ever read from the file more than once.  That means
    that only the portions of the PDF file that are actually needed
    are ever read from the input file, thus allowing the qpdf package
    to take advantage of this important design goal of PDF files.
   </p><p>
    If the requested object is inside of an object stream, the object
    stream itself is first read into memory.  Then the tokenizer reads
    objects from the memory stream based on the offset information
    stored in the stream.  Those individual objects are cached, after
    which the temporary buffer holding the object stream contents are
    discarded.  In this way, the first time an object in an object
    stream is requested, all objects in the stream are cached.
   </p><p>
    An instance of <code class="classname">QPDF</code> is constructed by using
    the class's default constructor.  If desired, the
    <code class="classname">QPDF</code> object may be configured with various
    methods that change its default behavior.  Then the
    <code class="function">QPDF::processFile()</code> method is passed the name
    of a PDF file, which permanently associates the file with that
    QPDF object.  A password may also be given for access to
    password-protected files.  QPDF does not enforce encryption
    parameters and will treat user and owner passwords equivalently.
    Either password may be used to access an encrypted file.
    <a href="#ftn.idm837" class="footnote" id="idm837"><sup class="footnote">[1]</sup></a>
    <code class="classname">QPDF</code> will allow recovery of a user password
    given an owner password.  The input PDF file must be seekable.
    (Output files written by <code class="classname">QPDFWriter</code> need
    not be seekable, even when creating linearized files.)  During
    construction, <code class="classname">QPDF</code> validates the PDF file's
    header, and then reads the cross reference tables and trailer
    dictionaries.  The <code class="classname">QPDF</code> class keeps only
    the first trailer dictionary though it does read all of them so it
    can check the <code class="literal">/Prev</code> key.
    <code class="classname">QPDF</code> class users may request the root
    object and the trailer dictionary specifically.  The cross
    reference table is kept private.  Objects may then be requested by
    number of by walking the object tree.
   </p><p>
    When a PDF file has a cross-reference stream instead of a
    cross-reference table and trailer, requesting the document's
    trailer dictionary returns the stream dictionary from the
    cross-reference stream instead.
   </p><p>
    There are some convenience routines for very common operations
    such as walking the page tree and returning a vector of all page
    objects.  For full details, please see the header file
    <code class="filename">QPDF.hh</code>.
   </p><p>
    The following example should clarify how
    <code class="classname">QPDF</code> processes a simple file.
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       Client constructs <code class="classname">QPDF</code>
       <code class="varname">pdf</code> and calls
       <code class="function">pdf.processFile("a.pdf");</code>.
      </p></li><li class="listitem"><p>
       The <code class="classname">QPDF</code> class checks the beginning of
       <code class="filename">a.pdf</code> for
       <code class="literal">%!PDF-1.[0-9]+</code>.  It then reads the cross
       reference table mentioned at the end of the file, ensuring that
       it is looking before the last <code class="literal">%%EOF</code>.  After
       getting to <code class="literal">trailer</code> keyword, it invokes the
       parser.
      </p></li><li class="listitem"><p>
       The parser sees “<code class="literal">&lt;&lt;</code>”, so
       it calls itself recursively in dictionary creation mode.
      </p></li><li class="listitem"><p>
       In dictionary creation mode, the parser keeps accumulating
       objects until it encounters
       “<code class="literal">&gt;&gt;</code>”.  Each object that is
       read is pushed onto a stack.  If
       “<code class="literal">R</code>” is read, the last two
       objects on the stack are inspected.  If they are integers, they
       are popped off the stack and their values are used to construct
       an indirect object handle which is then pushed onto the stack.
       When “<code class="literal">&gt;&gt;</code>” is finally read,
       the stack is converted into a
       <code class="classname">QPDF_Dictionary</code> which is placed in a
       <code class="classname">QPDFObjectHandle</code> and returned.
      </p></li><li class="listitem"><p>
       The resulting dictionary is saved as the trailer dictionary.
      </p></li><li class="listitem"><p>
       The <code class="literal">/Prev</code> key is searched.  If present,
       <code class="classname">QPDF</code> seeks to that point and repeats
       except that the new trailer dictionary is not saved.  If
       <code class="literal">/Prev</code> is not present, the initial parsing
       process is complete.
      </p><p>
       If there is an encryption dictionary, the document's encryption
       parameters are initialized.
      </p></li><li class="listitem"><p>
       The client requests root object.  The
       <code class="classname">QPDF</code> class gets the value of root key
       from trailer dictionary and returns it.  It is an unresolved
       indirect <code class="classname">QPDFObjectHandle</code>.
      </p></li><li class="listitem"><p>
       The client requests the <code class="literal">/Pages</code> key from root
       <code class="classname">QPDFObjectHandle</code>.  The
       <code class="classname">QPDFObjectHandle</code> notices that it is
       indirect so it asks <code class="classname">QPDF</code> to resolve it.
       <code class="classname">QPDF</code> looks in the object cache for an
       object with the root dictionary's object ID and generation
       number.  Upon not seeing it, it checks the cross reference
       table, gets the offset, and reads the object present at that
       offset.  It stores the result in the object cache and returns
       the cached result.  The calling
       <code class="classname">QPDFObjectHandle</code> replaces its object
       pointer with the one from the resolved
       <code class="classname">QPDFObjectHandle</code>, verifies that it a
       valid dictionary object, and returns the (unresolved indirect)
       <code class="classname">QPDFObject</code> handle to the top of the
       Pages hierarchy.
      </p><p>
       As the client continues to request objects, the same process is
       followed for each new requested object.
      </p></li></ul></div><p>
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.casting"></a>6.3. Casting Policy</h2></div></div></div><p>
    This section describes the casting policy followed by qpdf's
    implementation.  This is no concern to qpdf's end users and
    largely of no concern to people writing code that uses qpdf, but
    it could be of interest to people who are porting qpdf to a new
    platform or who are making modifications to the code.
   </p><p>
    The C++ code in qpdf is free of old-style casts except where
    unavoidable (e.g. where the old-style cast is in a macro provided
    by a third-party header file).  When there is a need for a cast,
    it is handled, in order of preference, by rewriting the code to
    avoid the need for a cast, calling
    <code class="function">const_cast</code>, calling
    <code class="function">static_cast</code>, calling
    <code class="function">reinterpret_cast</code>, or calling some combination
    of the above.  As a last resort, a compiler-specific
    <code class="literal">#pragma</code> may be used to suppress a warning that
    we don't want to fix.  Examples may include suppressing warnings
    about the use of old-style casts in code that is shared between C
    and C++ code.
   </p><p>
    The casting policy explicitly prohibits casting between integer
    sizes for no purpose other than to quiet a compiler warning when
    there is no reasonable chance of a problem resulting.  The reason
    for this exclusion is that the practice of adding these additional
    casts precludes future use of additional compiler warnings as a
    tool for making future improvements to this aspect of the code,
    and it also damages the readability of the code.
   </p><p>
    There are a few significant areas where casting is common in the
    qpdf sources or where casting would be required to quiet higher
    levels of compiler warnings but is omitted at present:
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       <span class="type">char</span> vs. <span class="type">unsigned char</span>.  For
       historical reasons, there are a lot of places in qpdf's
       internals that deal with <span class="type">unsigned char</span>, which
       means that a lot of casting is required to interoperate with
       standard library calls and <span class="type">std::string</span>.  In
       retrospect, qpdf should have probably used regular (signed)
       <span class="type">char</span> and <span class="type">char*</span> everywhere and just
       cast to <span class="type">unsigned char</span> when needed, but it's too
       late to make that change now.  There are
       <code class="function">reinterpret_cast</code> calls to go between
       <span class="type">char*</span> and <span class="type">unsigned char*</span>, and there
       are <code class="function">static_cast</code> calls to go between
       <span class="type">char</span> and <span class="type">unsigned char</span>.  These should
       always be safe.
      </p></li><li class="listitem"><p>
       Non-const <span class="type">unsigned char*</span> used in the
       <span class="type">Pipeline</span> interface.  The pipeline interface has a
       <code class="function">write</code> call that uses <span class="type">unsigned
       char*</span> without a <span class="type">const</span> qualifier.  The main
       reason for this is to support pipelines that make calls to
       third-party libraries, such as zlib, that don't include
       <span class="type">const</span> in their interfaces.  Unfortunately, there
       are many places in the code where it is desirable to have
       <span class="type">const char*</span> with pipelines.  None of the pipeline
       implementations in qpdf currently modify the data passed to
       write, and doing so would be counter to the intent of
       <span class="type">Pipeline</span>, but there is nothing in the code to
       prevent this from being done.  There are places in the code
       where <code class="function">const_cast</code> is used to remove the
       const-ness of pointers going into <span class="type">Pipeline</span>s.  This
       could theoretically be unsafe, but there is adequate testing to
       assert that it is safe and will remain safe in qpdf's code.
      </p></li><li class="listitem"><p>
       <span class="type">size_t</span> vs. <span class="type">qpdf_offset_t</span>.  This is
       pretty much unavoidable since sizes are unsigned types and
       offsets are signed types.  Whenever it is necessary to seek by
       an amount given by a <span class="type">size_t</span>, it becomes necessary
       to mix and match between <span class="type">size_t</span> and
       <span class="type">qpdf_offset_t</span>.  Additionally, qpdf sometimes
       treats memory buffers like files (as with
       <span class="type">BufferInputSource</span>, and those seek interfaces have
       to be consistent with file-based input sources.  Neither gcc
       nor MSVC give warnings for this case by default, but both have
       warning flags that can enable this.  (MSVC:
       <code class="option">/W14267</code> or <code class="option">/W3</code>, which also
       enables some additional warnings that we ignore; gcc:
       <code class="option">-Wconversion -Wsign-conversion</code>).  This could
       matter for files whose sizes are larger than
       2<sup>63</sup> bytes, but it is reasonable to
       expect that a world where such files are common would also have
       larger <span class="type">size_t</span> and <span class="type">qpdf_offset_t</span> types
       in it.  On most 64-bit systems at the time of this writing (the
       release of version 4.1.0 of qpdf), both <span class="type">size_t</span> and
       <span class="type">qpdf_offset_t</span> are 64-bit integer types, while on
       many current 32-bit systems, <span class="type">size_t</span> is a 32-bit
       type while <span class="type">qpdf_offset_t</span> is a 64-bit type.  I am
       not aware of any cases where 32-bit systems that have
       <span class="type">size_t</span> smaller than <span class="type">qpdf_offset_t</span>
       could run into problems.  Although I can't conclusively rule
       out the possibility of such problems existing, I suspect any
       cases would be pretty contrived.  In the event that someone
       should produce a file that qpdf can't handle because of what is
       suspected to be issues involving the handling of
       <span class="type">size_t</span> vs. <span class="type">qpdf_offset_t</span> (such files
       may behave properly on 64-bit systems but not on 32-bit systems
       because they have very large embedded files or streams, for
       example), the above mentioned warning flags could be enabled
       and all those implicit conversions could be carefully
       scrutinized.  (I have already gone through that exercise once
       in adding support for files larger than 4 GB in size.)  I
       continue to be committed to supporting large files on 32-bit
       systems, but I would not go to any lengths to support corner
       cases involving large embedded files or large streams that work
       on 64-bit systems but not on 32-bit systems because of
       <span class="type">size_t</span> being too small.  It is reasonable to
       assume that anyone working with such files would be using a
       64-bit system anyway since many 32-bit applications would have
       similar difficulties.
      </p></li><li class="listitem"><p>
       <span class="type">size_t</span> vs. <span class="type">int</span> or <span class="type">long</span>.
       There are some cases where <span class="type">size_t</span> and
       <span class="type">int</span> or <span class="type">long</span> or <span class="type">size_t</span>
       and <span class="type">unsigned int</span> or <span class="type">unsigned long</span> are
       used interchangeably.  These cases occur when working with very
       small amounts of memory, such as with the bit readers (where
       we're working with just a few bytes at a time), some cases of
       <code class="function">strlen</code>, and a few other cases.  I have
       scrutinized all of these cases and determined them to be safe,
       but there is no mechanism in the code to ensure that new unsafe
       conversions between <span class="type">int</span> and <span class="type">size_t</span>
       aren't introduced short of good testing and strong awareness of
       the issues.  Again, if any such bugs are suspected in the
       future, enabling the additional warning flags and scrutinizing
       the warnings would be in order.
      </p></li></ul></div><p>
   </p><p>
    To be clear, I believe qpdf to be well-behaved with respect to
    sizes and offsets, and qpdf's test suite includes actual
    generation and full processing of files larger than 4 GB in
    size.  The issues raised here are largely academic and should not
    in any way be interpreted to mean that qpdf has practical problems
    involving sloppiness with integer types.  I also believe that
    appropriate measures have been taken in the code to avoid problems
    with signed vs. unsigned integers from resulting in memory
    overwrites or other issues with potential security implications,
    though there are never any absolute guarantees.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.encryption"></a>6.4. Encryption</h2></div></div></div><p>
    Encryption is supported transparently by qpdf.  When opening a PDF
    file, if an encryption dictionary exists, the
    <code class="classname">QPDF</code> object processes this dictionary using
    the password (if any) provided.  The primary decryption key is
    computed and cached.  No further access is made to the encryption
    dictionary after that time.  When an object is read from a file,
    the object ID and generation of the object in which it is
    contained is always known.  Using this information along with the
    stored encryption key, all stream and string objects are
    transparently decrypted.  Raw encrypted objects are never stored
    in memory.  This way, nothing in the library ever has to know or
    care whether it is reading an encrypted file.
   </p><p>
    An interface is also provided for writing encrypted streams and
    strings given an encryption key.  This is used by
    <code class="classname">QPDFWriter</code> when it rewrites encrypted
    files.
   </p><p>
    When copying encrypted files, unless otherwise directed, qpdf will
    preserve any encryption in force in the original file.  qpdf can
    do this with either the user or the owner password.  There is no
    difference in capability based on which password is used.  When 40
    or 128 bit encryption keys are used, the user password can be
    recovered with the owner password.  With 256 keys, the user and
    owner passwords are used independently to encrypt the actual
    encryption key, so while either can be used, the owner password
    can no longer be used to recover the user password.
   </p><p>
    Starting with version 4.0.0, qpdf can read files that are not
    encrypted but that contain encrypted attachments, but it cannot
    write such files.  qpdf also requires the password to be specified
    in order to open the file, not just to extract attachments, since
    once the file is open, all decryption is handled transparently.
    When copying files like this while preserving encryption, qpdf
    will apply the file's encryption to everything in the file, not
    just to the attachments.  When decrypting the file, qpdf will
    decrypt the attachments.  In general, when copying PDF files with
    multiple encryption formats, qpdf will choose the newest format.
    The only exception to this is that clear-text metadata will be
    preserved as clear-text if it is that way in the original file.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.random-numbers"></a>6.5. Random Number Generation</h2></div></div></div><p>
    QPDF generates random numbers to support generation of encrypted
    data.  Versions prior to 5.0.1 used <code class="function">random</code> or
    <code class="function">rand</code> from <code class="filename">stdlib</code> to
    generate random numbers.  Version 5.0.1, if available, used
    operating system-provided secure random number generation instead,
    enabling use of <code class="filename">stdlib</code> random number
    generation only if enabled by a compile-time option.  Starting in
    version 5.1.0, use of insecure random numbers was disabled unless
    enabled at compile time.  Starting in version 5.1.0, it is also
    possible for you to disable use of OS-provided secure random
    numbers.  This is especially useful on Windows if you want to
    avoid a dependency on Microsoft's cryptography API.  In this case,
    you must provide your own random data provider.  Regardless of how
    you compile qpdf, starting in version 5.1.0, it is possible for
    you to provide your own random data provider at runtime.  This
    would enable you to use some software-based secure pseudorandom
    number generator and to avoid use of whatever the operating system
    provides.  For details on how to do this, please refer to the
    top-level README.md file in the source distribution and to comments
    in <code class="filename">QUtil.hh</code>.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.adding-and-remove-pages"></a>6.6. Adding and Removing Pages</h2></div></div></div><p>
    While qpdf's API has supported adding and modifying objects for
    some time, version 3.0 introduces specific methods for adding and
    removing pages.  These are largely convenience routines that
    handle two tricky issues: pushing inheritable resources from the
    <code class="literal">/Pages</code> tree down to individual pages and
    manipulation of the <code class="literal">/Pages</code> tree itself.  For
    details, see <code class="function">addPage</code> and surrounding methods
    in <code class="filename">QPDF.hh</code>.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.reserved-objects"></a>6.7. Reserving Object Numbers</h2></div></div></div><p>
    Version 3.0 of qpdf introduced the concept of reserved objects.
    These are seldom needed for ordinary operations, but there are
    cases in which you may want to add a series of indirect objects
    with references to each other to a <code class="classname">QPDF</code>
    object.  This causes a problem because you can't determine the
    object ID that a new indirect object will have until you add it to
    the <code class="classname">QPDF</code> object with
    <code class="function">QPDF::makeIndirectObject</code>.  The only way to
    add two mutually referential objects to a
    <code class="classname">QPDF</code> object prior to version 3.0 would be
    to add the new objects first and then make them refer to each
    other after adding them.  Now it is possible to create a
    <em class="firstterm">reserved object</em> using
    <code class="function">QPDFObjectHandle::newReserved</code>.  This is an
    indirect object that stays “unresolved” even if it is
    queried for its type.  So now, if you want to create a set of
    mutually referential objects, you can create reservations for each
    one of them and use those reservations to construct the
    references.  When finished, you can call
    <code class="function">QPDF::replaceReserved</code> to replace the reserved
    objects with the real ones.  This functionality will never be
    needed by most applications, but it is used internally by QPDF
    when copying objects from other PDF files, as discussed in <a class="xref" href="#ref.foreign-objects" title="6.8. Copying Objects From Other PDF Files">Section 6.8, “Copying Objects From Other PDF Files”</a>.  For an example of how to use
    reserved objects, search for <code class="function">newReserved</code> in
    <code class="filename">test_driver.cc</code> in qpdf's sources.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.foreign-objects"></a>6.8. Copying Objects From Other PDF Files</h2></div></div></div><p>
    Version 3.0 of qpdf introduced the ability to copy objects into a
    <code class="classname">QPDF</code> object from a different
    <code class="classname">QPDF</code> object, which we refer to as
    <em class="firstterm">foreign objects</em>. This allows arbitrary
    merging of PDF files. The “from”
    <code class="classname">QPDF</code> object must remain valid after the
    copy as discussed in the note below. The <span class="command"><strong>qpdf</strong></span>
    command-line tool provides limited support for basic page
    selection, including merging in pages from other files, but the
    library's API makes it possible to implement arbitrarily complex
    merging operations. The main method for copying foreign objects is
    <code class="function">QPDF::copyForeignObject</code>. This takes an
    indirect object from another <code class="classname">QPDF</code> and
    copies it recursively into this object while preserving all object
    structure, including circular references. This means you can add a
    direct object that you create from scratch to a
    <code class="classname">QPDF</code> object with
    <code class="function">QPDF::makeIndirectObject</code>, and you can add an
    indirect object from another file with
    <code class="function">QPDF::copyForeignObject</code>. The fact that
    <code class="function">QPDF::makeIndirectObject</code> does not
    automatically detect a foreign object and copy it is an explicit
    design decision. Copying a foreign object seems like a
    sufficiently significant thing to do that it should be done
    explicitly.
   </p><p>
    The other way to copy foreign objects is by passing a page from
    one <code class="classname">QPDF</code> to another by calling
    <code class="function">QPDF::addPage</code>.  In contrast to
    <code class="function">QPDF::makeIndirectObject</code>, this method
    automatically distinguishes between indirect objects in the
    current file, foreign objects, and direct objects.
   </p><p>
    Please note: when you copy objects from one
    <code class="classname">QPDF</code> to another, the source
    <code class="classname">QPDF</code> object must remain valid until you
    have finished with the destination object. This is because the
    original object is still used to retrieve any referenced stream
    data from the copied object.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.rewriting"></a>6.9. Writing PDF Files</h2></div></div></div><p>
    The qpdf library supports file writing of
    <code class="classname">QPDF</code> objects to PDF files through the
    <code class="classname">QPDFWriter</code> class.  The
    <code class="classname">QPDFWriter</code> class has two writing modes: one
    for non-linearized files, and one for linearized files.  See <a class="xref" href="#ref.linearization" title="Chapter 7. Linearization">Chapter 7, <em>Linearization</em></a> for a description of linearization
    is implemented.  This section describes how we write
    non-linearized files including the creation of QDF files (see
    <a class="xref" href="#ref.qdf" title="Chapter 4. QDF Mode">Chapter 4, <em>QDF Mode</em></a>.
   </p><p>
    This outline was written prior to implementation and is not
    exactly accurate, but it provides a correct “notional”
    idea of how writing works.  Look at the code in
    <code class="classname">QPDFWriter</code> for exact details.
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       Initialize state:
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          next object number = 1
         </p></li><li class="listitem"><p>
          object queue = empty
         </p></li><li class="listitem"><p>
          renumber table: old object id/generation to new id/0 = empty
         </p></li><li class="listitem"><p>
          xref table: new id -&gt; offset = empty
         </p></li></ul></div><p>
      </p></li><li class="listitem"><p>
       Create a QPDF object from a file.
      </p></li><li class="listitem"><p>
       Write header for new PDF file.
      </p></li><li class="listitem"><p>
       Request the trailer dictionary.
      </p></li><li class="listitem"><p>
       For each value that is an indirect object, grab the next object
       number (via an operation that returns and increments the
       number).  Map object to new number in renumber table.  Push
       object onto queue.
      </p></li><li class="listitem"><p>
       While there are more objects on the queue:
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          Pop queue.
         </p></li><li class="listitem"><p>
          Look up object's new number <span class="emphasis"><em>n</em></span> in the
          renumbering table.
         </p></li><li class="listitem"><p>
          Store current offset into xref table.
         </p></li><li class="listitem"><p>
          Write <code class="literal"><em class="replaceable"><code>n</code></em> 0 obj</code>.
         </p></li><li class="listitem"><p>
          If object is null, whether direct or indirect, write out
          null, thus eliminating unresolvable indirect object
          references.
         </p></li><li class="listitem"><p>
          If the object is a stream stream, write stream contents,
          piped through any filters as required, to a memory buffer.
          Use this buffer to determine the stream length.
         </p></li><li class="listitem"><p>
          If object is not a stream, array, or dictionary, write out
          its contents.
         </p></li><li class="listitem"><p>
          If object is an array or dictionary (including stream),
          traverse its elements (for array) or values (for
          dictionaries), handling recursive dictionaries and arrays,
          looking for indirect objects.  When an indirect object is
          found, if it is not resolvable, ignore.  (This case is
          handled when writing it out.)  Otherwise, look it up in the
          renumbering table.  If not found, grab the next available
          object number, assign to the referenced object in the
          renumbering table, and push the referenced object onto the
          queue.  As a special case, when writing out a stream
          dictionary, replace length, filters, and decode parameters
          as required.
         </p><p>
          Write out dictionary or array, replacing any unresolvable
          indirect object references with null (pdf spec says
          reference to non-existent object is legal and resolves to
          null) and any resolvable ones with references to the
          renumbered objects.
         </p></li><li class="listitem"><p>
          If the object is a stream, write
          <code class="literal">stream\n</code>, the stream contents (from the
          memory buffer), and <code class="literal">\nendstream\n</code>.
         </p></li><li class="listitem"><p>
          When done, write <code class="literal">endobj</code>.
         </p></li></ul></div><p>
      </p></li></ul></div><p>
   </p><p>
    Once we have finished the queue, all referenced objects will have
    been written out and all deleted objects or unreferenced objects
    will have been skipped.  The new cross-reference table will
    contain an offset for every new object number from 1 up to the
    number of objects written.  This can be used to write out a new
    xref table.  Finally we can write out the trailer dictionary with
    appropriately computed /ID (see spec, 8.3, File Identifiers), the
    cross reference table offset, and <code class="literal">%%EOF</code>.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.filtered-streams"></a>6.10. Filtered Streams</h2></div></div></div><p>
    Support for streams is implemented through the
    <code class="classname">Pipeline</code> interface which was designed for
    this package.
   </p><p>
    When reading streams, create a series of
    <code class="classname">Pipeline</code> objects.  The
    <code class="classname">Pipeline</code> abstract base requires
    implementation <code class="function">write()</code> and
    <code class="function">finish()</code> and provides an implementation of
    <code class="function">getNext()</code>.  Each pipeline object, upon
    receiving data, does whatever it is going to do and then writes
    the data (possibly modified) to its successor.  Alternatively, a
    pipeline may be an end-of-the-line pipeline that does something
    like store its output to a file or a memory buffer ignoring a
    successor.  For additional details, look at
    <code class="filename">Pipeline.hh</code>.
   </p><p>
    <code class="classname">QPDF</code> can read raw or filtered streams.
    When reading a filtered stream, the <code class="classname">QPDF</code>
    class creates a <code class="classname">Pipeline</code> object for one of
    each appropriate filter object and chains them together.  The last
    filter should write to whatever type of output is required.  The
    <code class="classname">QPDF</code> class has an interface to write raw or
    filtered stream contents to a given pipeline.
   </p></div><div class="footnotes"><br /><hr style="width:100; text-align:left;margin-left: 0" /><div id="ftn.idm837" class="footnote"><p><a href="#idm837" class="para"><sup class="para">[1] </sup></a>
      As pointed out earlier, the intention is not for qpdf to be used
      to bypass security on files. but as any open source PDF consumer
      may be easily modified to bypass basic PDF document security,
      and qpdf offers may transformations that can do this as well,
      there seems to be little point in the added complexity of
      conditionally enforcing document security.
     </p></div></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.linearization"></a>Chapter 7. Linearization</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#ref.linearization-strategy">7.1. Basic Strategy for Linearization</a></span></dt><dt><span class="sect1"><a href="#ref.linearized.preparation">7.2. Preparing For Linearization</a></span></dt><dt><span class="sect1"><a href="#ref.optimization">7.3. Optimization</a></span></dt><dt><span class="sect1"><a href="#ref.linearization.writing">7.4. Writing Linearized Files</a></span></dt><dt><span class="sect1"><a href="#ref.linearization-data">7.5. Calculating Linearization Data</a></span></dt><dt><span class="sect1"><a href="#ref.linearization-issues">7.6. Known Issues with Linearization</a></span></dt><dt><span class="sect1"><a href="#ref.linearization-debugging">7.7. Debugging Note</a></span></dt></dl></div><p>
   This chapter describes how <code class="classname">QPDF</code> and
   <code class="classname">QPDFWriter</code> implement creation and processing
   of linearized PDFS.
  </p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.linearization-strategy"></a>7.1. Basic Strategy for Linearization</h2></div></div></div><p>
    To avoid the incestuous problem of having the qpdf library
    validate its own linearized files, we have a special linearized
    file checking mode which can be invoked via <span class="command"><strong>qpdf
    --check-linearization</strong></span> (or <span class="command"><strong>qpdf
    --check</strong></span>).  This mode reads the linearization parameter
    dictionary and the hint streams and validates that object
    ordering, parameters, and hint stream contents are correct.  The
    validation code was first tested against linearized files created
    by external tools (Acrobat and pdlin) and then used to validate
    files created by <code class="classname">QPDFWriter</code> itself.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.linearized.preparation"></a>7.2. Preparing For Linearization</h2></div></div></div><p>
    Before creating a linearized PDF file from any other PDF file, the
    PDF file must be altered such that all page attributes are
    propagated down to the page level (and not inherited from parents
    in the <code class="literal">/Pages</code> tree).  We also have to know
    which objects refer to which other objects, being concerned with
    page boundaries and a few other cases.  We refer to this part of
    preparing the PDF file as <em class="firstterm">optimization</em>,
    discussed in <a class="xref" href="#ref.optimization" title="7.3. Optimization">Section 7.3, “Optimization”</a>.  Note the, in
    this context, the term <em class="firstterm">optimization</em> is a
    qpdf term, and the term <em class="firstterm">linearization</em> is a
    term from the PDF specification.  Do not be confused by the fact
    that many applications refer to linearization as optimization or
    web optimization.
   </p><p>
    When creating linearized PDF files from optimized PDF files, there
    are really only a few issues that need to be dealt with:
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       Creation of hints tables
      </p></li><li class="listitem"><p>
       Placing objects in the correct order
      </p></li><li class="listitem"><p>
       Filling in offsets and byte sizes
      </p></li></ul></div><p>
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.optimization"></a>7.3. Optimization</h2></div></div></div><p>
    In order to perform various operations such as linearization and
    splitting files into pages, it is necessary to know which objects
    are referenced by which pages, page thumbnails, and root and
    trailer dictionary keys.  It is also necessary to ensure that all
    page-level attributes appear directly at the page level and are
    not inherited from parents in the pages tree.
   </p><p>
    We refer to the process of enforcing these constraints as
    <em class="firstterm">optimization</em>.  As mentioned above, note
    that some applications refer to linearization as optimization.
    Although this optimization was initially motivated by the need to
    create linearized files, we are using these terms separately.
   </p><p>
    PDF file optimization is implemented in the
    <code class="filename">QPDF_optimization.cc</code> source file.  That file
    is richly commented and serves as the primary reference for the
    optimization process.
   </p><p>
    After optimization has been completed, the private member
    variables <code class="varname">obj_user_to_objects</code> and
    <code class="varname">object_to_obj_users</code> in
    <code class="classname">QPDF</code> have been populated.  Any object that
    has more than one value in the
    <code class="varname">object_to_obj_users</code> table is shared.  Any
    object that has exactly one value in the
    <code class="varname">object_to_obj_users</code> table is private.  To find
    all the private objects in a page or a trailer or root dictionary
    key, one merely has make this determination for each element in
    the <code class="varname">obj_user_to_objects</code> table for the given
    page or key.
   </p><p>
    Note that pages and thumbnails have different object user types,
    so the above test on a page will not include objects referenced by
    the page's thumbnail dictionary and nothing else.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.linearization.writing"></a>7.4. Writing Linearized Files</h2></div></div></div><p>
    We will create files with only primary hint streams.  We will
    never write overflow hint streams.  (As of PDF version 1.4,
    Acrobat doesn't either, and they are never necessary.)  The hint
    streams contain offset information to objects that point to where
    they would be if the hint stream were not present.  This means
    that we have to calculate all object positions before we can
    generate and write the hint table.  This means that we have to
    generate the file in two passes.  To make this reliable,
    <code class="classname">QPDFWriter</code> in linearization mode invokes
    exactly the same code twice to write the file to a pipeline.
   </p><p>
    In the first pass, the target pipeline is a count pipeline chained
    to a discard pipeline.  The count pipeline simply passes its data
    through to the next pipeline in the chain but can return the
    number of bytes passed through it at any intermediate point.  The
    discard pipeline is an end of line pipeline that just throws its
    data away.  The hint stream is not written and dummy values with
    adequate padding are stored in the first cross reference table,
    linearization parameter dictionary, and /Prev key of the first
    trailer dictionary.  All the offset, length, object renumbering
    information, and anything else we need for the second pass is
    stored.
   </p><p>
    At the end of the first pass, this information is passed to the
    <code class="classname">QPDF</code> class which constructs a compressed
    hint stream in a memory buffer and returns it.
    <code class="classname">QPDFWriter</code> uses this information to write a
    complete hint stream object into a memory buffer.  At this point,
    the length of the hint stream is known.
   </p><p>
    In the second pass, the end of the pipeline chain is a regular
    file instead of a discard pipeline, and we have known values for
    all the offsets and lengths that we didn't have in the first pass.
    We have to adjust offsets that appear after the start of the hint
    stream by the length of the hint stream, which is known.  Anything
    that is of variable length is padded, with the padding code
    surrounding any writing code that differs in the two passes.  This
    ensures that changes to the way things are represented never
    results in offsets that were gathered during the first pass
    becoming incorrect for the second pass.
   </p><p>
    Using this strategy, we can write linearized files to a
    non-seekable output stream with only a single pass to disk or
    wherever the output is going.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.linearization-data"></a>7.5. Calculating Linearization Data</h2></div></div></div><p>
    Once a file is optimized, we have information about which objects
    access which other objects.  We can then process these tables to
    decide which part (as described in “Linearized PDF Document
    Structure” in the PDF specification) each object is
    contained within.  This tells us the exact order in which objects
    are written.  The <code class="classname">QPDFWriter</code> class asks for
    this information and enqueues objects for writing in the proper
    order.  It also turns on a check that causes an exception to be
    thrown if an object is encountered that has not already been
    queued.  (This could happen only if there were a bug in the
    traversal code used to calculate the linearization data.)
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.linearization-issues"></a>7.6. Known Issues with Linearization</h2></div></div></div><p>
    There are a handful of known issues with this linearization code.
    These issues do not appear to impact the behavior of linearized
    files which still work as intended: it is possible for a web
    browser to begin to display them before they are fully
    downloaded.  In fact, it seems that various other programs that
    create linearized files have many of these same issues.  These
    items make reference to terminology used in the linearization
    appendix of the PDF specification.
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       Thread Dictionary information keys appear in part 4 with the
       rest of Threads instead of in part 9.  Objects in part 9 are
       not grouped together functionally.
      </p></li><li class="listitem"><p>
       We are not calculating numerators for shared object positions
       within content streams or interleaving them within content
       streams.
      </p></li><li class="listitem"><p>
       We generate only page offset, shared object, and outline hint
       tables.  It would be relatively easy to add some additional
       tables.  We gather most of the information needed to create
       thumbnail hint tables.  There are comments in the code about
       this.
      </p></li></ul></div><p>
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.linearization-debugging"></a>7.7. Debugging Note</h2></div></div></div><p>
    The <span class="command"><strong>qpdf --show-linearization</strong></span> command can show
    the complete contents of linearization hint streams.  To look at
    the raw data, you can extract the filtered contents of the
    linearization hint tables using <span class="command"><strong>qpdf --show-object=n
    --filtered-stream-data</strong></span>.  Then, to convert this into a
    bit stream (since linearization tables are bit streams written
    without regard to byte boundaries), you can pipe the resulting
    data through the following perl code:

    </p><pre class="programlisting">use bytes;
binmode STDIN;
undef $/;
my $a = &lt;STDIN&gt;;
my @ch = split(//, $a);
map { printf("%08b", ord($_)) } @ch;
print "\n";
</pre><p>
   </p></div></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a id="ref.object-and-xref-streams"></a>Chapter 8. Object and Cross-Reference Streams</h1></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#ref.object-streams">8.1. Object Streams</a></span></dt><dt><span class="sect1"><a href="#ref.xref-streams">8.2. Cross-Reference Streams</a></span></dt><dd><dl><dt><span class="sect2"><a href="#ref.xref-stream-data">8.2.1. Cross-Reference Stream Data</a></span></dt></dl></dd><dt><span class="sect1"><a href="#ref.object-streams-linearization">8.3. Implications for Linearized Files</a></span></dt><dt><span class="sect1"><a href="#ref.object-stream-implementation">8.4. Implementation Notes</a></span></dt></dl></div><p>
   This chapter provides information about the implementation of
   object stream and cross-reference stream support in qpdf.
  </p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.object-streams"></a>8.1. Object Streams</h2></div></div></div><p>
    Object streams can contain any regular object except the
    following:
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       stream objects
      </p></li><li class="listitem"><p>
       objects with generation &gt; 0
      </p></li><li class="listitem"><p>
       the encryption dictionary
      </p></li><li class="listitem"><p>
       objects containing the /Length of another stream
      </p></li></ul></div><p>
    In addition, Adobe reader (at least as of version 8.0.0) appears
    to not be able to handle having the document catalog appear in an
    object stream if the file is encrypted, though this is not
    specifically disallowed by the specification.
   </p><p>
    There are additional restrictions for linearized files.  See <a class="xref" href="#ref.object-streams-linearization" title="8.3. Implications for Linearized Files">Section 8.3, “Implications for Linearized Files”</a>for details.
   </p><p>
    The PDF specification refers to objects in object streams as
    “compressed objects” regardless of whether the object
    stream is compressed.
   </p><p>
    The generation number of every object in an object stream must be
    zero.  It is possible to delete and replace an object in an object
    stream with a regular object.
   </p><p>
    The object stream dictionary has the following keys:
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       <code class="literal">/N</code>: number of objects
      </p></li><li class="listitem"><p>
       <code class="literal">/First</code>: byte offset of first object
      </p></li><li class="listitem"><p>
       <code class="literal">/Extends</code>: indirect reference to stream that
       this extends
      </p></li></ul></div><p>
   </p><p>
    Stream collections are formed with <code class="literal">/Extends</code>.
    They must form a directed acyclic graph.  These can be used for
    semantic information and are not meaningful to the PDF document's
    syntactic structure.  Although qpdf preserves stream collections,
    it never generates them and doesn't make use of this information
    in any way.
   </p><p>
    The specification recommends limiting the number of objects in
    object stream for efficiency in reading and decoding.  Acrobat 6
    uses no more than 100 objects per object stream for linearized
    files and no more 200 objects per stream for non-linearized files.
    <code class="classname">QPDFWriter</code>, in object stream generation
    mode, never puts more than 100 objects in an object stream.
   </p><p>
    Object stream contents consists of <span class="emphasis"><em>N</em></span> pairs of
    integers, each of which is the object number and the byte offset
    of the object relative to the first object in the stream, followed
    by the objects themselves, concatenated.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.xref-streams"></a>8.2. Cross-Reference Streams</h2></div></div></div><p>
    For non-hybrid files, the value following
    <code class="literal">startxref</code> is the byte offset to the xref stream
    rather than the word <code class="literal">xref</code>.
   </p><p>
    For hybrid files (files containing both xref tables and
    cross-reference streams), the xref table's trailer dictionary
    contains the key <code class="literal">/XRefStm</code> whose value is the
    byte offset to a cross-reference stream that supplements the xref
    table.  A PDF 1.5-compliant application should read the xref table
    first.  Then it should replace any object that it has already seen
    with any defined in the xref stream.  Then it should follow any
    <code class="literal">/Prev</code> pointer in the original xref table's
    trailer dictionary.  The specification is not clear about what
    should be done, if anything, with a <code class="literal">/Prev</code>
    pointer in the xref stream referenced by an xref table.  The
    <code class="classname">QPDF</code> class ignores it, which is probably
    reasonable since, if this case were to appear for any sensible PDF
    file, the previous xref table would probably have a corresponding
    <code class="literal">/XRefStm</code> pointer of its own.  For example, if a
    hybrid file were appended, the appended section would have its own
    xref table and <code class="literal">/XRefStm</code>.  The appended xref
    table would point to the previous xref table which would point the
    <code class="literal">/XRefStm</code>, meaning that the new
    <code class="literal">/XRefStm</code> doesn't have to point to it.
   </p><p>
    Since xref streams must be read very early, they may not be
    encrypted, and the may not contain indirect objects for keys
    required to read them, which are these:
    </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
       <code class="literal">/Type</code>: value <code class="literal">/XRef</code>
      </p></li><li class="listitem"><p>
       <code class="literal">/Size</code>: value <span class="emphasis"><em>n+1</em></span>: where
       <span class="emphasis"><em>n</em></span> is highest object number (same as
       <code class="literal">/Size</code> in the trailer dictionary)
      </p></li><li class="listitem"><p>
       <code class="literal">/Index</code> (optional): value
       <code class="literal">[<em class="replaceable"><code>n count</code></em> ...]</code>
       used to determine which objects' information is stored in this
       stream.  The default is <code class="literal">[0 /Size]</code>.
      </p></li><li class="listitem"><p>
       <code class="literal">/Prev</code>: value
       <em class="replaceable"><code>offset</code></em>: byte offset of previous xref
       stream (same as <code class="literal">/Prev</code> in the trailer
       dictionary)
      </p></li><li class="listitem"><p>
       <code class="literal">/W [...]</code>: sizes of each field in the xref
       table
      </p></li></ul></div><p>
   </p><p>
    The other fields in the xref stream, which may be indirect if
    desired, are the union of those from the xref table's trailer
    dictionary.
   </p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="ref.xref-stream-data"></a>8.2.1. Cross-Reference Stream Data</h3></div></div></div><p>
     The stream data is binary and encoded in big-endian byte order.
     Entries are concatenated, and each entry has a length equal to
     the total of the entries in <code class="literal">/W</code> above.  Each
     entry consists of one or more fields, the first of which is the
     type of the field.  The number of bytes for each field is given
     by <code class="literal">/W</code> above.  A 0 in <code class="literal">/W</code>
     indicates that the field is omitted and has the default value.
     The default value for the field type is
     “<code class="literal">1</code>”.  All other default values are
     “<code class="literal">0</code>”.
    </p><p>
     PDF 1.5 has three field types:
     </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        0: for free objects.  Format: <code class="literal">0 obj
        next-generation</code>, same as the free table in a
        traditional cross-reference table
      </p></li><li class="listitem"><p>
       1: regular non-compressed object.  Format: <code class="literal">1 offset
       generation</code>
      </p></li><li class="listitem"><p>
       2: for objects in object streams.  Format: <code class="literal">2
       object-stream-number index</code>, the number of object
       stream containing the object and the index within the object
       stream of the object.
      </p></li></ul></div><p>
    </p><p>
     It seems standard to have the first entry in the table be
     <code class="literal">0 0 0</code> instead of <code class="literal">0 0 ffff</code>
     if there are no deleted objects.
    </p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.object-streams-linearization"></a>8.3. Implications for Linearized Files</h2></div></div></div><p>
    For linearized files, the linearization dictionary, document
    catalog, and page objects may not be contained in object streams.
   </p><p>
    Objects stored within object streams are given the highest range
    of object numbers within the main and first-page cross-reference
    sections.
   </p><p>
    It is okay to use cross-reference streams in place of regular xref
    tables.  There are on special considerations.
   </p><p>
    Hint data refers to object streams themselves, not the objects in
    the streams.  Shared object references should also be made to the
    object streams.  There are no reference in any hint tables to the
    object numbers of compressed objects (objects within object
    streams).
   </p><p>
    When numbering objects, all shared objects within both the first
    and second halves of the linearized files must be numbered
    consecutively after all normal uncompressed objects in that half.
   </p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ref.object-stream-implementation"></a>8.4. Implementation Notes</h2></div></div></div><p>
    There are three modes for writing object streams:
    <code class="option">disable</code>, <code class="option">preserve</code>, and
    <code class="option">generate</code>.  In disable mode, we do not generate
    any object streams, and we also generate an xref table rather than
    xref streams.  This can be used to generate PDF files that are
    viewable with older readers.  In preserve mode, we write object
    streams such that written object streams contain the same objects
    and <code class="literal">/Extends</code> relationships as in the original
    file.  This is equal to disable if the file has no object streams.
    In generate, we create object streams ourselves by grouping
    objects that are allowed in object streams together in sets of no
    more than 100 objects.  We also ensure that the PDF version is at
    least 1.5 in generate mode, but we preserve the version header in
    the other modes.  The default is <code class="option">preserve</code>.
   </p><p>
    We do not support creation of hybrid files.  When we write files,
    even in preserve mode, we will lose any xref tables and merge any
    appended sections.
   </p></div></div><div class="appendix"><div class="titlepage"><div><div><h1 class="title"><a id="ref.release-notes"></a>Appendix A. Release Notes</h1></div></div></div><p>
   For a detailed list of changes, please see the file
   <code class="filename">ChangeLog</code> in the source distribution.
  </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">8.0.2: March 6, 2018</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        When a loop is detected while following cross reference
        streams or tables, treat this as damage instead of silently
        ignoring the previous table. This prevents loss of otherwise
        recoverable data in some damaged files.
       </p></li></ul></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
         Properly handle pages with no contents.
       </p></li></ul></div></dd><dt><span class="term">8.0.1: March 4, 2018</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Disregard data check errors when uncompressing
        <code class="option">/FlateDecode</code> streams. This is consistent with
        most other PDF readers and allows qpdf to recover data from
        another class of malformed PDF files.
       </p></li><li class="listitem"><p>
        On the command line when specifying page ranges, support
        preceding a page number by “r” to indicate that it
        should be counted from the end. For example, the range
        <code class="literal">r3-r1</code> would indicate the last three pages
        of a document.
       </p></li></ul></div></dd><dt><span class="term">8.0.0: February 25, 2018</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Packaging and Distribution Changes
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          QPDF is now distributed as an <a class="ulink" href="https://appimage.org/" target="_top">AppImage</a> in addition to
          all the other ways it is distributed. The AppImage can be
          found in the download area with the other packages. Thanks
          to Kurt Pfeifle and Simon Peter for their contributions.
         </p></li></ul></div></li><li class="listitem"><p>
        Bug Fixes
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          <code class="function">QPDFObjectHandle::getUTF8Val</code> now
          properly treats non-Unicode strings as encoded with PDF Doc
          Encoding.
         </p></li><li class="listitem"><p>
          Improvements to handling of objects in PDF files that are
          not of the expected type. In most cases, qpdf will be able
          to warn for such cases rather than fail with an exception.
          Previous versions of qpdf would sometimes fail with errors
          such as “operation for dictionary object attempted on
          object of wrong type”. This situation should be mostly
          or entirely eliminated now.
         </p></li></ul></div></li><li class="listitem"><p>
        Enhancements to the <span class="command"><strong>qpdf</strong></span> Command-line Tool.
        All new options listed here are documented in more detail in
        <a class="xref" href="#ref.using" title="Chapter 3. Running QPDF">Chapter 3, <em>Running QPDF</em></a>.
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          The option
          <code class="option">--linearize-pass1=<em class="replaceable"><code>file</code></em></code>
          has been added for debugging qpdf's linearization code.
         </p></li><li class="listitem"><p>
          The option <code class="option">--coalesce-contents</code> can be used
          to combine content streams of a page whose contents are an
          array of streams into a single stream.
         </p></li></ul></div></li><li class="listitem"><p>
        API Enhancements. All new API calls are documented in their
        respective classes' header files. There are no non-compatible
        changes to the API.
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          Add function <code class="function">qpdf_check_pdf</code> to the C API.
          This function does basic checking that is a subset of what
          <span class="command"><strong>qpdf --check</strong></span> performs.
         </p></li><li class="listitem"><p>
          Major enhancements to the lexical layer of qpdf. For a
          complete list of enhancements, please refer to the
          <code class="filename">ChangeLog</code> file. Most of the changes
          result in improvements to qpdf's ability handle erroneous
          files. It is also possible for programs to handle
          whitespace, comments, and inline images as tokens.
         </p></li><li class="listitem"><p>
          New API for working with PDF content streams at a lexical
          level. The new class
          <code class="classname">QPDFObjectHandle::TokenFilter</code> allows
          the developer to provide token handlers. Token filters can be
          used with several different methods in
          <code class="classname">QPDFObjectHandle</code> as well as with a
          lower-level interface. See comments in
          <code class="filename">QPDFObjectHandle.hh</code> as well as the new
          examples <code class="filename">examples/pdf-filter-tokens.cc</code>
          and <code class="filename">examples/pdf-count-strings.cc</code> for
          details.
         </p></li></ul></div></li></ul></div></dd><dt><span class="term">7.1.1: February 4, 2018</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Bug fix: files whose /ID fields were other than 16 bytes long
        can now be properly linearized
       </p></li><li class="listitem"><p>
        A few compile and link issues have been corrected for some
        platforms.
       </p></li></ul></div></dd><dt><span class="term">7.1.0: January 14, 2018</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        PDF files contain streams that may be compressed with various
        compression algorithms which, in some cases, may be enhanced
        by various predictor functions. Previously only the PNG up
        predictor was supported. In this version, all the PNG
        predictors as well as the TIFF predictor are supported. This
        increases the range of files that qpdf is able to handle.
       </p></li><li class="listitem"><p>
        QPDF now allows a raw encryption key to be specified in place
        of a password when opening encrypted files, and will
        optionally display the encryption key used by a file. This is
        a non-standard operation, but it can be useful in certain
        situations. Please see the discussion of
        <code class="option">--password-is-hex-key</code> in <a class="xref" href="#ref.basic-options" title="3.2. Basic Options">Section 3.2, “Basic Options”</a> or the comments around
        <code class="function">QPDF::setPasswordIsHexKey</code> in
        <code class="filename">QPDF.hh</code> for additional details.
       </p></li><li class="listitem"><p>
        Bug fix: numbers ending with a trailing decimal point are now
        properly recognized as numbers.
       </p></li><li class="listitem"><p>
        Bug fix: when building qpdf from source on some platforms
        (especially MacOS), the build could get confused by older
        versions of qpdf installed on the system. This has been
        corrected.
       </p></li></ul></div></dd><dt><span class="term">7.0.0: September 15, 2017</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Packaging and Distribution Changes
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          QPDF's primary license is now <a class="ulink" href="http://www.apache.org/licenses/LICENSE-2.0" target="_top">version 2.0
          of the Apache License</a> rather than version 2.0 of the
          Artistic License. You may still, at your option, consider
          qpdf to be licensed with version 2.0 of the Artistic
          license.
         </p></li><li class="listitem"><p>
          QPDF no longer has a dependency on the PCRE (Perl-Compatible
          Regular Expression) library. QPDF now has an added
          dependency on the JPEG library.
         </p></li></ul></div></li></ul></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Bug Fixes
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          This release contains many bug fixes for various infinite
          loops, memory leaks, and other memory errors that could be
          encountered with specially crafted or otherwise erroneous
          PDF files.
         </p></li></ul></div></li></ul></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        New Features
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          QPDF now supports reading and writing streams encoded with
          JPEG or RunLength encoding. Library API enhancements and
          command-line options have been added to control this
          behavior. See command-line options
          <code class="option">--compress-streams</code> and
          <code class="option">--decode-level</code> and methods
          <code class="function">QPDFWriter::setCompressStreams</code> and
          <code class="function">QPDFWriter::setDecodeLevel</code>.
         </p></li><li class="listitem"><p>
          QPDF is much better at recovering from broken files. In most
          cases, qpdf will skip invalid objects and will preserve
          broken stream data by not attempting to filter broken
          streams. QPDF is now able to recover or at least not crash
          on dozens of broken test files I have received over the past
          few years.
         </p></li><li class="listitem"><p>
          Page rotation is now supported and accessible from both the
          library and the command line.
         </p></li><li class="listitem"><p>
          <code class="classname">QPDFWriter</code> supports writing files in
          a way that preserves PCLm compliance in support of
          driverless printing. This is very specialized and is only
          useful to applications that already know how to create PCLm
          files.
         </p></li></ul></div></li></ul></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Enhancements to the <span class="command"><strong>qpdf</strong></span> Command-line Tool.
        All new options listed here are documented in more detail in
        <a class="xref" href="#ref.using" title="Chapter 3. Running QPDF">Chapter 3, <em>Running QPDF</em></a>.
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          Command-line arguments can now be read from files or
          standard input using <code class="literal">@file</code> or
          <code class="literal">@-</code> syntax. Please see <a class="xref" href="#ref.invocation" title="3.1. Basic Invocation">Section 3.1, “Basic Invocation”</a>.
         </p></li><li class="listitem"><p>
          <code class="option">--rotate</code>: request page rotation
         </p></li><li class="listitem"><p>
          <code class="option">--newline-before-endstream</code>: ensure that a
          newline appears before every <code class="literal">endstream</code>
          keyword in the file; used to prevent qpdf from breaking
          PDF/A compliance on already compliant files.
         </p></li><li class="listitem"><p>
          <code class="option">--preserve-unreferenced</code>: preserve
          unreferenced objects in the input PDF
         </p></li><li class="listitem"><p>
	  <code class="option">--split-pages</code>: break output into chunks
          with fixed numbers of pages
         </p></li><li class="listitem"><p>
	  <code class="option">--verbose</code>: print the name of each output
          file that is created
         </p></li><li class="listitem"><p>
          <code class="option">--compress-streams</code> and
          <code class="option">--decode-level</code> replace
          <code class="option">--stream-data</code> for improving granularity of
          controlling compression and decompression of stream data.
          The <code class="option">--stream-data</code> option will remain
          available.
         </p></li><li class="listitem"><p>
          When running <span class="command"><strong>qpdf --check</strong></span> with other
          options, checks are always run first. This enables qpdf to
          perform its full recovery logic before outputting other
          information. This can be especially useful when manually
          recovering broken files, looking at qpdf's regenerated cross
          reference table, or other similar operations.
         </p></li><li class="listitem"><p>
          Process <span class="command"><strong>--pages</strong></span> earlier so that other
          options like <code class="option">--show-pages</code> or
          <code class="option">--split-pages</code> can operate on the file after
          page splitting/merging has occurred.
         </p></li></ul></div></li></ul></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        API Changes. All new API calls are documented in their
        respective classes' header files.
       </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
          <code class="function">QPDFObjectHandle::rotatePage</code>: apply
          rotation to a page object
         </p></li><li class="listitem"><p>
          <code class="function">QPDFWriter::setNewlineBeforeEndstream</code>:
          force newline to appear before <code class="literal">endstream</code>
         </p></li><li class="listitem"><p>
          <code class="function">QPDFWriter::setPreserveUnreferencedObjects</code>:
          preserve unreferenced objects that appear in the input PDF.
          The default behavior is to discard them.
         </p></li><li class="listitem"><p>
          New <code class="classname">Pipeline</code> types
          <code class="classname">Pl_RunLength</code> and
          <code class="classname">Pl_DCT</code> are available for developers
          who wish to produce or consume RunLength or DCT stream data
          directly. The <code class="filename">examples/pdf-create.cc</code>
          example illustrates their use.
         </p></li><li class="listitem"><p>
	  <code class="function">QPDFWriter::setCompressStreams</code> and
	  <code class="function">QPDFWriter::setDecodeLevel</code> methods
	  control handling of different types of stream compression.
         </p></li><li class="listitem"><p>
	  Add new C API functions
	  <code class="function">qpdf_set_compress_streams</code>,
	  <code class="function">qpdf_set_decode_level</code>,
	  <code class="function">qpdf_set_preserve_unreferenced_objects</code>,
	  and <code class="function">qpdf_set_newline_before_endstream</code>
	  corresponding to the new <code class="classname">QPDFWriter</code>
	  methods.
         </p></li></ul></div></li></ul></div></dd></dl></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">6.0.0: November 10, 2015</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Implement <code class="option">--deterministic-id</code> command-line
        option and <code class="function">QPDFWriter::setDeterministicID</code>
        as well as C API function
        <code class="function">qpdf_set_deterministic_ID</code> for generating
        a deterministic ID for non-encrypted files. When this option
        is selected, the ID of the file depends on the contents of the
        output file, and not on transient items such as the timestamp
        or output file name.
       </p></li><li class="listitem"><p>
        Make qpdf more tolerant of files whose xref table entries are
        not the correct length.
       </p></li></ul></div></dd><dt><span class="term">5.1.3: May 24, 2015</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Bug fix: fix-qdf was not properly handling files that
        contained object streams with more than 255 objects in them.
       </p></li><li class="listitem"><p>
        Bug fix: qpdf was not properly initializing Microsoft's secure
        crypto provider on fresh Windows installations that had not
        had any keys created yet.
       </p></li><li class="listitem"><p>
        Fix a few errors found by Gynvael Coldwind and
	Mateusz Jurczyk of the Google Security Team. Please see the
        ChangeLog for details.
       </p></li><li class="listitem"><p>
        Properly handle pages that have no contents at all. There were
        many cases in which qpdf handled this fine, but a few methods
        blindly obtained page contents with handling the possibility
        that there were no contents.
       </p></li><li class="listitem"><p>
        Make qpdf more robust for a few more kinds of problems that
        may occur in invalid PDF files.
       </p></li></ul></div></dd><dt><span class="term">5.1.2: June 7, 2014</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Bug fix: linearizing files could create a corrupted output
        file under extremely unlikely file size circumstances. See
        ChangeLog for details. The odds of getting hit by this are
        very low, though one person did.
       </p></li><li class="listitem"><p>
        Bug fix: qpdf would fail to write files that had streams with
        decode parameters referencing other streams.
       </p></li><li class="listitem"><p>
        New example program: <span class="command"><strong>pdf-split-pages</strong></span>:
        efficiently split PDF files into individual pages. The example
        program does this more efficiently than using <span class="command"><strong>qpdf
        --pages</strong></span> to do it.
       </p></li><li class="listitem"><p>
        Packaging fix: Visual C++ binaries did not support Windows XP.
        This has been rectified by updating the compilers used to
        generate the release binaries.
       </p></li></ul></div></dd><dt><span class="term">5.1.1: January 14, 2014</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Performance fix: copying foreign objects could be very slow
        with certain types of files.  This was most likely to be
        visible during page splitting and was due to traversing the
        same objects multiple times in some cases.
       </p></li></ul></div></dd><dt><span class="term">5.1.0: December 17, 2013</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Added runtime option
        (<code class="function">QUtil::setRandomDataProvider</code>) to supply
        your own random data provider.  You can use this if you want
        to avoid using the OS-provided secure random number generation
        facility or stdlib's less secure version.  See comments in
        include/qpdf/QUtil.hh for details.
       </p></li><li class="listitem"><p>
        Fixed image comparison tests to not create 12-bit-per-pixel
        images since some versions of tiffcmp have bugs in comparing
        them in some cases.  This increases the disk space required by
        the image comparison tests, which are off by default anyway.
       </p></li><li class="listitem"><p>
        Introduce a number of small fixes for compilation on the
        latest clang in MacOS and the latest Visual C++ in Windows.
       </p></li><li class="listitem"><p>
        Be able to handle broken files that end the xref table header
        with a space instead of a newline.
       </p></li></ul></div></dd><dt><span class="term">5.0.1: October 18, 2013</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Thanks to a detailed review by Florian Weimer and the Red Hat
        Product Security Team, this release includes a number of
        non-user-visible security hardening changes.  Please see the
        ChangeLog file in the source distribution for the complete
        list.
       </p></li><li class="listitem"><p>
        When available, operating system-specific secure random number
        generation is used for generating initialization vectors and
        other random values used during encryption or file creation.
        For the Windows build, this results in an added dependency on
        Microsoft's cryptography API.  To disable the OS-specific
        cryptography and use the old version, pass the
        <code class="option">--enable-insecure-random</code> option to
        <span class="command"><strong>./configure</strong></span>.
       </p></li><li class="listitem"><p>
        The <span class="command"><strong>qpdf</strong></span> command-line tool now issues a
        warning when <code class="option">-accessibility=n</code> is specified
        for newer encryption versions stating that the option is
        ignored.  qpdf, per the spec, has always ignored this flag,
        but it previously did so silently.  This warning is issued
        only by the command-line tool, not by the library.  The
        library's handling of this flag is unchanged.
       </p></li></ul></div></dd><dt><span class="term">5.0.0: July 10, 2013</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Bug fix: previous versions of qpdf would lose objects with
        generation != 0 when generating object streams.  Fixing this
        required changes to the public API.
       </p></li><li class="listitem"><p>
        Removed methods from public API that were only supposed to be
        called by QPDFWriter and couldn't realistically be called
        anywhere else.  See ChangeLog for details.
       </p></li><li class="listitem"><p>
        New <span class="type">QPDFObjGen</span> class added to represent an object
        ID/generation pair.
        <code class="function">QPDFObjectHandle::getObjGen()</code> is now
        preferred over
        <code class="function">QPDFObjectHandle::getObjectID()</code> and
        <code class="function">QPDFObjectHandle::getGeneration()</code> as it
        makes it less likely for people to accidentally write code
        that ignores the generation number.  See
        <code class="filename">QPDF.hh</code> and
        <code class="filename">QPDFObjectHandle.hh</code> for additional notes.
       </p></li><li class="listitem"><p>
        Add <code class="option">--show-npages</code> command-line option to the
        <span class="command"><strong>qpdf</strong></span> command to show the number of pages in
        a file.
       </p></li><li class="listitem"><p>
        Allow omission of the page range within
        <code class="option">--pages</code> for the <span class="command"><strong>qpdf</strong></span>
        command.  When omitted, the page range is implicitly taken to
        be all the pages in the file.
       </p></li><li class="listitem"><p>
        Various enhancements were made to support different types of
        broken files or broken readers.  Details can be found in
        <code class="filename">ChangeLog</code>.
       </p></li></ul></div></dd><dt><span class="term">4.1.0: April 14, 2013</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Note to people including qpdf in distributions: the
        <code class="filename">.la</code> files generated by libtool are now
        installed by qpdf's <span class="command"><strong>make install</strong></span> target.
        Before, they were not installed.  This means that if your
        distribution does not want to include <code class="filename">.la</code>
        files, you must remove them as part of your packaging process.
       </p></li><li class="listitem"><p>
        Major enhancement: API enhancements have been made to support
        parsing of content streams.  This enhancement includes the
        following changes:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
           <code class="function">QPDFObjectHandle::parseContentStream</code>
           method parses objects in a content stream and calls
           handlers in a callback class.  The example
           <code class="filename">examples/pdf-parse-content.cc</code>
           illustrates how this may be used.
          </p></li><li class="listitem"><p>
           <span class="type">QPDFObjectHandle</span> can now represent operators
           and inline images, object types that may only appear in
           content streams.
          </p></li><li class="listitem"><p>
           Method <code class="function">QPDFObjectHandle::getTypeCode()</code>
           returns an enumerated type value representing the
           underlying object type.  Method
           <code class="function">QPDFObjectHandle::getTypeName()</code>
           returns a text string describing the name of the type of a
           <span class="type">QPDFObjectHandle</span> object.  These methods can be
           used for more efficient parsing and debugging/diagnostic
           messages.
          </p></li></ul></div><p>
       </p></li><li class="listitem"><p>
        <span class="command"><strong>qpdf --check</strong></span> now parses all pages' content
        streams in addition to doing other checks.  While there are
        still many types of errors that cannot be detected, syntactic
        errors in content streams will now be reported.
       </p></li><li class="listitem"><p>
        Minor compilation enhancements have been made to facilitate
        easier for support for a broader range of compilers and
        compiler versions.
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
           Warning flags have been moved into a separate variable in
           <code class="filename">autoconf.mk</code>
          </p></li><li class="listitem"><p>
           The configure flag <code class="option">--enable-werror</code> work
           for Microsoft compilers
          </p></li><li class="listitem"><p>
           All MSVC CRT security warnings have been resolved.
          </p></li><li class="listitem"><p>
           All C-style casts in C++ Code have been replaced by C++
           casts, and many casts that had been included to suppress
           higher warning levels for some compilers have been removed,
           primarily for clarity.  Places where integer type coercion
           occurs have been scrutinized.  A new casting policy has
           been documented in the manual.  This is of concern mainly
           to people porting qpdf to new platforms or compilers.  It
           is not visible to programmers writing code that uses the
           library
          </p></li><li class="listitem"><p>
           Some internal limits have been removed in code that
           converts numbers to strings.  This is largely invisible to
           users, but it does trigger a bug in some older versions of
           mingw-w64's C++ library.  See
           <code class="filename">README-windows.md</code> in the source
           distribution if you think this may affect you.  The copy of
           the DLL distributed with qpdf's binary distribution is not
           affected by this problem.
          </p></li></ul></div><p>
       </p></li><li class="listitem"><p>
        The RPM spec file previously included with qpdf has been
        removed.  This is because virtually all Linux distributions
        include qpdf now that it is a dependency of CUPS filters.
       </p></li><li class="listitem"><p>
        A few bug fixes are included:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
           Overridden compressed objects are properly handled.
           Before, there were certain constructs that could cause qpdf
           to see old versions of some objects.  The most usual
           manifestation of this was loss of filled in form values for
           certain files.
          </p></li><li class="listitem"><p>
           Installation no longer uses GNU/Linux-specific versions of
           some commands, so <span class="command"><strong>make install</strong></span> works on
           Solaris with native tools.
          </p></li><li class="listitem"><p>
           The 64-bit mingw Windows binary package no longer includes
           a 32-bit DLL.
          </p></li></ul></div><p>
       </p></li></ul></div></dd><dt><span class="term">4.0.1: January 17, 2013</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Fix detection of binary attachments in test suite to avoid
        false test failures on some platforms.
       </p></li><li class="listitem"><p>
        Add clarifying comment in <code class="filename">QPDF.hh</code> to
        methods that return the user password explaining that it is no
        longer possible with newer encryption formats to recover the
        user password knowing the owner password.  In earlier
        encryption formats, the user password was encrypted in the
        file using the owner password.  In newer encryption formats, a
        separate encryption key is used on the file, and that key is
        independently encrypted using both the user password and the
        owner password.
       </p></li></ul></div></dd><dt><span class="term">4.0.0: December 31, 2012</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Major enhancement: support has been added for newer encryption
        schemes supported by version X of Adobe Acrobat.  This
        includes use of 127-character passwords, 256-bit encryption
        keys, and the encryption scheme specified in ISO 32000-2, the
        PDF 2.0 specification.  This scheme can be chosen from the
        command line by specifying use of 256-bit keys.  qpdf also
        supports the deprecated encryption method used by Acrobat IX.
        This encryption style has known security weaknesses and should
        not be used in practice.  However, such files exist “in
        the wild,” so support for this scheme is still useful.
        New methods
        <code class="function">QPDFWriter::setR6EncryptionParameters</code>
        (for the PDF 2.0 scheme) and
        <code class="function">QPDFWriter::setR5EncryptionParameters</code>
        (for the deprecated scheme) have been added to enable these
        new encryption schemes.  Corresponding functions have been
        added to the C API as well.
       </p></li><li class="listitem"><p>
        Full support for Adobe extension levels in PDF version
        information.  Starting with PDF version 1.7, corresponding to
        ISO 32000, Adobe adds new functionality by increasing the
        extension level rather than increasing the version.  This
        support includes addition of the
        <code class="function">QPDF::getExtensionLevel</code> method for
        retrieving the document's extension level, addition of
        versions of
        <code class="function">QPDFWriter::setMinimumPDFVersion</code> and
        <code class="function">QPDFWriter::forcePDFVersion</code> that accept
        an extension level, and extended syntax for specifying forced
        and minimum versions on the command line as described in <a class="xref" href="#ref.advanced-transformation" title="3.6. Advanced Transformation Options">Section 3.6, “Advanced Transformation Options”</a>.  Corresponding
        functions have been added to the C API as well.
       </p></li><li class="listitem"><p>
        Minor fixes to prevent qpdf from referencing objects in the
        file that are not referenced in the file's overall structure.
        Most files don't have any such objects, but some files have
        contain unreferenced objects with errors, so these fixes
        prevent qpdf from needlessly rejecting or complaining about
        such objects.
       </p></li><li class="listitem"><p>
        Add new generalized methods for reading and writing files
        from/to programmer-defined sources.  The method
        <code class="function">QPDF::processInputSource</code> allows the
        programmer to use any input source for the input file, and
        <code class="function">QPDFWriter::setOutputPipeline</code> allows the
        programmer to write the output file through any pipeline.
        These methods would make it possible to perform any number of
        specialized operations, such as accessing external storage
        systems, creating bindings for qpdf in other programming
        languages that have their own I/O systems, etc.
       </p></li><li class="listitem"><p>
        Add new method <code class="function">QPDF::getEncryptionKey</code> for
        retrieving the underlying encryption key used in the file.
       </p></li><li class="listitem"><p>
        This release includes a small handful of non-compatible API
        changes.  While effort is made to avoid such changes, all the
        non-compatible API changes in this version were to parts of
        the API that would likely never be used outside the library
        itself.  In all cases, the altered methods or structures were
        parts of the <code class="classname">QPDF</code> that were public to
        enable them to be called from either
        <code class="classname">QPDFWriter</code> or were part of validation
        code that was over-zealous in reporting problems in parts of
        the file that would not ordinarily be referenced.  In no case
        did any of the removed methods do anything worse that falsely
        report error conditions in files that were broken in ways that
        didn't matter.  The following public parts of the
        <code class="classname">QPDF</code> class were changed in a
        non-compatible way:
        </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
           Updated nested <code class="classname">QPDF::EncryptionData</code>
           class to add fields needed by the newer encryption formats,
           member variables changed to private so that future changes
           will not require breaking backward compatibility.
          </p></li><li class="listitem"><p>
           Added additional parameters to
           <code class="function">compute_data_key</code>, which is used by
           <code class="classname">QPDFWriter</code> to compute the encryption
           key used to encrypt a specific object.
          </p></li><li class="listitem"><p>
           Removed the method
           <code class="function">flattenScalarReferences</code>.  This method
           was previously used prior to writing a new PDF file, but it
           has the undesired side effect of causing qpdf to read
           objects in the file that were not referenced.  Some
           otherwise files have unreferenced objects with errors in
           them, so this could cause qpdf to reject files that would
           be accepted by virtually all other PDF readers.  In fact,
           qpdf relied on only a very small part of what
           flattenScalarReferences did, so only this part has been
           preserved, and it is now done directly inside
           <code class="classname">QPDFWriter</code>.
          </p></li><li class="listitem"><p>
           Removed the method <code class="function">decodeStreams</code>.
           This method was used by the <code class="option">--check</code> option
           of the <span class="command"><strong>qpdf</strong></span> command-line tool to force
           all streams in the file to be decoded, but it also suffered
           from the problem of opening otherwise unreferenced streams
           and thus could report false positive.  The
           <code class="option">--check</code> option now causes qpdf to go
           through all the motions of writing a new file based on the
           original one, so it will always reference and check exactly
           those parts of a file that any ordinary viewer would check.
          </p></li><li class="listitem"><p>
           Removed the method
           <code class="function">trimTrailerForWrite</code>.  This method was
           used by <code class="classname">QPDFWriter</code> to modify the
           original QPDF object by removing fields from the trailer
           dictionary that wouldn't apply to the newly written file.
           This functionality, though generally harmless, was a poor
           implementation and has been replaced by having QPDFWriter
           filter these out when copying the trailer rather than
           modifying the original QPDF object.  (Note that qpdf never
           modifies the original file itself.)
          </p></li></ul></div><p>
       </p></li><li class="listitem"><p>
        Allow the PDF header to appear anywhere in the first 1024
        bytes of the file.  This is consistent with what other readers
        do.
       </p></li><li class="listitem"><p>
        Fix the <span class="command"><strong>pkg-config</strong></span> files to list zlib and
        pcre in <code class="function">Requires.private</code> to better
        support static linking using <span class="command"><strong>pkg-config</strong></span>.
       </p></li></ul></div></dd><dt><span class="term">3.0.2: September 6, 2012</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Bug fix: <code class="function">QPDFWriter::setOutputMemory</code> did
        not work when not used with
        <code class="function">QPDFWriter::setStaticID</code>, which made it
        pretty much useless.  This has been fixed.
       </p></li><li class="listitem"><p>
        New API call
        <code class="function">QPDFWriter::setExtraHeaderText</code> inserts
        additional text near the header of the PDF file.  The intended
        use case is to insert comments that may be consumed by a
        downstream application, though other use cases may exist.
       </p></li></ul></div></dd><dt><span class="term">3.0.1: August 11, 2012</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Version 3.0.0 included addition of files for
        <span class="command"><strong>pkg-config</strong></span>, but this was not mentioned in
        the release notes.  The release notes for 3.0.0 were updated
        to mention this.
       </p></li><li class="listitem"><p>
        Bug fix: if an object stream ended with a scalar object not
        followed by space, qpdf would incorrectly report that it
        encountered a premature EOF.  This bug has been in qpdf since
        version 2.0.
       </p></li></ul></div></dd><dt><span class="term">3.0.0: August 2, 2012</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Acknowledgment: I would like to express gratitude for the
        contributions of Tobias Hoffmann toward the release of qpdf
        version 3.0.  He is responsible for most of the implementation
        and design of the new API for manipulating pages, and
        contributed code and ideas for many of the improvements made
        in version 3.0.  Without his work, this release would
        certainly not have happened as soon as it did, if at all.
       </p></li><li class="listitem"><p>
        <span class="emphasis"><em>Non-compatible API change:</em></span> The version of
        <code class="function">QPDFObjectHandle::replaceStreamData</code> that
        uses a <code class="classname">StreamDataProvider</code> no longer
        requires (or accepts) a <code class="varname">length</code> parameter.
        See <a class="xref" href="#ref.upgrading-to-3.0" title="Appendix C. Upgrading to 3.0">Appendix C, <em>Upgrading to 3.0</em></a> for an explanation.
        While care is taken to avoid non-compatible API changes in
        general, an exception was made this time because the new
        interface offers an opportunity to significantly simplify
        calling code.
       </p></li><li class="listitem"><p>
        Support has been added for large files.  The test suite
        verifies support for files larger than 4 gigabytes, and manual
        testing has verified support for files larger than 10
        gigabytes.  Large file support is available for both 32-bit
        and 64-bit platforms as long as the compiler and underlying
        platforms support it.
       </p></li><li class="listitem"><p>
        Support for page selection (splitting and merging PDF files)
        has been added to the <span class="command"><strong>qpdf</strong></span> command-line
        tool.  See <a class="xref" href="#ref.page-selection" title="3.4. Page Selection Options">Section 3.4, “Page Selection Options”</a>.
       </p></li><li class="listitem"><p>
        Options have been added to the <span class="command"><strong>qpdf</strong></span>
        command-line tool for copying encryption parameters from
        another file.  See <a class="xref" href="#ref.basic-options" title="3.2. Basic Options">Section 3.2, “Basic Options”</a>.
       </p></li><li class="listitem"><p>
        New methods have been added to the <code class="classname">QPDF</code>
        object for adding and removing pages.  See <a class="xref" href="#ref.adding-and-remove-pages" title="6.6. Adding and Removing Pages">Section 6.6, “Adding and Removing Pages”</a>.
       </p></li><li class="listitem"><p>
        New methods have been added to the <code class="classname">QPDF</code>
        object for copying objects from other PDF files.  See <a class="xref" href="#ref.foreign-objects" title="6.8. Copying Objects From Other PDF Files">Section 6.8, “Copying Objects From Other PDF Files”</a>
       </p></li><li class="listitem"><p>
        A new method <code class="function">QPDFObjectHandle::parse</code> has
        been added for constructing
        <code class="classname">QPDFObjectHandle</code> objects from a string
        description.
       </p></li><li class="listitem"><p>
        Methods have been added to <code class="classname">QPDFWriter</code>
        to allow writing to an already open stdio <span class="type">FILE*</span>
        addition to writing to standard output or a named file.
        Methods have been added to <code class="classname">QPDF</code> to be
        able to process a file from an already open stdio
        <span class="type">FILE*</span>.  This makes it possible to read and write
        PDF from secure temporary files that have been unlinked prior
        to being fully read or written.
       </p></li><li class="listitem"><p>
        The <code class="function">QPDF::emptyPDF</code> can be used to allow
        creation of PDF files from scratch.  The example
        <code class="filename">examples/pdf-create.cc</code> illustrates how it
        can be used.
       </p></li><li class="listitem"><p>
        Several methods to take
        <code class="classname">PointerHolder&lt;Buffer&gt;</code> can now
        also accept <span class="type">std::string</span> arguments.
       </p></li><li class="listitem"><p>
        Many new convenience methods have been added to the library,
        most in <code class="classname">QPDFObjectHandle</code>.  See
        <code class="filename">ChangeLog</code> for a full list.
       </p></li><li class="listitem"><p>
        When building on a platform that supports ELF shared libraries
        (such as Linux), symbol versions are enabled by default.  They
        can be disabled by passing
        <code class="option">--disable-ld-version-script</code> to
        <span class="command"><strong>./configure</strong></span>.
       </p></li><li class="listitem"><p>
        The file <code class="filename">libqpdf.pc</code> is now installed to
        support <span class="command"><strong>pkg-config</strong></span>.
       </p></li><li class="listitem"><p>
        Image comparison tests are off by default now since they are
        not needed to verify a correct build or port of qpdf.  They
        are needed only when changing the actual PDF output generated
        by qpdf.  You should enable them if you are making deep
        changes to qpdf itself.  See <code class="filename">README.md</code> for
        details.
       </p></li><li class="listitem"><p>
        Large file tests are off by default but can be turned on with
        <span class="command"><strong>./configure</strong></span> or by setting an environment
        variable before running the test suite.  See
        <code class="filename">README.md</code> for details.
       </p></li><li class="listitem"><p>
        When qpdf's test suite fails, failures are not printed to the
        terminal anymore by default.  Instead, find them in
        <code class="filename">build/qtest.log</code>.  For packagers who are
        building with an autobuilder, you can add the
        <code class="option">--enable-show-failed-test-output</code> option to
        <span class="command"><strong>./configure</strong></span> to restore the old behavior.
       </p></li></ul></div></dd><dt><span class="term">2.3.1: December 28, 2011</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Fix thread-safety problem resulting from non-thread-safe use
        of the PCRE library.
       </p></li><li class="listitem"><p>
        Made a few minor documentation fixes.
       </p></li><li class="listitem"><p>
        Add workaround for a bug that appears in some versions of
        ghostscript to the test suite
       </p></li><li class="listitem"><p>
        Fix minor build issue for Visual C++ 2010.
       </p></li></ul></div></dd><dt><span class="term">2.3.0: August 11, 2011</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Bug fix: when preserving existing encryption on encrypted
        files with cleartext metadata, older qpdf versions would
        generate password-protected files with no valid password.
        This operation now works.  This bug only affected files
        created by copying existing encryption parameters; explicit
        encryption with specification of cleartext metadata worked
        before and continues to work.
       </p></li><li class="listitem"><p>
        Enhance <code class="classname">QPDFWriter</code> with a new
        constructor that allows you to delay the specification of the
        output file.  When using this constructor, you may now call
        <code class="function">QPDFWriter::setOutputFilename</code> to specify
        the output file, or you may use
        <code class="function">QPDFWriter::setOutputMemory</code> to cause
        <code class="classname">QPDFWriter</code> to write the resulting PDF
        file to a memory buffer.  You may then use
        <code class="function">QPDFWriter::getBuffer</code> to retrieve the
        memory buffer.
       </p></li><li class="listitem"><p>
        Add new API call <code class="function">QPDF::replaceObject</code> for
        replacing objects by object ID
       </p></li><li class="listitem"><p>
        Add new API call <code class="function">QPDF::swapObjects</code> for
        swapping two objects by object ID
       </p></li><li class="listitem"><p>
        Add <code class="function">QPDFObjectHandle::getDictAsMap</code> and
        <code class="function">QPDFObjectHandle::getArrayAsVector</code> to
        allow retrieval of dictionary objects as maps and array
        objects as vectors.
       </p></li><li class="listitem"><p>
        Add functions <code class="function">qpdf_get_info_key</code> and
        <code class="function">qpdf_set_info_key</code> to the C API for
        manipulating string fields of the document's
        <code class="literal">/Info</code> dictionary.
       </p></li><li class="listitem"><p>
        Add functions <code class="function">qpdf_init_write_memory</code>,
        <code class="function">qpdf_get_buffer_length</code>, and
        <code class="function">qpdf_get_buffer</code> to the C API for writing
        PDF files to a memory buffer instead of a file.
       </p></li></ul></div></dd><dt><span class="term">2.2.4: June 25, 2011</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Fix installation and compilation issues; no functionality
        changes.
       </p></li></ul></div></dd><dt><span class="term">2.2.3: April 30, 2011</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Handle some damaged streams with incorrect characters
        following the stream keyword.
       </p></li><li class="listitem"><p>
        Improve handling of inline images when normalizing content
        streams.
       </p></li><li class="listitem"><p>
        Enhance error recovery to properly handle files that use
        object 0 as a regular object, which is specifically disallowed
        by the spec.
       </p></li></ul></div></dd><dt><span class="term">2.2.2: October 4, 2010</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Add new function <code class="function">qpdf_read_memory</code>
        to the C API to call
        <code class="function">QPDF::processMemoryFile</code>.  This was an
        omission in qpdf 2.2.1.
       </p></li></ul></div></dd><dt><span class="term">2.2.1: October 1, 2010</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Add new method <code class="function">QPDF::setOutputStreams</code>
        to replace <code class="varname">std::cout</code> and
        <code class="varname">std::cerr</code> with other streams for generation
        of diagnostic messages and error messages.  This can be useful
        for GUIs or other applications that want to capture any output
        generated by the library to present to the user in some other
        way.  Note that QPDF does not write to
        <code class="varname">std::cout</code> (or the specified output stream)
        except where explicitly mentioned in
        <code class="filename">QPDF.hh</code>, and that the only use of the
        error stream is for warnings.  Note also that output of
        warnings is suppressed when
        <code class="literal">setSuppressWarnings(true)</code> is called.
       </p></li><li class="listitem"><p>
        Add new method <code class="function">QPDF::processMemoryFile</code>
        for operating on PDF files that are loaded into memory rather
        than in a file on disk.
       </p></li><li class="listitem"><p>
        Give a warning but otherwise ignore empty PDF objects by
        treating them as null.  Empty object are not permitted by the
        PDF specification but have been known to appear in some actual
        PDF files.
       </p></li><li class="listitem"><p>
        Handle inline image filter abbreviations when the appear as
        stream filter abbreviations.  The PDF specification does not
        allow use of stream filter abbreviations in this way, but
        Adobe Reader and some other PDF readers accept them since they
        sometimes appear incorrectly in actual PDF files.
       </p></li><li class="listitem"><p>
        Implement miscellaneous enhancements to
        <code class="classname">PointerHolder</code> and
        <code class="classname">Buffer</code> to support other changes.
       </p></li></ul></div></dd><dt><span class="term">2.2.0: August 14, 2010</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Add new methods to <code class="classname">QPDFObjectHandle</code>
        (<code class="function">newStream</code> and
        <code class="function">replaceStreamData</code> for creating new
        streams and replacing stream data.  This makes it possible to
        perform a wide range of operations that were not previously
        possible.
       </p></li><li class="listitem"><p>
        Add new helper method in
        <code class="classname">QPDFObjectHandle</code>
        (<code class="function">addPageContents</code>) for appending or
        prepending new content streams to a page.  This method makes
        it possible to manipulate content streams without having to be
        concerned whether a page's contents are a single stream or an
        array of streams.
       </p></li><li class="listitem"><p>
        Add new method in <code class="classname">QPDFObjectHandle</code>:
        <code class="function">replaceOrRemoveKey</code>, which replaces a
        dictionary key
        with a given value unless the value is null, in which case it
        removes the key instead.
       </p></li><li class="listitem"><p>
        Add new method in <code class="classname">QPDFObjectHandle</code>:
        <code class="function">getRawStreamData</code>, which returns the raw
        (unfiltered) stream data into a buffer.  This complements the
        <code class="function">getStreamData</code> method, which returns the
        filtered (uncompressed) stream data and can only be used when
        the stream's data is filterable.
       </p></li><li class="listitem"><p>
        Provide two new examples:
        <span class="command"><strong>pdf-double-page-size</strong></span> and
        <span class="command"><strong>pdf-invert-images</strong></span> that illustrate the newly
        added interfaces.
       </p></li><li class="listitem"><p>
        Fix a memory leak that would cause loss of a few bytes for
        every object involved in a cycle of object references.  Thanks
        to Jian Ma for calling my attention to the leak.
       </p></li></ul></div></dd><dt><span class="term">2.1.5: April 25, 2010</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Remove restriction of file identifier strings to 16 bytes.
        This unnecessary restriction was preventing qpdf from being
        able to encrypt or decrypt files with identifier strings that
        were not exactly 16 bytes long.  The specification imposes no
        such restriction.
       </p></li></ul></div></dd><dt><span class="term">2.1.4: April 18, 2010</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Apply the same padding calculation fix from version 2.1.2 to
        the main cross reference stream as well.
       </p></li><li class="listitem"><p>
        Since <span class="command"><strong>qpdf --check</strong></span> only performs limited
        checks, clarify the output to make it clear that there still
        may be errors that qpdf can't check.  This should make it less
        surprising to people when another PDF reader is unable to read
        a file that qpdf thinks is okay.
       </p></li></ul></div></dd><dt><span class="term">2.1.3: March 27, 2010</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Fix bug that could cause a failure when rewriting PDF files
        that contain object streams with unreferenced objects that in
        turn reference indirect scalars.
       </p></li><li class="listitem"><p>
        Don't complain about (invalid) AES streams that aren't a
        multiple of 16 bytes.  Instead, pad them before decrypting.
       </p></li></ul></div></dd><dt><span class="term">2.1.2: January 24, 2010</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Fix bug in padding around first half cross reference stream in
        linearized files.  The bug could cause an assertion failure
        when linearizing certain unlucky files.
       </p></li></ul></div></dd><dt><span class="term">2.1.1: December 14, 2009</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        No changes in functionality; insert missing include in an
        internal library header file to support gcc 4.4, and update
        test suite to ignore broken Adobe Reader installations.
       </p></li></ul></div></dd><dt><span class="term">2.1: October 30, 2009</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        This is the first version of qpdf to include Windows support.
        On Windows, it is possible to build a DLL. Additionally, a
        partial C-language API has been introduced, which makes it
        possible to call qpdf functions from non-C++ environments. I
        am very grateful to Žarko  Gajic (<a class="ulink" href="http://zarko-gajic.iz.hr/" target="_top">http://zarko-gajic.iz.hr/</a>)
        for tirelessly testing numerous pre-release versions of this
        DLL and providing many excellent suggestions on improving the
        interface.
       </p><p>
        For programming to the C interface, please see the header file
        <code class="filename">qpdf/qpdf-c.h</code> and the example
        <code class="filename">examples/pdf-linearize.c</code>.
       </p></li><li class="listitem"><p>
        Žarko Gajic has written a Delphi wrapper for qpdf, which can
        be downloaded from qpdf's download side.  Žarko's Delphi
        wrapper is released with the same licensing terms as qpdf
        itself and comes with this disclaimer: “Delphi wrapper
        unit <code class="filename">qpdf.pas</code> created by Žarko Gajic
        (<a class="ulink" href="http://zarko-gajic.iz.hr/" target="_top">http://zarko-gajic.iz.hr/</a>).
        Use at your own risk and for whatever purpose you want.  No
        support is provided.  Sample code is provided.”
       </p></li><li class="listitem"><p>
        Support has been added for AES encryption and crypt filters.
        Although qpdf does not presently support files that use
        PKI-based encryption, with the addition of AES and crypt
        filters, qpdf is now be able to open most encrypted files
        created with newer versions of Acrobat or other PDF creation
        software.  Note that I have not been able to get very many
        files encrypted in this way, so it's possible there could
        still be some cases that qpdf can't handle.  Please report
        them if you find them.
       </p></li><li class="listitem"><p>
        Many error messages have been improved to include more
        information in hopes of making qpdf a more useful tool for PDF
        experts to use in manually recovering damaged PDF files.
       </p></li><li class="listitem"><p>
        Attempt to avoid compressing metadata streams if possible.
        This is consistent with other PDF creation applications.
       </p></li><li class="listitem"><p>
        Provide new command-line options for AES encrypt, cleartext
        metadata, and setting the minimum and forced PDF versions of
        output files.
       </p></li><li class="listitem"><p>
        Add additional methods to the <code class="classname">QPDF</code>
        object for querying the document's permissions.  Although qpdf
        does not enforce these permissions, it does make them
        available so that applications that use qpdf can enforce
        permissions.
       </p></li><li class="listitem"><p>
        The <code class="option">--check</code> option to <span class="command"><strong>qpdf</strong></span>
        has been extended to include some additional information.
       </p></li><li class="listitem"><p>
        There have been a handful of non-compatible API changes.  For
        details, see <a class="xref" href="#ref.upgrading-to-2.1" title="Appendix B. Upgrading from 2.0 to 2.1">Appendix B, <em>Upgrading from 2.0 to 2.1</em></a>.
       </p></li></ul></div></dd><dt><span class="term">2.0.6: May 3, 2009</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Do not attempt to uncompress streams that have decode
        parameters we don't recognize.  Earlier versions of qpdf would
        have rejected files with such streams.
       </p></li></ul></div></dd><dt><span class="term">2.0.5: March 10, 2009</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Improve error handling in the LZW decoder, and fix a small
        error introduced in the previous version with regard to
        handling full tables.  The LZW decoder has been more strongly
        verified in this release.
       </p></li></ul></div></dd><dt><span class="term">2.0.4: February 21, 2009</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Include proper support for LZW streams encoded without the
        “early code change” flag.  Special thanks to Atom
        Smasher who reported the problem and provided an input file
        compressed in this way, which I did not previously have.
       </p></li><li class="listitem"><p>
        Implement some improvements to file recovery logic.
       </p></li></ul></div></dd><dt><span class="term">2.0.3: February 15, 2009</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Compile cleanly with gcc 4.4.
       </p></li><li class="listitem"><p>
        Handle strings encoded as UTF-16BE properly.
       </p></li></ul></div></dd><dt><span class="term">2.0.2: June 30, 2008</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        Update test suite to work properly with a
        non-<span class="command"><strong>bash</strong></span> <code class="filename">/bin/sh</code> and
        with Perl 5.10.  No changes were made to the actual qpdf
        source code itself for this release.
       </p></li></ul></div></dd><dt><span class="term">2.0.1: May 6, 2008</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        No changes in functionality or interface.  This release
        includes fixes to the source code so that qpdf compiles
        properly and passes its test suite on a broader range of
        platforms.  See <code class="filename">ChangeLog</code> in the source
        distribution for details.
       </p></li></ul></div></dd><dt><span class="term">2.0: April 29, 2008</span></dt><dd><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
        First public release.
       </p></li></ul></div></dd></dl></div></div><div class="appendix"><div class="titlepage"><div><div><h1 class="title"><a id="ref.upgrading-to-2.1"></a>Appendix B. Upgrading from 2.0 to 2.1</h1></div></div></div><p>
   Although, as a general rule, we like to avoid introducing
   source-level incompatibilities in qpdf's interface, there were a
   few non-compatible changes made in this version.  A considerable
   amount of source code that uses qpdf will probably compile without
   any changes, but in some cases, you may have to update your code.
   The changes are enumerated here.  There are also some new
   interfaces; for those, please refer to the header files.
  </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
     QPDF's exception handling mechanism now uses
     <code class="classname">std::logic_error</code> for internal errors and
     <code class="classname">std::runtime_error</code> for runtime errors in
     favor of the now removed <code class="classname">QEXC</code> classes used
     in previous versions.  The <code class="classname">QEXC</code> exception
     classes predated the addition of the
     <code class="filename">&lt;stdexcept&gt;</code> header file to the C++
     standard library.  Most of the exceptions thrown by the qpdf
     library itself are still of type <code class="classname">QPDFExc</code>
     which is now derived from
     <code class="classname">std::runtime_error</code>.  Programs that caught
     an instance of <code class="classname">std::exception</code> and
     displayed it by calling the <code class="function">what()</code> method
     will not need to be changed.
    </p></li><li class="listitem"><p>
     The <code class="classname">QPDFExc</code> class now internally
     represents various fields of the error condition and provides
     interfaces for querying them.  Among the fields is a numeric
     error code that can help applications act differently on (a small
     number of) different error conditions.  See
     <code class="filename">QPDFExc.hh</code> for details.
    </p></li><li class="listitem"><p>
     Warnings can be retrieved from qpdf as instances of
     <code class="classname">QPDFExc</code> instead of strings.
    </p></li><li class="listitem"><p>
     The nested <code class="classname">QPDF::EncryptionData</code> class's
     constructor takes an additional argument.  This class is
     primarily intended to be used by
     <code class="classname">QPDFWriter</code>.  There's not really anything
     useful an end-user application could do with it.  It probably
     shouldn't really be part of the public interface to begin with.
     Likewise, some of the methods for computing internal encryption
     dictionary parameters have changed to support
     <code class="literal">/R=4</code> encryption.
    </p></li><li class="listitem"><p>
     The method <code class="function">QPDF::getUserPassword</code> has been
     removed since it didn't do what people would think it did.  There
     are now two new methods:
     <code class="function">QPDF::getPaddedUserPassword</code> and
     <code class="function">QPDF::getTrimmedUserPassword</code>.  The first one
     does what the old <code class="function">QPDF::getUserPassword</code>
     method used to do, which is to return the password with possible
     binary padding as specified by the PDF specification.  The second
     one returns a human-readable password string.
    </p></li><li class="listitem"><p>
     The enumerated types that used to be nested in
     <code class="classname">QPDFWriter</code> have moved to top-level
     enumerated types and are now defined in the file
     <code class="filename">qpdf/Constants.h</code>.  This enables them to be
     shared by both the C and C++ interfaces.
    </p></li></ul></div></div><div class="appendix"><div class="titlepage"><div><div><h1 class="title"><a id="ref.upgrading-to-3.0"></a>Appendix C. Upgrading to 3.0</h1></div></div></div><p>
   For the most part, the API for qpdf version 3.0 is backward
   compatible with versions 2.1 and later.  There are two exceptions:
   </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
      The method
      <code class="function">QPDFObjectHandle::replaceStreamData</code> that
      uses a <code class="classname">StreamDataProvider</code> to provide the
      stream data no longer takes a <code class="varname">length</code>
      parameter.  While it would have been easy enough to keep the
      parameter for backward compatibility, in this case, the
      parameter was removed since this provides the user an
      opportunity to simplify the calling code.  This method was
      introduced in version 2.2.  At the time, the
      <code class="varname">length</code> parameter was required in order to
      ensure that calls to the stream data provider returned the same
      length for a specific stream every time they were invoked.  In
      particular, the linearization code depends on this.  Instead,
      qpdf 3.0 and newer check for that constraint explicitly.  The
      first time the stream data provider is called for a specific
      stream, the actual length is saved, and subsequent calls are
      required to return the same number of bytes.  This means the
      calling code no longer has to compute the length in advance,
      which can be a significant simplification.  If your code fails
      to compile because of the extra argument and you don't want to
      make other changes to your code, just omit the argument.
     </p></li><li class="listitem"><p>
      Many methods take <span class="type">long long</span> instead of other
      integer types.  Most if not all existing code should compile
      fine with this change since such parameters had always
      previously been smaller types.  This change was required to
      support files larger than two gigabytes in size.
     </p></li></ul></div><p>
  </p></div><div class="appendix"><div class="titlepage"><div><div><h1 class="title"><a id="ref.upgrading-to-4.0"></a>Appendix D. Upgrading to 4.0</h1></div></div></div><p>
   While version 4.0 includes a few non-compatible API changes, it is
   very unlikely that anyone's code would have used any of those parts
   of the API since they generally required information that would
   only be available inside the library.  In the unlikely event that
   you should run into trouble, please see the ChangeLog.  See also
   <a class="xref" href="#ref.release-notes" title="Appendix A. Release Notes">Appendix A, <em>Release Notes</em></a> for a complete list of the
   non-compatible API changes made in this version.
  </p></div></div></body></html>