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 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147
|
/*
* $Id: PdfWriter.java 3948 2009-06-03 15:17:22Z blowagie $
*
* Copyright 1999, 2000, 2001, 2002 Bruno Lowagie
*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library'.
*
* The Initial Developer of the Original Code is Bruno Lowagie. Portions created by
* the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie.
* All Rights Reserved.
* Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer
* are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved.
*
* Contributor(s): all the names of the contributors are added in the source code
* where applicable.
*
* Alternatively, the contents of this file may be used under the terms of the
* LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
* provisions of LGPL are applicable instead of those above. If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
* details.
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://www.lowagie.com/iText/
*/
package com.lowagie.text.pdf;
import java.awt.Color;
import java.awt.color.ICC_Profile;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.TreeSet;
import java.security.cert.Certificate;
import com.lowagie.text.DocListener;
import com.lowagie.text.DocWriter;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Image;
import com.lowagie.text.ImgJBIG2;
import com.lowagie.text.ImgWMF;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.collection.PdfCollection;
import com.lowagie.text.pdf.events.PdfPageEventForwarder;
import com.lowagie.text.pdf.interfaces.PdfAnnotations;
import com.lowagie.text.pdf.interfaces.PdfDocumentActions;
import com.lowagie.text.pdf.interfaces.PdfEncryptionSettings;
import com.lowagie.text.pdf.interfaces.PdfPageActions;
import com.lowagie.text.pdf.interfaces.PdfVersion;
import com.lowagie.text.pdf.interfaces.PdfViewerPreferences;
import com.lowagie.text.pdf.interfaces.PdfXConformance;
import com.lowagie.text.pdf.interfaces.PdfRunDirection;
import com.lowagie.text.pdf.internal.PdfVersionImp;
import com.lowagie.text.pdf.internal.PdfXConformanceImp;
import com.lowagie.text.xml.xmp.XmpWriter;
/**
* A <CODE>DocWriter</CODE> class for PDF.
* <P>
* When this <CODE>PdfWriter</CODE> is added
* to a certain <CODE>PdfDocument</CODE>, the PDF representation of every Element
* added to this Document will be written to the outputstream.</P>
*/
public class PdfWriter extends DocWriter implements
PdfViewerPreferences,
PdfEncryptionSettings,
PdfVersion,
PdfDocumentActions,
PdfPageActions,
PdfXConformance,
PdfRunDirection,
PdfAnnotations {
/**
* The highest generation number possible.
* @since iText 2.1.6
*/
public static final int GENERATION_MAX = 65535;
// INNER CLASSES
/**
* This class generates the structure of a PDF document.
* <P>
* This class covers the third section of Chapter 5 in the 'Portable Document Format
* Reference Manual version 1.3' (page 55-60). It contains the body of a PDF document
* (section 5.14) and it can also generate a Cross-reference Table (section 5.15).
*
* @see PdfWriter
* @see PdfObject
* @see PdfIndirectObject
*/
public static class PdfBody {
// inner classes
/**
* <CODE>PdfCrossReference</CODE> is an entry in the PDF Cross-Reference table.
*/
static class PdfCrossReference implements Comparable {
// membervariables
private int type;
/** Byte offset in the PDF file. */
private int offset;
private int refnum;
/** generation of the object. */
private int generation;
// constructors
/**
* Constructs a cross-reference element for a PdfIndirectObject.
* @param refnum
* @param offset byte offset of the object
* @param generation generation number of the object
*/
PdfCrossReference(int refnum, int offset, int generation) {
type = 0;
this.offset = offset;
this.refnum = refnum;
this.generation = generation;
}
/**
* Constructs a cross-reference element for a PdfIndirectObject.
* @param refnum
* @param offset byte offset of the object
*/
PdfCrossReference(int refnum, int offset) {
type = 1;
this.offset = offset;
this.refnum = refnum;
this.generation = 0;
}
PdfCrossReference(int type, int refnum, int offset, int generation) {
this.type = type;
this.offset = offset;
this.refnum = refnum;
this.generation = generation;
}
int getRefnum() {
return refnum;
}
/**
* Returns the PDF representation of this <CODE>PdfObject</CODE>.
* @param os
* @throws IOException
*/
public void toPdf(OutputStream os) throws IOException {
StringBuffer off = new StringBuffer("0000000000").append(offset);
off.delete(0, off.length() - 10);
StringBuffer gen = new StringBuffer("00000").append(generation);
gen.delete(0, gen.length() - 5);
off.append(' ').append(gen).append(generation == GENERATION_MAX ? " f \n" : " n \n");
os.write(getISOBytes(off.toString()));
}
/**
* Writes PDF syntax to the OutputStream
* @param midSize
* @param os
* @throws IOException
*/
public void toPdf(int midSize, OutputStream os) throws IOException {
os.write((byte)type);
while (--midSize >= 0)
os.write((byte)((offset >>> (8 * midSize)) & 0xff));
os.write((byte)((generation >>> 8) & 0xff));
os.write((byte)(generation & 0xff));
}
/**
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Object o) {
PdfCrossReference other = (PdfCrossReference)o;
return (refnum < other.refnum ? -1 : (refnum==other.refnum ? 0 : 1));
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj instanceof PdfCrossReference) {
PdfCrossReference other = (PdfCrossReference)obj;
return (refnum == other.refnum);
}
else
return false;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return refnum;
}
}
private static final int OBJSINSTREAM = 200;
// membervariables
/** array containing the cross-reference table of the normal objects. */
private TreeSet xrefs;
private int refnum;
/** the current byte position in the body. */
private int position;
private PdfWriter writer;
private ByteBuffer index;
private ByteBuffer streamObjects;
private int currentObjNum;
private int numObj = 0;
// constructors
/**
* Constructs a new <CODE>PdfBody</CODE>.
* @param writer
*/
PdfBody(PdfWriter writer) {
xrefs = new TreeSet();
xrefs.add(new PdfCrossReference(0, 0, GENERATION_MAX));
position = writer.getOs().getCounter();
refnum = 1;
this.writer = writer;
}
// methods
void setRefnum(int refnum) {
this.refnum = refnum;
}
private PdfWriter.PdfBody.PdfCrossReference addToObjStm(PdfObject obj, int nObj) throws IOException {
if (numObj >= OBJSINSTREAM)
flushObjStm();
if (index == null) {
index = new ByteBuffer();
streamObjects = new ByteBuffer();
currentObjNum = getIndirectReferenceNumber();
numObj = 0;
}
int p = streamObjects.size();
int idx = numObj++;
PdfEncryption enc = writer.crypto;
writer.crypto = null;
obj.toPdf(writer, streamObjects);
writer.crypto = enc;
streamObjects.append(' ');
index.append(nObj).append(' ').append(p).append(' ');
return new PdfWriter.PdfBody.PdfCrossReference(2, nObj, currentObjNum, idx);
}
private void flushObjStm() throws IOException {
if (numObj == 0)
return;
int first = index.size();
index.append(streamObjects);
PdfStream stream = new PdfStream(index.toByteArray());
stream.flateCompress(writer.getCompressionLevel());
stream.put(PdfName.TYPE, PdfName.OBJSTM);
stream.put(PdfName.N, new PdfNumber(numObj));
stream.put(PdfName.FIRST, new PdfNumber(first));
add(stream, currentObjNum);
index = null;
streamObjects = null;
numObj = 0;
}
/**
* Adds a <CODE>PdfObject</CODE> to the body.
* <P>
* This methods creates a <CODE>PdfIndirectObject</CODE> with a
* certain number, containing the given <CODE>PdfObject</CODE>.
* It also adds a <CODE>PdfCrossReference</CODE> for this object
* to an <CODE>ArrayList</CODE> that will be used to build the
* Cross-reference Table.
*
* @param object a <CODE>PdfObject</CODE>
* @return a <CODE>PdfIndirectObject</CODE>
* @throws IOException
*/
PdfIndirectObject add(PdfObject object) throws IOException {
return add(object, getIndirectReferenceNumber());
}
PdfIndirectObject add(PdfObject object, boolean inObjStm) throws IOException {
return add(object, getIndirectReferenceNumber(), inObjStm);
}
/**
* Gets a PdfIndirectReference for an object that will be created in the future.
* @return a PdfIndirectReference
*/
PdfIndirectReference getPdfIndirectReference() {
return new PdfIndirectReference(0, getIndirectReferenceNumber());
}
int getIndirectReferenceNumber() {
int n = refnum++;
xrefs.add(new PdfCrossReference(n, 0, GENERATION_MAX));
return n;
}
/**
* Adds a <CODE>PdfObject</CODE> to the body given an already existing
* PdfIndirectReference.
* <P>
* This methods creates a <CODE>PdfIndirectObject</CODE> with the number given by
* <CODE>ref</CODE>, containing the given <CODE>PdfObject</CODE>.
* It also adds a <CODE>PdfCrossReference</CODE> for this object
* to an <CODE>ArrayList</CODE> that will be used to build the
* Cross-reference Table.
*
* @param object a <CODE>PdfObject</CODE>
* @param ref a <CODE>PdfIndirectReference</CODE>
* @return a <CODE>PdfIndirectObject</CODE>
* @throws IOException
*/
PdfIndirectObject add(PdfObject object, PdfIndirectReference ref) throws IOException {
return add(object, ref.getNumber());
}
PdfIndirectObject add(PdfObject object, PdfIndirectReference ref, boolean inObjStm) throws IOException {
return add(object, ref.getNumber(), inObjStm);
}
PdfIndirectObject add(PdfObject object, int refNumber) throws IOException {
return add(object, refNumber, true); // to false
}
PdfIndirectObject add(PdfObject object, int refNumber, boolean inObjStm) throws IOException {
if (inObjStm && object.canBeInObjStm() && writer.isFullCompression()) {
PdfCrossReference pxref = addToObjStm(object, refNumber);
PdfIndirectObject indirect = new PdfIndirectObject(refNumber, object, writer);
if (!xrefs.add(pxref)) {
xrefs.remove(pxref);
xrefs.add(pxref);
}
return indirect;
}
else {
PdfIndirectObject indirect = new PdfIndirectObject(refNumber, object, writer);
PdfCrossReference pxref = new PdfCrossReference(refNumber, position);
if (!xrefs.add(pxref)) {
xrefs.remove(pxref);
xrefs.add(pxref);
}
indirect.writeTo(writer.getOs());
position = writer.getOs().getCounter();
return indirect;
}
}
/**
* Returns the offset of the Cross-Reference table.
*
* @return an offset
*/
int offset() {
return position;
}
/**
* Returns the total number of objects contained in the CrossReferenceTable of this <CODE>Body</CODE>.
*
* @return a number of objects
*/
int size() {
return Math.max(((PdfCrossReference)xrefs.last()).getRefnum() + 1, refnum);
}
/**
* Returns the CrossReferenceTable of the <CODE>Body</CODE>.
* @param os
* @param root
* @param info
* @param encryption
* @param fileID
* @param prevxref
* @throws IOException
*/
void writeCrossReferenceTable(OutputStream os, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, int prevxref) throws IOException {
int refNumber = 0;
if (writer.isFullCompression()) {
flushObjStm();
refNumber = getIndirectReferenceNumber();
xrefs.add(new PdfCrossReference(refNumber, position));
}
PdfCrossReference entry = (PdfCrossReference)xrefs.first();
int first = entry.getRefnum();
int len = 0;
ArrayList sections = new ArrayList();
for (Iterator i = xrefs.iterator(); i.hasNext(); ) {
entry = (PdfCrossReference)i.next();
if (first + len == entry.getRefnum())
++len;
else {
sections.add(new Integer(first));
sections.add(new Integer(len));
first = entry.getRefnum();
len = 1;
}
}
sections.add(new Integer(first));
sections.add(new Integer(len));
if (writer.isFullCompression()) {
int mid = 4;
int mask = 0xff000000;
for (; mid > 1; --mid) {
if ((mask & position) != 0)
break;
mask >>>= 8;
}
ByteBuffer buf = new ByteBuffer();
for (Iterator i = xrefs.iterator(); i.hasNext(); ) {
entry = (PdfCrossReference) i.next();
entry.toPdf(mid, buf);
}
PdfStream xr = new PdfStream(buf.toByteArray());
buf = null;
xr.flateCompress(writer.getCompressionLevel());
xr.put(PdfName.SIZE, new PdfNumber(size()));
xr.put(PdfName.ROOT, root);
if (info != null) {
xr.put(PdfName.INFO, info);
}
if (encryption != null)
xr.put(PdfName.ENCRYPT, encryption);
if (fileID != null)
xr.put(PdfName.ID, fileID);
xr.put(PdfName.W, new PdfArray(new int[]{1, mid, 2}));
xr.put(PdfName.TYPE, PdfName.XREF);
PdfArray idx = new PdfArray();
for (int k = 0; k < sections.size(); ++k)
idx.add(new PdfNumber(((Integer)sections.get(k)).intValue()));
xr.put(PdfName.INDEX, idx);
if (prevxref > 0)
xr.put(PdfName.PREV, new PdfNumber(prevxref));
PdfEncryption enc = writer.crypto;
writer.crypto = null;
PdfIndirectObject indirect = new PdfIndirectObject(refNumber, xr, writer);
indirect.writeTo(writer.getOs());
writer.crypto = enc;
}
else {
os.write(getISOBytes("xref\n"));
Iterator i = xrefs.iterator();
for (int k = 0; k < sections.size(); k += 2) {
first = ((Integer)sections.get(k)).intValue();
len = ((Integer)sections.get(k + 1)).intValue();
os.write(getISOBytes(String.valueOf(first)));
os.write(getISOBytes(" "));
os.write(getISOBytes(String.valueOf(len)));
os.write('\n');
while (len-- > 0) {
entry = (PdfCrossReference) i.next();
entry.toPdf(os);
}
}
}
}
}
/**
* <CODE>PdfTrailer</CODE> is the PDF Trailer object.
* <P>
* This object is described in the 'Portable Document Format Reference Manual version 1.3'
* section 5.16 (page 59-60).
*/
static class PdfTrailer extends PdfDictionary {
// membervariables
int offset;
// constructors
/**
* Constructs a PDF-Trailer.
*
* @param size the number of entries in the <CODE>PdfCrossReferenceTable</CODE>
* @param offset offset of the <CODE>PdfCrossReferenceTable</CODE>
* @param root an indirect reference to the root of the PDF document
* @param info an indirect reference to the info object of the PDF document
* @param encryption
* @param fileID
* @param prevxref
*/
PdfTrailer(int size, int offset, PdfIndirectReference root, PdfIndirectReference info, PdfIndirectReference encryption, PdfObject fileID, int prevxref) {
this.offset = offset;
put(PdfName.SIZE, new PdfNumber(size));
put(PdfName.ROOT, root);
if (info != null) {
put(PdfName.INFO, info);
}
if (encryption != null)
put(PdfName.ENCRYPT, encryption);
if (fileID != null)
put(PdfName.ID, fileID);
if (prevxref > 0)
put(PdfName.PREV, new PdfNumber(prevxref));
}
/**
* Returns the PDF representation of this <CODE>PdfObject</CODE>.
* @param writer
* @param os
* @throws IOException
*/
public void toPdf(PdfWriter writer, OutputStream os) throws IOException {
os.write(getISOBytes("trailer\n"));
super.toPdf(null, os);
os.write(getISOBytes("\nstartxref\n"));
os.write(getISOBytes(String.valueOf(offset)));
os.write(getISOBytes("\n%%EOF\n"));
}
}
// ESSENTIALS
// Construct a PdfWriter instance
/**
* Constructs a <CODE>PdfWriter</CODE>.
*/
protected PdfWriter() {
}
/**
* Constructs a <CODE>PdfWriter</CODE>.
* <P>
* Remark: a PdfWriter can only be constructed by calling the method
* <CODE>getInstance(Document document, OutputStream os)</CODE>.
*
* @param document The <CODE>PdfDocument</CODE> that has to be written
* @param os The <CODE>OutputStream</CODE> the writer has to write to.
*/
protected PdfWriter(PdfDocument document, OutputStream os) {
super(document, os);
pdf = document;
directContent = new PdfContentByte(this);
directContentUnder = new PdfContentByte(this);
}
/**
* Use this method to get an instance of the <CODE>PdfWriter</CODE>.
*
* @param document The <CODE>Document</CODE> that has to be written
* @param os The <CODE>OutputStream</CODE> the writer has to write to.
* @return a new <CODE>PdfWriter</CODE>
*
* @throws DocumentException on error
*/
public static PdfWriter getInstance(Document document, OutputStream os)
throws DocumentException {
PdfDocument pdf = new PdfDocument();
document.addDocListener(pdf);
PdfWriter writer = new PdfWriter(pdf, os);
pdf.addWriter(writer);
return writer;
}
/**
* Use this method to get an instance of the <CODE>PdfWriter</CODE>.
*
* @return a new <CODE>PdfWriter</CODE>
* @param document The <CODE>Document</CODE> that has to be written
* @param os The <CODE>OutputStream</CODE> the writer has to write to.
* @param listener A <CODE>DocListener</CODE> to pass to the PdfDocument.
* @throws DocumentException on error
*/
public static PdfWriter getInstance(Document document, OutputStream os, DocListener listener)
throws DocumentException {
PdfDocument pdf = new PdfDocument();
pdf.addDocListener(listener);
document.addDocListener(pdf);
PdfWriter writer = new PdfWriter(pdf, os);
pdf.addWriter(writer);
return writer;
}
// the PdfDocument instance
/** the pdfdocument object. */
protected PdfDocument pdf;
/**
* Gets the <CODE>PdfDocument</CODE> associated with this writer.
* @return the <CODE>PdfDocument</CODE>
*/
PdfDocument getPdfDocument() {
return pdf;
}
/**
* Use this method to get the info dictionary if you want to
* change it directly (add keys and values to the info dictionary).
* @return the info dictionary
*/
public PdfDictionary getInfo() {
return pdf.getInfo();
}
/**
* Use this method to get the current vertical page position.
* @param ensureNewLine Tells whether a new line shall be enforced. This may cause side effects
* for elements that do not terminate the lines they've started because those lines will get
* terminated.
* @return The current vertical page position.
*/
public float getVerticalPosition(boolean ensureNewLine) {
return pdf.getVerticalPosition(ensureNewLine);
}
/**
* Sets the initial leading for the PDF document.
* This has to be done before the document is opened.
* @param leading the initial leading
* @since 2.1.6
* @throws DocumentException if you try setting the leading after the document was opened.
*/
public void setInitialLeading(float leading) throws DocumentException {
if (open)
throw new DocumentException("You can't set the initial leading if the document is already open.");
pdf.setLeading(leading);
}
// the PdfDirectContentByte instances
/*
* You should see Direct Content as a canvas on which you can draw
* graphics and text. One canvas goes on top of the page (getDirectContent),
* the other goes underneath (getDirectContentUnder).
* You can always the same object throughout your document,
* even if you have moved to a new page. Whatever you add on
* the canvas will be displayed on top or under the current page.
*/
/** The direct content in this document. */
protected PdfContentByte directContent;
/** The direct content under in this document. */
protected PdfContentByte directContentUnder;
/**
* Use this method to get the direct content for this document.
* There is only one direct content, multiple calls to this method
* will allways retrieve the same object.
* @return the direct content
*/
public PdfContentByte getDirectContent() {
if (!open)
throw new RuntimeException("The document is not open.");
return directContent;
}
/**
* Use this method to get the direct content under for this document.
* There is only one direct content, multiple calls to this method
* will always retrieve the same object.
* @return the direct content
*/
public PdfContentByte getDirectContentUnder() {
if (!open)
throw new RuntimeException("The document is not open.");
return directContentUnder;
}
/**
* Resets all the direct contents to empty.
* This happens when a new page is started.
*/
void resetContent() {
directContent.reset();
directContentUnder.reset();
}
// PDF body
/*
* A PDF file has 4 parts: a header, a body, a cross-reference table, and a trailer.
* The body contains all the PDF objects that make up the PDF document.
* Each element gets a reference (a set of numbers) and the byte position of
* every object is stored in the cross-reference table.
* Use these methods only if you know what you're doing.
*/
/** body of the PDF document */
protected PdfBody body;
/**
* Adds the local destinations to the body of the document.
* @param dest the <CODE>HashMap</CODE> containing the destinations
* @throws IOException on error
*/
void addLocalDestinations(TreeMap dest) throws IOException {
for (Iterator i = dest.entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
String name = (String) entry.getKey();
Object obj[] = (Object[]) entry.getValue();
PdfDestination destination = (PdfDestination)obj[2];
if (obj[1] == null)
obj[1] = getPdfIndirectReference();
if (destination == null)
addToBody(new PdfString("invalid_" + name), (PdfIndirectReference)obj[1]);
else
addToBody(destination, (PdfIndirectReference)obj[1]);
}
}
/**
* Use this method to add a PDF object to the PDF body.
* Use this method only if you know what you're doing!
* @param object
* @return a PdfIndirectObject
* @throws IOException
*/
public PdfIndirectObject addToBody(PdfObject object) throws IOException {
PdfIndirectObject iobj = body.add(object);
return iobj;
}
/**
* Use this method to add a PDF object to the PDF body.
* Use this method only if you know what you're doing!
* @param object
* @param inObjStm
* @return a PdfIndirectObject
* @throws IOException
*/
public PdfIndirectObject addToBody(PdfObject object, boolean inObjStm) throws IOException {
PdfIndirectObject iobj = body.add(object, inObjStm);
return iobj;
}
/**
* Use this method to add a PDF object to the PDF body.
* Use this method only if you know what you're doing!
* @param object
* @param ref
* @return a PdfIndirectObject
* @throws IOException
*/
public PdfIndirectObject addToBody(PdfObject object, PdfIndirectReference ref) throws IOException {
PdfIndirectObject iobj = body.add(object, ref);
return iobj;
}
/**
* Use this method to add a PDF object to the PDF body.
* Use this method only if you know what you're doing!
* @param object
* @param ref
* @param inObjStm
* @return a PdfIndirectObject
* @throws IOException
*/
public PdfIndirectObject addToBody(PdfObject object, PdfIndirectReference ref, boolean inObjStm) throws IOException {
PdfIndirectObject iobj = body.add(object, ref, inObjStm);
return iobj;
}
/**
* Use this method to add a PDF object to the PDF body.
* Use this method only if you know what you're doing!
* @param object
* @param refNumber
* @return a PdfIndirectObject
* @throws IOException
*/
public PdfIndirectObject addToBody(PdfObject object, int refNumber) throws IOException {
PdfIndirectObject iobj = body.add(object, refNumber);
return iobj;
}
/**
* Use this method to add a PDF object to the PDF body.
* Use this method only if you know what you're doing!
* @param object
* @param refNumber
* @param inObjStm
* @return a PdfIndirectObject
* @throws IOException
*/
public PdfIndirectObject addToBody(PdfObject object, int refNumber, boolean inObjStm) throws IOException {
PdfIndirectObject iobj = body.add(object, refNumber, inObjStm);
return iobj;
}
/**
* Use this to get an <CODE>PdfIndirectReference</CODE> for an object that
* will be created in the future.
* Use this method only if you know what you're doing!
* @return the <CODE>PdfIndirectReference</CODE>
*/
public PdfIndirectReference getPdfIndirectReference() {
return body.getPdfIndirectReference();
}
int getIndirectReferenceNumber() {
return body.getIndirectReferenceNumber();
}
/**
* Returns the outputStreamCounter.
* @return the outputStreamCounter
*/
OutputStreamCounter getOs() {
return os;
}
// PDF Catalog
/*
* The Catalog is also called the root object of the document.
* Whereas the Cross-Reference maps the objects number with the
* byte offset so that the viewer can find the objects, the
* Catalog tells the viewer the numbers of the objects needed
* to render the document.
*/
protected PdfDictionary getCatalog(PdfIndirectReference rootObj)
{
PdfDictionary catalog = pdf.getCatalog(rootObj);
// [F12] tagged PDF
if (tagged) {
try {
getStructureTreeRoot().buildTree();
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
catalog.put(PdfName.STRUCTTREEROOT, structureTreeRoot.getReference());
PdfDictionary mi = new PdfDictionary();
mi.put(PdfName.MARKED, PdfBoolean.PDFTRUE);
if (userProperties)
mi.put(PdfName.USERPROPERTIES, PdfBoolean.PDFTRUE);
catalog.put(PdfName.MARKINFO, mi);
}
// [F13] OCG
if (!documentOCG.isEmpty()) {
fillOCProperties(false);
catalog.put(PdfName.OCPROPERTIES, OCProperties);
}
return catalog;
}
/** Holds value of property extraCatalog this is used for Output Intents. */
protected PdfDictionary extraCatalog;
/**
* Sets extra keys to the catalog.
* @return the catalog to change
*/
public PdfDictionary getExtraCatalog() {
if (extraCatalog == null)
extraCatalog = new PdfDictionary();
return this.extraCatalog;
}
// PdfPages
/*
* The page root keeps the complete page tree of the document.
* There's an entry in the Catalog that refers to the root
* of the page tree, the page tree contains the references
* to pages and other page trees.
*/
/** The root of the page tree. */
protected PdfPages root = new PdfPages(this);
/** The PdfIndirectReference to the pages. */
protected ArrayList pageReferences = new ArrayList();
/** The current page number. */
protected int currentPageNumber = 1;
/**
* The value of the Tabs entry in the page dictionary.
* @since 2.1.5
*/
protected PdfName tabs = null;
/**
* Use this method to make sure the page tree has a linear structure
* (every leave is attached directly to the root).
* Use this method to allow page reordering with method reorderPages.
*/
public void setLinearPageMode() {
root.setLinearMode(null);
}
/**
* Use this method to reorder the pages in the document.
* A <CODE>null</CODE> argument value only returns the number of pages to process.
* It is advisable to issue a <CODE>Document.newPage()</CODE> before using this method.
* @return the total number of pages
* @param order an array with the new page sequence. It must have the
* same size as the number of pages.
* @throws DocumentException if all the pages are not present in the array
*/
public int reorderPages(int order[]) throws DocumentException {
return root.reorderPages(order);
}
/**
* Use this method to get a reference to a page existing or not.
* If the page does not exist yet the reference will be created
* in advance. If on closing the document, a page number greater
* than the total number of pages was requested, an exception
* is thrown.
* @param page the page number. The first page is 1
* @return the reference to the page
*/
public PdfIndirectReference getPageReference(int page) {
--page;
if (page < 0)
throw new IndexOutOfBoundsException("The page numbers start at 1.");
PdfIndirectReference ref;
if (page < pageReferences.size()) {
ref = (PdfIndirectReference)pageReferences.get(page);
if (ref == null) {
ref = body.getPdfIndirectReference();
pageReferences.set(page, ref);
}
}
else {
int empty = page - pageReferences.size();
for (int k = 0; k < empty; ++k)
pageReferences.add(null);
ref = body.getPdfIndirectReference();
pageReferences.add(ref);
}
return ref;
}
/**
* Gets the pagenumber of this document.
* This number can be different from the real pagenumber,
* if you have (re)set the page number previously.
* @return a page number
*/
public int getPageNumber() {
return pdf.getPageNumber();
}
PdfIndirectReference getCurrentPage() {
return getPageReference(currentPageNumber);
}
public int getCurrentPageNumber() {
return currentPageNumber;
}
/**
* Sets the value for the Tabs entry in the page tree.
* @param tabs Can be PdfName.R, PdfName.C or PdfName.S.
* Since the Adobe Extensions Level 3, it can also be PdfName.A
* or PdfName.W
* @since 2.1.5
*/
public void setTabs(PdfName tabs) {
this.tabs = tabs;
}
/**
* Returns the value to be used for the Tabs entry in the page tree.
* @since 2.1.5
*/
public PdfName getTabs() {
return tabs;
}
/**
* Adds some <CODE>PdfContents</CODE> to this Writer.
* <P>
* The document has to be open before you can begin to add content
* to the body of the document.
*
* @return a <CODE>PdfIndirectReference</CODE>
* @param page the <CODE>PdfPage</CODE> to add
* @param contents the <CODE>PdfContents</CODE> of the page
* @throws PdfException on error
*/
PdfIndirectReference add(PdfPage page, PdfContents contents) throws PdfException {
if (!open) {
throw new PdfException("The document isn't open.");
}
PdfIndirectObject object;
try {
object = addToBody(contents);
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
page.add(object.getIndirectReference());
// [U5]
if (group != null) {
page.put(PdfName.GROUP, group);
group = null;
}
else if (rgbTransparencyBlending) {
PdfDictionary pp = new PdfDictionary();
pp.put(PdfName.TYPE, PdfName.GROUP);
pp.put(PdfName.S, PdfName.TRANSPARENCY);
pp.put(PdfName.CS, PdfName.DEVICERGB);
page.put(PdfName.GROUP, pp);
}
root.addPage(page);
currentPageNumber++;
return null;
}
// page events
/*
* Page events are specific for iText, not for PDF.
* Upon specific events (for instance when a page starts
* or ends), the corresponding method in the page event
* implementation that is added to the writer is invoked.
*/
/** The <CODE>PdfPageEvent</CODE> for this document. */
private PdfPageEvent pageEvent;
/**
* Sets the <CODE>PdfPageEvent</CODE> for this document.
* @param event the <CODE>PdfPageEvent</CODE> for this document
*/
public void setPageEvent(PdfPageEvent event) {
if (event == null) this.pageEvent = null;
else if (this.pageEvent == null) this.pageEvent = event;
else if (this.pageEvent instanceof PdfPageEventForwarder) ((PdfPageEventForwarder)this.pageEvent).addPageEvent(event);
else {
PdfPageEventForwarder forward = new PdfPageEventForwarder();
forward.addPageEvent(this.pageEvent);
forward.addPageEvent(event);
this.pageEvent = forward;
}
}
/**
* Gets the <CODE>PdfPageEvent</CODE> for this document or <CODE>null</CODE>
* if none is set.
* @return the <CODE>PdfPageEvent</CODE> for this document or <CODE>null</CODE>
* if none is set
*/
public PdfPageEvent getPageEvent() {
return pageEvent;
}
// Open and Close methods + method that create the PDF
/** A number referring to the previous Cross-Reference Table. */
protected int prevxref = 0;
/**
* Signals that the <CODE>Document</CODE> has been opened and that
* <CODE>Elements</CODE> can be added.
* <P>
* When this method is called, the PDF-document header is
* written to the outputstream.
* @see com.lowagie.text.DocWriter#open()
*/
public void open() {
super.open();
try {
pdf_version.writeHeader(os);
body = new PdfBody(this);
if (pdfxConformance.isPdfX32002()) {
PdfDictionary sec = new PdfDictionary();
sec.put(PdfName.GAMMA, new PdfArray(new float[]{2.2f,2.2f,2.2f}));
sec.put(PdfName.MATRIX, new PdfArray(new float[]{0.4124f,0.2126f,0.0193f,0.3576f,0.7152f,0.1192f,0.1805f,0.0722f,0.9505f}));
sec.put(PdfName.WHITEPOINT, new PdfArray(new float[]{0.9505f,1f,1.089f}));
PdfArray arr = new PdfArray(PdfName.CALRGB);
arr.add(sec);
setDefaultColorspace(PdfName.DEFAULTRGB, addToBody(arr).getIndirectReference());
}
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
}
/**
* Signals that the <CODE>Document</CODE> was closed and that no other
* <CODE>Elements</CODE> will be added.
* <P>
* The pages-tree is built and written to the outputstream.
* A Catalog is constructed, as well as an Info-object,
* the reference table is composed and everything is written
* to the outputstream embedded in a Trailer.
* @see com.lowagie.text.DocWriter#close()
*/
public void close() {
if (open) {
if ((currentPageNumber - 1) != pageReferences.size())
throw new RuntimeException("The page " + pageReferences.size() +
" was requested but the document has only " + (currentPageNumber - 1) + " pages.");
pdf.close();
try {
addSharedObjectsToBody();
// add the root to the body
PdfIndirectReference rootRef = root.writePageTree();
// make the catalog-object and add it to the body
PdfDictionary catalog = getCatalog(rootRef);
// [C9] if there is XMP data to add: add it
if (xmpMetadata != null) {
PdfStream xmp = new PdfStream(xmpMetadata);
xmp.put(PdfName.TYPE, PdfName.METADATA);
xmp.put(PdfName.SUBTYPE, PdfName.XML);
if (crypto != null && !crypto.isMetadataEncrypted()) {
PdfArray ar = new PdfArray();
ar.add(PdfName.CRYPT);
xmp.put(PdfName.FILTER, ar);
}
catalog.put(PdfName.METADATA, body.add(xmp).getIndirectReference());
}
// [C10] make pdfx conformant
if (isPdfX()) {
pdfxConformance.completeInfoDictionary(getInfo());
pdfxConformance.completeExtraCatalog(getExtraCatalog());
}
// [C11] Output Intents
if (extraCatalog != null) {
catalog.mergeDifferent(extraCatalog);
}
writeOutlines(catalog, false);
// add the Catalog to the body
PdfIndirectObject indirectCatalog = addToBody(catalog, false);
// add the info-object to the body
PdfIndirectObject infoObj = addToBody(getInfo(), false);
// [F1] encryption
PdfIndirectReference encryption = null;
PdfObject fileID = null;
body.flushObjStm();
if (crypto != null) {
PdfIndirectObject encryptionObject = addToBody(crypto.getEncryptionDictionary(), false);
encryption = encryptionObject.getIndirectReference();
fileID = crypto.getFileID();
}
else
fileID = PdfEncryption.createInfoId(PdfEncryption.createDocumentId());
// write the cross-reference table of the body
body.writeCrossReferenceTable(os, indirectCatalog.getIndirectReference(),
infoObj.getIndirectReference(), encryption, fileID, prevxref);
// make the trailer
// [F2] full compression
if (fullCompression) {
os.write(getISOBytes("startxref\n"));
os.write(getISOBytes(String.valueOf(body.offset())));
os.write(getISOBytes("\n%%EOF\n"));
}
else {
PdfTrailer trailer = new PdfTrailer(body.size(),
body.offset(),
indirectCatalog.getIndirectReference(),
infoObj.getIndirectReference(),
encryption,
fileID, prevxref);
trailer.toPdf(this, os);
}
super.close();
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
}
}
protected void addSharedObjectsToBody() throws IOException {
// [F3] add the fonts
for (Iterator it = documentFonts.values().iterator(); it.hasNext();) {
FontDetails details = (FontDetails)it.next();
details.writeFont(this);
}
// [F4] add the form XObjects
for (Iterator it = formXObjects.values().iterator(); it.hasNext();) {
Object objs[] = (Object[])it.next();
PdfTemplate template = (PdfTemplate)objs[1];
if (template != null && template.getIndirectReference() instanceof PRIndirectReference)
continue;
if (template != null && template.getType() == PdfTemplate.TYPE_TEMPLATE) {
addToBody(template.getFormXObject(compressionLevel), template.getIndirectReference());
}
}
// [F5] add all the dependencies in the imported pages
for (Iterator it = importedPages.values().iterator(); it.hasNext();) {
currentPdfReaderInstance = (PdfReaderInstance)it.next();
currentPdfReaderInstance.writeAllPages();
}
currentPdfReaderInstance = null;
// [F6] add the spotcolors
for (Iterator it = documentColors.values().iterator(); it.hasNext();) {
ColorDetails color = (ColorDetails)it.next();
addToBody(color.getSpotColor(this), color.getIndirectReference());
}
// [F7] add the pattern
for (Iterator it = documentPatterns.keySet().iterator(); it.hasNext();) {
PdfPatternPainter pat = (PdfPatternPainter)it.next();
addToBody(pat.getPattern(compressionLevel), pat.getIndirectReference());
}
// [F8] add the shading patterns
for (Iterator it = documentShadingPatterns.keySet().iterator(); it.hasNext();) {
PdfShadingPattern shadingPattern = (PdfShadingPattern)it.next();
shadingPattern.addToBody();
}
// [F9] add the shadings
for (Iterator it = documentShadings.keySet().iterator(); it.hasNext();) {
PdfShading shading = (PdfShading)it.next();
shading.addToBody();
}
// [F10] add the extgstate
for (Iterator it = documentExtGState.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
PdfDictionary gstate = (PdfDictionary) entry.getKey();
PdfObject obj[] = (PdfObject[]) entry.getValue();
addToBody(gstate, (PdfIndirectReference)obj[1]);
}
// [F11] add the properties
for (Iterator it = documentProperties.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
Object prop = entry.getKey();
PdfObject[] obj = (PdfObject[]) entry.getValue();
if (prop instanceof PdfLayerMembership){
PdfLayerMembership layer = (PdfLayerMembership)prop;
addToBody(layer.getPdfObject(), layer.getRef());
}
else if ((prop instanceof PdfDictionary) && !(prop instanceof PdfLayer)){
addToBody((PdfDictionary)prop, (PdfIndirectReference)obj[1]);
}
}
// [F13] add the OCG layers
for (Iterator it = documentOCG.iterator(); it.hasNext();) {
PdfOCG layer = (PdfOCG)it.next();
addToBody(layer.getPdfObject(), layer.getRef());
}
}
// Root data for the PDF document (used when composing the Catalog)
// [C1] Outlines (bookmarks)
/**
* Use this method to get the root outline
* and construct bookmarks.
* @return the root outline
*/
public PdfOutline getRootOutline() {
return directContent.getRootOutline();
}
protected java.util.List newBookmarks;
/**
* Sets the bookmarks. The list structure is defined in
* {@link SimpleBookmark}.
* @param outlines the bookmarks or <CODE>null</CODE> to remove any
*/
public void setOutlines(java.util.List outlines) {
newBookmarks = outlines;
}
protected void writeOutlines(PdfDictionary catalog, boolean namedAsNames) throws IOException {
if (newBookmarks == null || newBookmarks.isEmpty())
return;
PdfDictionary top = new PdfDictionary();
PdfIndirectReference topRef = getPdfIndirectReference();
Object kids[] = SimpleBookmark.iterateOutlines(this, topRef, newBookmarks, namedAsNames);
top.put(PdfName.FIRST, (PdfIndirectReference)kids[0]);
top.put(PdfName.LAST, (PdfIndirectReference)kids[1]);
top.put(PdfName.COUNT, new PdfNumber(((Integer)kids[2]).intValue()));
addToBody(top, topRef);
catalog.put(PdfName.OUTLINES, topRef);
}
// [C2] PdfVersion interface
/** possible PDF version (header) */
public static final char VERSION_1_2 = '2';
/** possible PDF version (header) */
public static final char VERSION_1_3 = '3';
/** possible PDF version (header) */
public static final char VERSION_1_4 = '4';
/** possible PDF version (header) */
public static final char VERSION_1_5 = '5';
/** possible PDF version (header) */
public static final char VERSION_1_6 = '6';
/** possible PDF version (header) */
public static final char VERSION_1_7 = '7';
/** possible PDF version (catalog) */
public static final PdfName PDF_VERSION_1_2 = new PdfName("1.2");
/** possible PDF version (catalog) */
public static final PdfName PDF_VERSION_1_3 = new PdfName("1.3");
/** possible PDF version (catalog) */
public static final PdfName PDF_VERSION_1_4 = new PdfName("1.4");
/** possible PDF version (catalog) */
public static final PdfName PDF_VERSION_1_5 = new PdfName("1.5");
/** possible PDF version (catalog) */
public static final PdfName PDF_VERSION_1_6 = new PdfName("1.6");
/** possible PDF version (catalog) */
public static final PdfName PDF_VERSION_1_7 = new PdfName("1.7");
/** Stores the version information for the header and the catalog. */
protected PdfVersionImp pdf_version = new PdfVersionImp();
/** @see com.lowagie.text.pdf.interfaces.PdfVersion#setPdfVersion(char) */
public void setPdfVersion(char version) {
pdf_version.setPdfVersion(version);
}
/** @see com.lowagie.text.pdf.interfaces.PdfVersion#setAtLeastPdfVersion(char) */
public void setAtLeastPdfVersion(char version) {
pdf_version.setAtLeastPdfVersion(version);
}
/** @see com.lowagie.text.pdf.interfaces.PdfVersion#setPdfVersion(com.lowagie.text.pdf.PdfName) */
public void setPdfVersion(PdfName version) {
pdf_version.setPdfVersion(version);
}
/**
* @see com.lowagie.text.pdf.interfaces.PdfVersion#addDeveloperExtension(com.lowagie.text.pdf.PdfDeveloperExtension)
* @since 2.1.6
*/
public void addDeveloperExtension(PdfDeveloperExtension de) {
pdf_version.addDeveloperExtension(de);
}
/**
* Returns the version information.
*/
PdfVersionImp getPdfVersion() {
return pdf_version;
}
// [C3] PdfViewerPreferences interface
// page layout (section 13.1.1 of "iText in Action")
/** A viewer preference */
public static final int PageLayoutSinglePage = 1;
/** A viewer preference */
public static final int PageLayoutOneColumn = 2;
/** A viewer preference */
public static final int PageLayoutTwoColumnLeft = 4;
/** A viewer preference */
public static final int PageLayoutTwoColumnRight = 8;
/** A viewer preference */
public static final int PageLayoutTwoPageLeft = 16;
/** A viewer preference */
public static final int PageLayoutTwoPageRight = 32;
// page mode (section 13.1.2 of "iText in Action")
/** A viewer preference */
public static final int PageModeUseNone = 64;
/** A viewer preference */
public static final int PageModeUseOutlines = 128;
/** A viewer preference */
public static final int PageModeUseThumbs = 256;
/** A viewer preference */
public static final int PageModeFullScreen = 512;
/** A viewer preference */
public static final int PageModeUseOC = 1024;
/** A viewer preference */
public static final int PageModeUseAttachments = 2048;
// values for setting viewer preferences in iText versions older than 2.x
/** A viewer preference */
public static final int HideToolbar = 1 << 12;
/** A viewer preference */
public static final int HideMenubar = 1 << 13;
/** A viewer preference */
public static final int HideWindowUI = 1 << 14;
/** A viewer preference */
public static final int FitWindow = 1 << 15;
/** A viewer preference */
public static final int CenterWindow = 1 << 16;
/** A viewer preference */
public static final int DisplayDocTitle = 1 << 17;
/** A viewer preference */
public static final int NonFullScreenPageModeUseNone = 1 << 18;
/** A viewer preference */
public static final int NonFullScreenPageModeUseOutlines = 1 << 19;
/** A viewer preference */
public static final int NonFullScreenPageModeUseThumbs = 1 << 20;
/** A viewer preference */
public static final int NonFullScreenPageModeUseOC = 1 << 21;
/** A viewer preference */
public static final int DirectionL2R = 1 << 22;
/** A viewer preference */
public static final int DirectionR2L = 1 << 23;
/** A viewer preference */
public static final int PrintScalingNone = 1 << 24;
/** @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#setViewerPreferences(int) */
public void setViewerPreferences(int preferences) {
pdf.setViewerPreferences(preferences);
}
/** @see com.lowagie.text.pdf.interfaces.PdfViewerPreferences#addViewerPreference(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject) */
public void addViewerPreference(PdfName key, PdfObject value) {
pdf.addViewerPreference(key, value);
}
// [C4] Page labels
/**
* Use this method to add page labels
* @param pageLabels the page labels
*/
public void setPageLabels(PdfPageLabels pageLabels) {
pdf.setPageLabels(pageLabels);
}
// [C5] named objects: named destinations, javascript, embedded files
/**
* Use this method to add a JavaScript action at the document level.
* When the document opens, all this JavaScript runs.
* @param js The JavaScript action
*/
public void addJavaScript(PdfAction js) {
pdf.addJavaScript(js);
}
/**
* Use this method to add a JavaScript action at the document level.
* When the document opens, all this JavaScript runs.
* @param code the JavaScript code
* @param unicode select JavaScript unicode. Note that the internal
* Acrobat JavaScript engine does not support unicode,
* so this may or may not work for you
*/
public void addJavaScript(String code, boolean unicode) {
addJavaScript(PdfAction.javaScript(code, this, unicode));
}
/**
* Use this method to adds a JavaScript action at the document level.
* When the document opens, all this JavaScript runs.
* @param code the JavaScript code
*/
public void addJavaScript(String code) {
addJavaScript(code, false);
}
/**
* Use this method to add a JavaScript action at the document level.
* When the document opens, all this JavaScript runs.
* @param name The name of the JS Action in the name tree
* @param js The JavaScript action
*/
public void addJavaScript(String name, PdfAction js) {
pdf.addJavaScript(name, js);
}
/**
* Use this method to add a JavaScript action at the document level.
* When the document opens, all this JavaScript runs.
* @param name The name of the JS Action in the name tree
* @param code the JavaScript code
* @param unicode select JavaScript unicode. Note that the internal
* Acrobat JavaScript engine does not support unicode,
* so this may or may not work for you
*/
public void addJavaScript(String name, String code, boolean unicode) {
addJavaScript(name, PdfAction.javaScript(code, this, unicode));
}
/**
* Use this method to adds a JavaScript action at the document level.
* When the document opens, all this JavaScript runs.
* @param name The name of the JS Action in the name tree
* @param code the JavaScript code
*/
public void addJavaScript(String name, String code) {
addJavaScript(name, code, false);
}
/**
* Use this method to add a file attachment at the document level.
* @param description the file description
* @param fileStore an array with the file. If it's <CODE>null</CODE>
* the file will be read from the disk
* @param file the path to the file. It will only be used if
* <CODE>fileStore</CODE> is not <CODE>null</CODE>
* @param fileDisplay the actual file name stored in the pdf
* @throws IOException on error
*/
public void addFileAttachment(String description, byte fileStore[], String file, String fileDisplay) throws IOException {
addFileAttachment(description, PdfFileSpecification.fileEmbedded(this, file, fileDisplay, fileStore));
}
/**
* Use this method to add a file attachment at the document level.
* @param description the file description
* @param fs the file specification
*/
public void addFileAttachment(String description, PdfFileSpecification fs) throws IOException {
pdf.addFileAttachment(description, fs);
}
/**
* Use this method to add a file attachment at the document level.
* @param fs the file specification
*/
public void addFileAttachment(PdfFileSpecification fs) throws IOException {
addFileAttachment(null, fs);
}
// [C6] Actions (open and additional)
/** action value */
public static final PdfName DOCUMENT_CLOSE = PdfName.WC;
/** action value */
public static final PdfName WILL_SAVE = PdfName.WS;
/** action value */
public static final PdfName DID_SAVE = PdfName.DS;
/** action value */
public static final PdfName WILL_PRINT = PdfName.WP;
/** action value */
public static final PdfName DID_PRINT = PdfName.DP;
/** @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setOpenAction(java.lang.String) */
public void setOpenAction(String name) {
pdf.setOpenAction(name);
}
/** @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setOpenAction(com.lowagie.text.pdf.PdfAction) */
public void setOpenAction(PdfAction action) {
pdf.setOpenAction(action);
}
/** @see com.lowagie.text.pdf.interfaces.PdfDocumentActions#setAdditionalAction(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfAction) */
public void setAdditionalAction(PdfName actionType, PdfAction action) throws DocumentException {
if (!(actionType.equals(DOCUMENT_CLOSE) ||
actionType.equals(WILL_SAVE) ||
actionType.equals(DID_SAVE) ||
actionType.equals(WILL_PRINT) ||
actionType.equals(DID_PRINT))) {
throw new DocumentException("Invalid additional action type: " + actionType.toString());
}
pdf.addAdditionalAction(actionType, action);
}
// [C7] portable collections
/**
* Use this method to add the Collection dictionary.
* @param collection a dictionary of type PdfCollection
*/
public void setCollection(PdfCollection collection) {
setAtLeastPdfVersion(VERSION_1_7);
pdf.setCollection(collection);
}
// [C8] AcroForm
/** signature value */
public static final int SIGNATURE_EXISTS = 1;
/** signature value */
public static final int SIGNATURE_APPEND_ONLY = 2;
/** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#getAcroForm() */
public PdfAcroForm getAcroForm() {
return pdf.getAcroForm();
}
/** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#addAnnotation(com.lowagie.text.pdf.PdfAnnotation) */
public void addAnnotation(PdfAnnotation annot) {
pdf.addAnnotation(annot);
}
void addAnnotation(PdfAnnotation annot, int page) {
addAnnotation(annot);
}
/** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#addCalculationOrder(com.lowagie.text.pdf.PdfFormField) */
public void addCalculationOrder(PdfFormField annot) {
pdf.addCalculationOrder(annot);
}
/** @see com.lowagie.text.pdf.interfaces.PdfAnnotations#setSigFlags(int) */
public void setSigFlags(int f) {
pdf.setSigFlags(f);
}
// [C9] Metadata
/** XMP Metadata for the document. */
protected byte[] xmpMetadata = null;
/**
* Use this method to set the XMP Metadata.
* @param xmpMetadata The xmpMetadata to set.
*/
public void setXmpMetadata(byte[] xmpMetadata) {
this.xmpMetadata = xmpMetadata;
}
/**
* Use this method to set the XMP Metadata for each page.
* @param xmpMetadata The xmpMetadata to set.
*/
public void setPageXmpMetadata(byte[] xmpMetadata) {
pdf.setXmpMetadata(xmpMetadata);
}
/**
* Use this method to creates XMP Metadata based
* on the metadata in the PdfDocument.
*/
public void createXmpMetadata() {
setXmpMetadata(createXmpMetadataBytes());
}
/**
* @return an XmpMetadata byte array
*/
private byte[] createXmpMetadataBytes() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
XmpWriter xmp = new XmpWriter(baos, pdf.getInfo(), pdfxConformance.getPDFXConformance());
xmp.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
return baos.toByteArray();
}
// [C10] PDFX Conformance
/** A PDF/X level. */
public static final int PDFXNONE = 0;
/** A PDF/X level. */
public static final int PDFX1A2001 = 1;
/** A PDF/X level. */
public static final int PDFX32002 = 2;
/** PDFA-1A level. */
public static final int PDFA1A = 3;
/** PDFA-1B level. */
public static final int PDFA1B = 4;
/** Stores the PDF/X level. */
private PdfXConformanceImp pdfxConformance = new PdfXConformanceImp();
/** @see com.lowagie.text.pdf.interfaces.PdfXConformance#setPDFXConformance(int) */
public void setPDFXConformance(int pdfx) {
if (pdfxConformance.getPDFXConformance() == pdfx)
return;
if (pdf.isOpen())
throw new PdfXConformanceException("PDFX conformance can only be set before opening the document.");
if (crypto != null)
throw new PdfXConformanceException("A PDFX conforming document cannot be encrypted.");
if (pdfx == PDFA1A || pdfx == PDFA1B)
setPdfVersion(VERSION_1_4);
else if (pdfx != PDFXNONE)
setPdfVersion(VERSION_1_3);
pdfxConformance.setPDFXConformance(pdfx);
}
/** @see com.lowagie.text.pdf.interfaces.PdfXConformance#getPDFXConformance() */
public int getPDFXConformance() {
return pdfxConformance.getPDFXConformance();
}
/** @see com.lowagie.text.pdf.interfaces.PdfXConformance#isPdfX() */
public boolean isPdfX() {
return pdfxConformance.isPdfX();
}
// [C11] Output intents
/**
* Sets the values of the output intent dictionary. Null values are allowed to
* suppress any key.
*
* @param outputConditionIdentifier a value
* @param outputCondition a value, "PDFA/A" to force GTS_PDFA1, otherwise cued by pdfxConformance.
* @param registryName a value
* @param info a value
* @param colorProfile a value
* @since 2.1.5
* @throws IOException on error
*/
public void setOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, ICC_Profile colorProfile) throws IOException {
getExtraCatalog();
PdfDictionary out = new PdfDictionary(PdfName.OUTPUTINTENT);
if (outputCondition != null)
out.put(PdfName.OUTPUTCONDITION, new PdfString(outputCondition, PdfObject.TEXT_UNICODE));
if (outputConditionIdentifier != null)
out.put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString(outputConditionIdentifier, PdfObject.TEXT_UNICODE));
if (registryName != null)
out.put(PdfName.REGISTRYNAME, new PdfString(registryName, PdfObject.TEXT_UNICODE));
if (info != null)
out.put(PdfName.INFO, new PdfString(info, PdfObject.TEXT_UNICODE));
if (colorProfile != null) {
PdfStream stream = new PdfICCBased(colorProfile, compressionLevel);
out.put(PdfName.DESTOUTPUTPROFILE, addToBody(stream).getIndirectReference());
}
PdfName intentSubtype;
if (pdfxConformance.isPdfA1() || "PDFA/1".equals(outputCondition)) {
intentSubtype = PdfName.GTS_PDFA1;
}
else {
intentSubtype = PdfName.GTS_PDFX;
}
out.put(PdfName.S, intentSubtype);
extraCatalog.put(PdfName.OUTPUTINTENTS, new PdfArray(out));
}
/**
* Sets the values of the output intent dictionary. Null values are allowed to
* suppress any key.
*
* Prefer the <CODE>ICC_Profile</CODE>-based version of this method.
* @param outputConditionIdentifier a value
* @param outputCondition a value, "PDFA/A" to force GTS_PDFA1, otherwise cued by pdfxConformance.
* @param registryName a value
* @param info a value
* @param destOutputProfile a value
* @since 1.x
*
* @throws IOException
*/
public void setOutputIntents(String outputConditionIdentifier, String outputCondition, String registryName, String info, byte destOutputProfile[]) throws IOException {
ICC_Profile colorProfile = (destOutputProfile == null) ? null : ICC_Profile.getInstance(destOutputProfile);
setOutputIntents(outputConditionIdentifier, outputCondition, registryName, info, colorProfile);
}
/**
* Use this method to copy the output intent dictionary
* from another document to this one.
* @param reader the other document
* @param checkExistence <CODE>true</CODE> to just check for the existence of a valid output intent
* dictionary, <CODE>false</CODE> to insert the dictionary if it exists
* @throws IOException on error
* @return <CODE>true</CODE> if the output intent dictionary exists, <CODE>false</CODE>
* otherwise
*/
public boolean setOutputIntents(PdfReader reader, boolean checkExistence) throws IOException {
PdfDictionary catalog = reader.getCatalog();
PdfArray outs = catalog.getAsArray(PdfName.OUTPUTINTENTS);
if (outs == null)
return false;
if (outs.isEmpty())
return false;
PdfDictionary out = outs.getAsDict(0);
PdfObject obj = PdfReader.getPdfObject(out.get(PdfName.S));
if (obj == null || !PdfName.GTS_PDFX.equals(obj))
return false;
if (checkExistence)
return true;
PRStream stream = (PRStream)PdfReader.getPdfObject(out.get(PdfName.DESTOUTPUTPROFILE));
byte destProfile[] = null;
if (stream != null) {
destProfile = PdfReader.getStreamBytes(stream);
}
setOutputIntents(getNameString(out, PdfName.OUTPUTCONDITIONIDENTIFIER), getNameString(out, PdfName.OUTPUTCONDITION),
getNameString(out, PdfName.REGISTRYNAME), getNameString(out, PdfName.INFO), destProfile);
return true;
}
private static String getNameString(PdfDictionary dic, PdfName key) {
PdfObject obj = PdfReader.getPdfObject(dic.get(key));
if (obj == null || !obj.isString())
return null;
return ((PdfString)obj).toUnicodeString();
}
// PDF Objects that have an impact on the PDF body
// [F1] PdfEncryptionSettings interface
// types of encryption
/** Type of encryption */
public static final int STANDARD_ENCRYPTION_40 = 0;
/** Type of encryption */
public static final int STANDARD_ENCRYPTION_128 = 1;
/** Type of encryption */
public static final int ENCRYPTION_AES_128 = 2;
/** Mask to separate the encryption type from the encryption mode. */
static final int ENCRYPTION_MASK = 7;
/** Add this to the mode to keep the metadata in clear text */
public static final int DO_NOT_ENCRYPT_METADATA = 8;
/**
* Add this to the mode to keep encrypt only the embedded files.
* @since 2.1.3
*/
public static final int EMBEDDED_FILES_ONLY = 24;
// permissions
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_PRINTING = 4 + 2048;
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_MODIFY_CONTENTS = 8;
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_COPY = 16;
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_MODIFY_ANNOTATIONS = 32;
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_FILL_IN = 256;
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_SCREENREADERS = 512;
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_ASSEMBLY = 1024;
/** The operation permitted when the document is opened with the user password
*
* @since 2.0.7
*/
public static final int ALLOW_DEGRADED_PRINTING = 4;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_PRINTING} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowPrinting = ALLOW_PRINTING;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_MODIFY_CONTENTS} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowModifyContents = ALLOW_MODIFY_CONTENTS;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_COPY} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowCopy = ALLOW_COPY;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_MODIFY_ANNOTATIONS} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowModifyAnnotations = ALLOW_MODIFY_ANNOTATIONS;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_FILL_IN} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowFillIn = ALLOW_FILL_IN;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_SCREENREADERS} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowScreenReaders = ALLOW_SCREENREADERS;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_ASSEMBLY} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowAssembly = ALLOW_ASSEMBLY;
/** @deprecated As of iText 2.0.7, use {@link #ALLOW_DEGRADED_PRINTING} instead. Scheduled for removal at or after 2.2.0 */
public static final int AllowDegradedPrinting = ALLOW_DEGRADED_PRINTING;
// Strength of the encryption (kept for historical reasons)
/** @deprecated As of iText 2.0.7, use {@link #STANDARD_ENCRYPTION_40} instead. Scheduled for removal at or after 2.2.0 */
public static final boolean STRENGTH40BITS = false;
/** @deprecated As of iText 2.0.7, use {@link #STANDARD_ENCRYPTION_128} instead. Scheduled for removal at or after 2.2.0 */
public static final boolean STRENGTH128BITS = true;
/** Contains the business logic for cryptography. */
protected PdfEncryption crypto;
PdfEncryption getEncryption() {
return crypto;
}
/** @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(byte[], byte[], int, int) */
public void setEncryption(byte userPassword[], byte ownerPassword[], int permissions, int encryptionType) throws DocumentException {
if (pdf.isOpen())
throw new DocumentException("Encryption can only be added before opening the document.");
crypto = new PdfEncryption();
crypto.setCryptoMode(encryptionType, 0);
crypto.setupAllKeys(userPassword, ownerPassword, permissions);
}
/** @see com.lowagie.text.pdf.interfaces.PdfEncryptionSettings#setEncryption(java.security.cert.Certificate[], int[], int) */
public void setEncryption(Certificate[] certs, int[] permissions, int encryptionType) throws DocumentException {
if (pdf.isOpen())
throw new DocumentException("Encryption can only be added before opening the document.");
crypto = new PdfEncryption();
if (certs != null) {
for (int i=0; i < certs.length; i++) {
crypto.addRecipient(certs[i], permissions[i]);
}
}
crypto.setCryptoMode(encryptionType, 0);
crypto.getEncryptionDictionary();
}
/**
* Sets the encryption options for this document. The userPassword and the
* ownerPassword can be null or have zero length. In this case the ownerPassword
* is replaced by a random string. The open permissions for the document can be
* AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
* AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
* The permissions can be combined by ORing them.
* @param userPassword the user password. Can be null or empty
* @param ownerPassword the owner password. Can be null or empty
* @param permissions the user permissions
* @param strength128Bits <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length
* @throws DocumentException if the document is already open
* @deprecated As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0
*/
public void setEncryption(byte userPassword[], byte ownerPassword[], int permissions, boolean strength128Bits) throws DocumentException {
setEncryption(userPassword, ownerPassword, permissions, strength128Bits ? STANDARD_ENCRYPTION_128 : STANDARD_ENCRYPTION_40);
}
/**
* Sets the encryption options for this document. The userPassword and the
* ownerPassword can be null or have zero length. In this case the ownerPassword
* is replaced by a random string. The open permissions for the document can be
* AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
* AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
* The permissions can be combined by ORing them.
* @param strength <code>true</code> for 128 bit key length, <code>false</code> for 40 bit key length
* @param userPassword the user password. Can be null or empty
* @param ownerPassword the owner password. Can be null or empty
* @param permissions the user permissions
* @throws DocumentException if the document is already open
* @deprecated As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0
*/
public void setEncryption(boolean strength, String userPassword, String ownerPassword, int permissions) throws DocumentException {
setEncryption(getISOBytes(userPassword), getISOBytes(ownerPassword), permissions, strength ? STANDARD_ENCRYPTION_128 : STANDARD_ENCRYPTION_40);
}
/**
* Sets the encryption options for this document. The userPassword and the
* ownerPassword can be null or have zero length. In this case the ownerPassword
* is replaced by a random string. The open permissions for the document can be
* AllowPrinting, AllowModifyContents, AllowCopy, AllowModifyAnnotations,
* AllowFillIn, AllowScreenReaders, AllowAssembly and AllowDegradedPrinting.
* The permissions can be combined by ORing them.
* @param encryptionType the type of encryption. It can be one of STANDARD_ENCRYPTION_40, STANDARD_ENCRYPTION_128 or ENCRYPTION_AES128.
* Optionally DO_NOT_ENCRYPT_METADATA can be ored to output the metadata in cleartext
* @param userPassword the user password. Can be null or empty
* @param ownerPassword the owner password. Can be null or empty
* @param permissions the user permissions
* @throws DocumentException if the document is already open
* @deprecated As of iText 2.0.3, replaced by (@link #setEncryption(byte[], byte[], int, int)}. Scheduled for removal at or after 2.2.0
*/
public void setEncryption(int encryptionType, String userPassword, String ownerPassword, int permissions) throws DocumentException {
setEncryption(getISOBytes(userPassword), getISOBytes(ownerPassword), permissions, encryptionType);
}
// [F2] compression
/** Holds value of property fullCompression. */
protected boolean fullCompression = false;
/**
* Use this method to find out if 1.5 compression is on.
* @return the 1.5 compression status
*/
public boolean isFullCompression() {
return this.fullCompression;
}
/**
* Use this method to set the document's compression to the
* PDF 1.5 mode with object streams and xref streams.
* It can be set at any time but once set it can't be unset.
* <p>
* If set before opening the document it will also set the pdf version to 1.5.
*/
public void setFullCompression() {
this.fullCompression = true;
setAtLeastPdfVersion(VERSION_1_5);
}
/**
* The compression level of the content streams.
* @since 2.1.3
*/
protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION;
/**
* Returns the compression level used for streams written by this writer.
* @return the compression level (0 = best speed, 9 = best compression, -1 is default)
* @since 2.1.3
*/
public int getCompressionLevel() {
return compressionLevel;
}
/**
* Sets the compression level to be used for streams written by this writer.
* @param compressionLevel a value between 0 (best speed) and 9 (best compression)
* @since 2.1.3
*/
public void setCompressionLevel(int compressionLevel) {
if (compressionLevel < PdfStream.NO_COMPRESSION || compressionLevel > PdfStream.BEST_COMPRESSION)
this.compressionLevel = PdfStream.DEFAULT_COMPRESSION;
else
this.compressionLevel = compressionLevel;
}
// [F3] adding fonts
/** The fonts of this document */
protected LinkedHashMap documentFonts = new LinkedHashMap();
/** The font number counter for the fonts in the document. */
protected int fontNumber = 1;
/**
* Adds a <CODE>BaseFont</CODE> to the document but not to the page resources.
* It is used for templates.
* @param bf the <CODE>BaseFont</CODE> to add
* @return an <CODE>Object[]</CODE> where position 0 is a <CODE>PdfName</CODE>
* and position 1 is an <CODE>PdfIndirectReference</CODE>
*/
FontDetails addSimple(BaseFont bf) {
if (bf.getFontType() == BaseFont.FONT_TYPE_DOCUMENT) {
return new FontDetails(new PdfName("F" + (fontNumber++)), ((DocumentFont)bf).getIndirectReference(), bf);
}
FontDetails ret = (FontDetails)documentFonts.get(bf);
if (ret == null) {
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_FONT, bf);
ret = new FontDetails(new PdfName("F" + (fontNumber++)), body.getPdfIndirectReference(), bf);
documentFonts.put(bf, ret);
}
return ret;
}
void eliminateFontSubset(PdfDictionary fonts) {
for (Iterator it = documentFonts.values().iterator(); it.hasNext();) {
FontDetails ft = (FontDetails)it.next();
if (fonts.get(ft.getFontName()) != null)
ft.setSubset(false);
}
}
// [F4] adding (and releasing) form XObjects
/** The form XObjects in this document. The key is the xref and the value
is Object[]{PdfName, template}.*/
protected HashMap formXObjects = new HashMap();
/** The name counter for the form XObjects name. */
protected int formXObjectsCounter = 1;
/**
* Adds a template to the document but not to the page resources.
* @param template the template to add
* @param forcedName the template name, rather than a generated one. Can be null
* @return the <CODE>PdfName</CODE> for this template
*/
PdfName addDirectTemplateSimple(PdfTemplate template, PdfName forcedName) {
PdfIndirectReference ref = template.getIndirectReference();
Object obj[] = (Object[])formXObjects.get(ref);
PdfName name = null;
try {
if (obj == null) {
if (forcedName == null) {
name = new PdfName("Xf" + formXObjectsCounter);
++formXObjectsCounter;
}
else
name = forcedName;
if (template.getType() == PdfTemplate.TYPE_IMPORTED) {
// If we got here from PdfCopy we'll have to fill importedPages
PdfImportedPage ip = (PdfImportedPage)template;
PdfReader r = ip.getPdfReaderInstance().getReader();
if (!importedPages.containsKey(r)) {
importedPages.put(r, ip.getPdfReaderInstance());
}
template = null;
}
formXObjects.put(ref, new Object[]{name, template});
}
else
name = (PdfName)obj[0];
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
return name;
}
/**
* Use this method to releases the memory used by a template.
* This method writes the template to the output.
* The template can still be added to any content
* but changes to the template itself won't have any effect.
* @param tp the template to release
* @throws IOException on error
*/
public void releaseTemplate(PdfTemplate tp) throws IOException {
PdfIndirectReference ref = tp.getIndirectReference();
Object[] objs = (Object[])formXObjects.get(ref);
if (objs == null || objs[1] == null)
return;
PdfTemplate template = (PdfTemplate)objs[1];
if (template.getIndirectReference() instanceof PRIndirectReference)
return;
if (template.getType() == PdfTemplate.TYPE_TEMPLATE) {
addToBody(template.getFormXObject(compressionLevel), template.getIndirectReference());
objs[1] = null;
}
}
// [F5] adding pages imported form other PDF documents
protected HashMap importedPages = new HashMap();
/**
* Use this method to get a page from other PDF document.
* The page can be used as any other PdfTemplate.
* Note that calling this method more than once with the same parameters
* will retrieve the same object.
* @param reader the PDF document where the page is
* @param pageNumber the page number. The first page is 1
* @return the template representing the imported page
*/
public PdfImportedPage getImportedPage(PdfReader reader, int pageNumber) {
PdfReaderInstance inst = (PdfReaderInstance)importedPages.get(reader);
if (inst == null) {
inst = reader.getPdfReaderInstance(this);
importedPages.put(reader, inst);
}
return inst.getImportedPage(pageNumber);
}
/**
* Use this method to writes the reader to the document
* and free the memory used by it.
* The main use is when concatenating multiple documents
* to keep the memory usage restricted to the current
* appending document.
* @param reader the <CODE>PdfReader</CODE> to free
* @throws IOException on error
*/
public void freeReader(PdfReader reader) throws IOException {
currentPdfReaderInstance = (PdfReaderInstance)importedPages.get(reader);
if (currentPdfReaderInstance == null)
return;
currentPdfReaderInstance.writeAllPages();
currentPdfReaderInstance = null;
importedPages.remove(reader);
}
/**
* Use this method to gets the current document size.
* This size only includes the data already written
* to the output stream, it does not include templates or fonts.
* It is useful if used with <CODE>freeReader()</CODE>
* when concatenating many documents and an idea of
* the current size is needed.
* @return the approximate size without fonts or templates
*/
public int getCurrentDocumentSize() {
return body.offset() + body.size() * 20 + 0x48;
}
protected PdfReaderInstance currentPdfReaderInstance;
protected int getNewObjectNumber(PdfReader reader, int number, int generation) {
return currentPdfReaderInstance.getNewObjectNumber(number, generation);
}
RandomAccessFileOrArray getReaderFile(PdfReader reader) {
return currentPdfReaderInstance.getReaderFile();
}
// [F6] spot colors
/** The colors of this document */
protected HashMap documentColors = new HashMap();
/** The color number counter for the colors in the document. */
protected int colorNumber = 1;
PdfName getColorspaceName() {
return new PdfName("CS" + (colorNumber++));
}
/**
* Adds a <CODE>SpotColor</CODE> to the document but not to the page resources.
* @param spc the <CODE>SpotColor</CODE> to add
* @return an <CODE>Object[]</CODE> where position 0 is a <CODE>PdfName</CODE>
* and position 1 is an <CODE>PdfIndirectReference</CODE>
*/
ColorDetails addSimple(PdfSpotColor spc) {
ColorDetails ret = (ColorDetails)documentColors.get(spc);
if (ret == null) {
ret = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), spc);
documentColors.put(spc, ret);
}
return ret;
}
// [F7] document patterns
/** The patterns of this document */
protected HashMap documentPatterns = new HashMap();
/** The pattern number counter for the colors in the document. */
protected int patternNumber = 1;
PdfName addSimplePattern(PdfPatternPainter painter) {
PdfName name = (PdfName)documentPatterns.get(painter);
try {
if ( name == null ) {
name = new PdfName("P" + patternNumber);
++patternNumber;
documentPatterns.put(painter, name);
}
} catch (Exception e) {
throw new ExceptionConverter(e);
}
return name;
}
// [F8] shading patterns
protected HashMap documentShadingPatterns = new HashMap();
void addSimpleShadingPattern(PdfShadingPattern shading) {
if (!documentShadingPatterns.containsKey(shading)) {
shading.setName(patternNumber);
++patternNumber;
documentShadingPatterns.put(shading, null);
addSimpleShading(shading.getShading());
}
}
// [F9] document shadings
protected HashMap documentShadings = new HashMap();
void addSimpleShading(PdfShading shading) {
if (!documentShadings.containsKey(shading)) {
documentShadings.put(shading, null);
shading.setName(documentShadings.size());
}
}
// [F10] extended graphics state (for instance for transparency)
protected HashMap documentExtGState = new HashMap();
PdfObject[] addSimpleExtGState(PdfDictionary gstate) {
if (!documentExtGState.containsKey(gstate)) {
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_GSTATE, gstate);
documentExtGState.put(gstate, new PdfObject[]{new PdfName("GS" + (documentExtGState.size() + 1)), getPdfIndirectReference()});
}
return (PdfObject[])documentExtGState.get(gstate);
}
// [F11] adding properties (OCG, marked content)
protected HashMap documentProperties = new HashMap();
PdfObject[] addSimpleProperty(Object prop, PdfIndirectReference refi) {
if (!documentProperties.containsKey(prop)) {
if (prop instanceof PdfOCG)
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_LAYER, null);
documentProperties.put(prop, new PdfObject[]{new PdfName("Pr" + (documentProperties.size() + 1)), refi});
}
return (PdfObject[])documentProperties.get(prop);
}
boolean propertyExists(Object prop) {
return documentProperties.containsKey(prop);
}
// [F12] tagged PDF
protected boolean tagged = false;
protected PdfStructureTreeRoot structureTreeRoot;
/**
* Mark this document for tagging. It must be called before open.
*/
public void setTagged() {
if (open)
throw new IllegalArgumentException("Tagging must be set before opening the document.");
tagged = true;
}
/**
* Check if the document is marked for tagging.
* @return <CODE>true</CODE> if the document is marked for tagging
*/
public boolean isTagged() {
return tagged;
}
/**
* Gets the structure tree root. If the document is not marked for tagging it will return <CODE>null</CODE>.
* @return the structure tree root
*/
public PdfStructureTreeRoot getStructureTreeRoot() {
if (tagged && structureTreeRoot == null)
structureTreeRoot = new PdfStructureTreeRoot(this);
return structureTreeRoot;
}
// [F13] Optional Content Groups
/** A hashSet containing all the PdfLayer objects. */
protected HashSet documentOCG = new HashSet();
/** An array list used to define the order of an OCG tree. */
protected ArrayList documentOCGorder = new ArrayList();
/** The OCProperties in a catalog dictionary. */
protected PdfOCProperties OCProperties;
/** The RBGroups array in an OCG dictionary */
protected PdfArray OCGRadioGroup = new PdfArray();
/**
* The locked array in an OCG dictionary
* @since 2.1.2
*/
protected PdfArray OCGLocked = new PdfArray();
/**
* Use this method to get the <B>Optional Content Properties Dictionary</B>.
* Each call fills the dictionary with the current layer state.
* It's advisable to only call this method right before close
* and do any modifications at that time.
* @return the Optional Content Properties Dictionary
*/
public PdfOCProperties getOCProperties() {
fillOCProperties(true);
return OCProperties;
}
/**
* Use this method to set a collection of optional content groups
* whose states are intended to follow a "radio button" paradigm.
* That is, the state of at most one optional content group
* in the array should be ON at a time: if one group is turned
* ON, all others must be turned OFF.
* @param group the radio group
*/
public void addOCGRadioGroup(ArrayList group) {
PdfArray ar = new PdfArray();
for (int k = 0; k < group.size(); ++k) {
PdfLayer layer = (PdfLayer)group.get(k);
if (layer.getTitle() == null)
ar.add(layer.getRef());
}
if (ar.size() == 0)
return;
OCGRadioGroup.add(ar);
}
/**
* Use this method to lock an optional content group.
* The state of a locked group cannot be changed through the user interface
* of a viewer application. Producers can use this entry to prevent the visibility
* of content that depends on these groups from being changed by users.
* @param layer the layer that needs to be added to the array of locked OCGs
* @since 2.1.2
*/
public void lockLayer(PdfLayer layer) {
OCGLocked.add(layer.getRef());
}
private static void getOCGOrder(PdfArray order, PdfLayer layer) {
if (!layer.isOnPanel())
return;
if (layer.getTitle() == null)
order.add(layer.getRef());
ArrayList children = layer.getChildren();
if (children == null)
return;
PdfArray kids = new PdfArray();
if (layer.getTitle() != null)
kids.add(new PdfString(layer.getTitle(), PdfObject.TEXT_UNICODE));
for (int k = 0; k < children.size(); ++k) {
getOCGOrder(kids, (PdfLayer)children.get(k));
}
if (kids.size() > 0)
order.add(kids);
}
private void addASEvent(PdfName event, PdfName category) {
PdfArray arr = new PdfArray();
for (Iterator it = documentOCG.iterator(); it.hasNext();) {
PdfLayer layer = (PdfLayer)it.next();
PdfDictionary usage = (PdfDictionary)layer.get(PdfName.USAGE);
if (usage != null && usage.get(category) != null)
arr.add(layer.getRef());
}
if (arr.size() == 0)
return;
PdfDictionary d = (PdfDictionary)OCProperties.get(PdfName.D);
PdfArray arras = (PdfArray)d.get(PdfName.AS);
if (arras == null) {
arras = new PdfArray();
d.put(PdfName.AS, arras);
}
PdfDictionary as = new PdfDictionary();
as.put(PdfName.EVENT, event);
as.put(PdfName.CATEGORY, new PdfArray(category));
as.put(PdfName.OCGS, arr);
arras.add(as);
}
/**
* @since 2.1.2
*/
protected void fillOCProperties(boolean erase) {
if (OCProperties == null)
OCProperties = new PdfOCProperties();
if (erase) {
OCProperties.remove(PdfName.OCGS);
OCProperties.remove(PdfName.D);
}
if (OCProperties.get(PdfName.OCGS) == null) {
PdfArray gr = new PdfArray();
for (Iterator it = documentOCG.iterator(); it.hasNext();) {
PdfLayer layer = (PdfLayer)it.next();
gr.add(layer.getRef());
}
OCProperties.put(PdfName.OCGS, gr);
}
if (OCProperties.get(PdfName.D) != null)
return;
ArrayList docOrder = new ArrayList(documentOCGorder);
for (Iterator it = docOrder.iterator(); it.hasNext();) {
PdfLayer layer = (PdfLayer)it.next();
if (layer.getParent() != null)
it.remove();
}
PdfArray order = new PdfArray();
for (Iterator it = docOrder.iterator(); it.hasNext();) {
PdfLayer layer = (PdfLayer)it.next();
getOCGOrder(order, layer);
}
PdfDictionary d = new PdfDictionary();
OCProperties.put(PdfName.D, d);
d.put(PdfName.ORDER, order);
PdfArray gr = new PdfArray();
for (Iterator it = documentOCG.iterator(); it.hasNext();) {
PdfLayer layer = (PdfLayer)it.next();
if (!layer.isOn())
gr.add(layer.getRef());
}
if (gr.size() > 0)
d.put(PdfName.OFF, gr);
if (OCGRadioGroup.size() > 0)
d.put(PdfName.RBGROUPS, OCGRadioGroup);
if (OCGLocked.size() > 0)
d.put(PdfName.LOCKED, OCGLocked);
addASEvent(PdfName.VIEW, PdfName.ZOOM);
addASEvent(PdfName.VIEW, PdfName.VIEW);
addASEvent(PdfName.PRINT, PdfName.PRINT);
addASEvent(PdfName.EXPORT, PdfName.EXPORT);
d.put(PdfName.LISTMODE, PdfName.VISIBLEPAGES);
}
void registerLayer(PdfOCG layer) {
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_LAYER, null);
if (layer instanceof PdfLayer) {
PdfLayer la = (PdfLayer)layer;
if (la.getTitle() == null) {
if (!documentOCG.contains(layer)) {
documentOCG.add(layer);
documentOCGorder.add(layer);
}
}
else {
documentOCGorder.add(layer);
}
}
else
throw new IllegalArgumentException("Only PdfLayer is accepted.");
}
// User methods to change aspects of the page
// [U1] page size
/**
* Use this method to get the size of the media box.
* @return a Rectangle
*/
public Rectangle getPageSize() {
return pdf.getPageSize();
}
/**
* Use this method to set the crop box.
* The crop box should not be rotated even if the page is rotated.
* This change only takes effect in the next page.
* @param crop the crop box
*/
public void setCropBoxSize(Rectangle crop) {
pdf.setCropBoxSize(crop);
}
/**
* Use this method to set the page box sizes.
* Allowed names are: "crop", "trim", "art" and "bleed".
* @param boxName the box size
* @param size the size
*/
public void setBoxSize(String boxName, Rectangle size) {
pdf.setBoxSize(boxName, size);
}
/**
* Use this method to get the size of a trim, art, crop or bleed box,
* or null if not defined.
* @param boxName crop, trim, art or bleed
*/
public Rectangle getBoxSize(String boxName) {
return pdf.getBoxSize(boxName);
}
// [U2] take care of empty pages
/**
* Use this method to make sure a page is added,
* even if it's empty. If you use setPageEmpty(false),
* invoking newPage() after a blank page will add a newPage.
* @param pageEmpty the state
*/
public void setPageEmpty(boolean pageEmpty) {
pdf.setPageEmpty(pageEmpty);
}
// [U3] page actions (open and close)
/** action value */
public static final PdfName PAGE_OPEN = PdfName.O;
/** action value */
public static final PdfName PAGE_CLOSE = PdfName.C;
/** @see com.lowagie.text.pdf.interfaces.PdfPageActions#setPageAction(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfAction) */
public void setPageAction(PdfName actionType, PdfAction action) throws DocumentException {
if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE))
throw new DocumentException("Invalid page additional action type: " + actionType.toString());
pdf.setPageAction(actionType, action);
}
/** @see com.lowagie.text.pdf.interfaces.PdfPageActions#setDuration(int) */
public void setDuration(int seconds) {
pdf.setDuration(seconds);
}
/** @see com.lowagie.text.pdf.interfaces.PdfPageActions#setTransition(com.lowagie.text.pdf.PdfTransition) */
public void setTransition(PdfTransition transition) {
pdf.setTransition(transition);
}
// [U4] Thumbnail image
/**
* Use this method to set the thumbnail image for the current page.
* @param image the image
* @throws PdfException on error
* @throws DocumentException or error
*/
public void setThumbnail(Image image) throws PdfException, DocumentException {
pdf.setThumbnail(image);
}
// [U5] Transparency groups
/**
* A group attributes dictionary specifying the attributes
* of the page's page group for use in the transparent
* imaging model
*/
protected PdfDictionary group;
/**
* Use this method to get the group dictionary.
* @return Value of property group.
*/
public PdfDictionary getGroup() {
return this.group;
}
/**
* Use this method to set the group dictionary.
* @param group New value of property group.
*/
public void setGroup(PdfDictionary group) {
this.group = group;
}
// [U6] space char ratio
/** The default space-char ratio. */
public static final float SPACE_CHAR_RATIO_DEFAULT = 2.5f;
/** Disable the inter-character spacing. */
public static final float NO_SPACE_CHAR_RATIO = 10000000f;
/**
* The ratio between the extra word spacing and the extra character spacing.
* Extra word spacing will grow <CODE>ratio</CODE> times more than extra character spacing.
*/
private float spaceCharRatio = SPACE_CHAR_RATIO_DEFAULT;
/**
* Use this method to gets the space/character extra spacing ratio
* for fully justified text.
* @return the space/character extra spacing ratio
*/
public float getSpaceCharRatio() {
return spaceCharRatio;
}
/**
* Use this method to set the ratio between the extra word spacing and
* the extra character spacing when the text is fully justified.
* Extra word spacing will grow <CODE>spaceCharRatio</CODE> times more
* than extra character spacing. If the ratio is <CODE>PdfWriter.NO_SPACE_CHAR_RATIO</CODE>
* then the extra character spacing will be zero.
* @param spaceCharRatio the ratio between the extra word spacing and the extra character spacing
*/
public void setSpaceCharRatio(float spaceCharRatio) {
if (spaceCharRatio < 0.001f)
this.spaceCharRatio = 0.001f;
else
this.spaceCharRatio = spaceCharRatio;
}
// [U7] run direction (doesn't actually do anything)
/** Use the default run direction. */
public static final int RUN_DIRECTION_DEFAULT = 0;
/** Do not use bidirectional reordering. */
public static final int RUN_DIRECTION_NO_BIDI = 1;
/** Use bidirectional reordering with left-to-right
* preferential run direction.
*/
public static final int RUN_DIRECTION_LTR = 2;
/** Use bidirectional reordering with right-to-left
* preferential run direction.
*/
public static final int RUN_DIRECTION_RTL = 3;
protected int runDirection = RUN_DIRECTION_NO_BIDI;
/**
* Use this method to set the run direction.
* This is only used as a placeholder as it does not affect anything.
* @param runDirection the run direction
*/
public void setRunDirection(int runDirection) {
if (runDirection < RUN_DIRECTION_NO_BIDI || runDirection > RUN_DIRECTION_RTL)
throw new RuntimeException("Invalid run direction: " + runDirection);
this.runDirection = runDirection;
}
/**
* Use this method to set the run direction.
* @return the run direction
*/
public int getRunDirection() {
return runDirection;
}
// [U8] user units
protected float userunit = 0f;
/**
* Use this method to get the user unit.
* A user unit is a value that defines the default user space unit.
* The minimum UserUnit is 1 (1 unit = 1/72 inch).
* The maximum UserUnit is 75,000.
* Note that this userunit only works starting with PDF1.6!
* @return Returns the userunit.
*/
public float getUserunit() {
return userunit;
}
/**
* Use this method to set the user unit.
* A UserUnit is a value that defines the default user space unit.
* The minimum UserUnit is 1 (1 unit = 1/72 inch).
* The maximum UserUnit is 75,000.
* Note that this userunit only works starting with PDF1.6!
* @param userunit The userunit to set.
* @throws DocumentException on error
*/
public void setUserunit(float userunit) throws DocumentException {
if (userunit < 1f || userunit > 75000f) throw new DocumentException("UserUnit should be a value between 1 and 75000.");
this.userunit = userunit;
setAtLeastPdfVersion(VERSION_1_6);
}
// Miscellaneous topics
// [M1] Color settings
protected PdfDictionary defaultColorspace = new PdfDictionary();
/**
* Use this method to get the default colorspaces.
* @return the default colorspaces
*/
public PdfDictionary getDefaultColorspace() {
return defaultColorspace;
}
/**
* Use this method to sets the default colorspace that will be applied
* to all the document. The colorspace is only applied if another colorspace
* with the same name is not present in the content.
* <p>
* The colorspace is applied immediately when creating templates and
* at the page end for the main document content.
* @param key the name of the colorspace. It can be <CODE>PdfName.DEFAULTGRAY</CODE>, <CODE>PdfName.DEFAULTRGB</CODE>
* or <CODE>PdfName.DEFAULTCMYK</CODE>
* @param cs the colorspace. A <CODE>null</CODE> or <CODE>PdfNull</CODE> removes any colorspace with the same name
*/
public void setDefaultColorspace(PdfName key, PdfObject cs) {
if (cs == null || cs.isNull())
defaultColorspace.remove(key);
defaultColorspace.put(key, cs);
}
// [M2] spot patterns
protected HashMap documentSpotPatterns = new HashMap();
protected ColorDetails patternColorspaceRGB;
protected ColorDetails patternColorspaceGRAY;
protected ColorDetails patternColorspaceCMYK;
ColorDetails addSimplePatternColorspace(Color color) {
int type = ExtendedColor.getType(color);
if (type == ExtendedColor.TYPE_PATTERN || type == ExtendedColor.TYPE_SHADING)
throw new RuntimeException("An uncolored tile pattern can not have another pattern or shading as color.");
try {
switch (type) {
case ExtendedColor.TYPE_RGB:
if (patternColorspaceRGB == null) {
patternColorspaceRGB = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(PdfName.DEVICERGB);
addToBody(array, patternColorspaceRGB.getIndirectReference());
}
return patternColorspaceRGB;
case ExtendedColor.TYPE_CMYK:
if (patternColorspaceCMYK == null) {
patternColorspaceCMYK = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(PdfName.DEVICECMYK);
addToBody(array, patternColorspaceCMYK.getIndirectReference());
}
return patternColorspaceCMYK;
case ExtendedColor.TYPE_GRAY:
if (patternColorspaceGRAY == null) {
patternColorspaceGRAY = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(PdfName.DEVICEGRAY);
addToBody(array, patternColorspaceGRAY.getIndirectReference());
}
return patternColorspaceGRAY;
case ExtendedColor.TYPE_SEPARATION: {
ColorDetails details = addSimple(((SpotColor)color).getPdfSpotColor());
ColorDetails patternDetails = (ColorDetails)documentSpotPatterns.get(details);
if (patternDetails == null) {
patternDetails = new ColorDetails(getColorspaceName(), body.getPdfIndirectReference(), null);
PdfArray array = new PdfArray(PdfName.PATTERN);
array.add(details.getIndirectReference());
addToBody(array, patternDetails.getIndirectReference());
documentSpotPatterns.put(details, patternDetails);
}
return patternDetails;
}
default:
throw new RuntimeException("Invalid color type in PdfWriter.addSimplePatternColorspace().");
}
}
catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
// [M3] Images
/**
* Use this method to get the strictImageSequence status.
* @return value of property strictImageSequence
*/
public boolean isStrictImageSequence() {
return pdf.isStrictImageSequence();
}
/**
* Use this method to set the image sequence, so that it follows
* the text in strict order (or not).
* @param strictImageSequence new value of property strictImageSequence
*
*/
public void setStrictImageSequence(boolean strictImageSequence) {
pdf.setStrictImageSequence(strictImageSequence);
}
/**
* Use this method to clear text wrapping around images (if applicable).
* @throws DocumentException
*/
public void clearTextWrap() throws DocumentException {
pdf.clearTextWrap();
}
/** Dictionary, containing all the images of the PDF document */
protected PdfDictionary imageDictionary = new PdfDictionary();
/** This is the list with all the images in the document. */
private HashMap images = new HashMap();
/**
* Use this method to adds an image to the document
* but not to the page resources. It is used with
* templates and <CODE>Document.add(Image)</CODE>.
* Use this method only if you know what you're doing!
* @param image the <CODE>Image</CODE> to add
* @return the name of the image added
* @throws PdfException on error
* @throws DocumentException on error
*/
public PdfName addDirectImageSimple(Image image) throws PdfException, DocumentException {
return addDirectImageSimple(image, null);
}
/**
* Adds an image to the document but not to the page resources.
* It is used with templates and <CODE>Document.add(Image)</CODE>.
* Use this method only if you know what you're doing!
* @param image the <CODE>Image</CODE> to add
* @param fixedRef the reference to used. It may be <CODE>null</CODE>,
* a <CODE>PdfIndirectReference</CODE> or a <CODE>PRIndirectReference</CODE>.
* @return the name of the image added
* @throws PdfException on error
* @throws DocumentException on error
*/
public PdfName addDirectImageSimple(Image image, PdfIndirectReference fixedRef) throws PdfException, DocumentException {
PdfName name;
// if the images is already added, just retrieve the name
if (images.containsKey(image.getMySerialId())) {
name = (PdfName) images.get(image.getMySerialId());
}
// if it's a new image, add it to the document
else {
if (image.isImgTemplate()) {
name = new PdfName("img" + images.size());
if(image instanceof ImgWMF){
try {
ImgWMF wmf = (ImgWMF)image;
wmf.readWMF(PdfTemplate.createTemplate(this, 0, 0));
}
catch (Exception e) {
throw new DocumentException(e);
}
}
}
else {
PdfIndirectReference dref = image.getDirectReference();
if (dref != null) {
PdfName rname = new PdfName("img" + images.size());
images.put(image.getMySerialId(), rname);
imageDictionary.put(rname, dref);
return rname;
}
Image maskImage = image.getImageMask();
PdfIndirectReference maskRef = null;
if (maskImage != null) {
PdfName mname = (PdfName)images.get(maskImage.getMySerialId());
maskRef = getImageReference(mname);
}
PdfImage i = new PdfImage(image, "img" + images.size(), maskRef);
if (image instanceof ImgJBIG2) {
byte[] globals = ((ImgJBIG2) image).getGlobalBytes();
if (globals != null) {
PdfDictionary decodeparms = new PdfDictionary();
decodeparms.put(PdfName.JBIG2GLOBALS, getReferenceJBIG2Globals(globals));
i.put(PdfName.DECODEPARMS, decodeparms);
}
}
if (image.hasICCProfile()) {
PdfICCBased icc = new PdfICCBased(image.getICCProfile(), image.getCompressionLevel());
PdfIndirectReference iccRef = add(icc);
PdfArray iccArray = new PdfArray();
iccArray.add(PdfName.ICCBASED);
iccArray.add(iccRef);
PdfArray colorspace = i.getAsArray(PdfName.COLORSPACE);
if (colorspace != null) {
if (colorspace.size() > 1 && PdfName.INDEXED.equals(colorspace.getPdfObject(0)))
colorspace.set(1, iccArray);
else
i.put(PdfName.COLORSPACE, iccArray);
}
else
i.put(PdfName.COLORSPACE, iccArray);
}
add(i, fixedRef);
name = i.name();
}
images.put(image.getMySerialId(), name);
}
return name;
}
/**
* Writes a <CODE>PdfImage</CODE> to the outputstream.
*
* @param pdfImage the image to be added
* @return a <CODE>PdfIndirectReference</CODE> to the encapsulated image
* @throws PdfException when a document isn't open yet, or has been closed
*/
PdfIndirectReference add(PdfImage pdfImage, PdfIndirectReference fixedRef) throws PdfException {
if (! imageDictionary.contains(pdfImage.name())) {
PdfXConformanceImp.checkPDFXConformance(this, PdfXConformanceImp.PDFXKEY_IMAGE, pdfImage);
if (fixedRef instanceof PRIndirectReference) {
PRIndirectReference r2 = (PRIndirectReference)fixedRef;
fixedRef = new PdfIndirectReference(0, getNewObjectNumber(r2.getReader(), r2.getNumber(), r2.getGeneration()));
}
try {
if (fixedRef == null)
fixedRef = addToBody(pdfImage).getIndirectReference();
else
addToBody(pdfImage, fixedRef);
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
imageDictionary.put(pdfImage.name(), fixedRef);
return fixedRef;
}
return (PdfIndirectReference) imageDictionary.get(pdfImage.name());
}
/**
* return the <CODE>PdfIndirectReference</CODE> to the image with a given name.
*
* @param name the name of the image
* @return a <CODE>PdfIndirectReference</CODE>
*/
PdfIndirectReference getImageReference(PdfName name) {
return (PdfIndirectReference) imageDictionary.get(name);
}
protected PdfIndirectReference add(PdfICCBased icc) {
PdfIndirectObject object;
try {
object = addToBody(icc);
}
catch(IOException ioe) {
throw new ExceptionConverter(ioe);
}
return object.getIndirectReference();
}
/**
* A HashSet with Stream objects containing JBIG2 Globals
* @since 2.1.5
*/
protected HashMap JBIG2Globals = new HashMap();
/**
* Gets an indirect reference to a JBIG2 Globals stream.
* Adds the stream if it hasn't already been added to the writer.
* @param content a byte array that may already been added to the writer inside a stream object.
* @since 2.1.5
*/
protected PdfIndirectReference getReferenceJBIG2Globals(byte[] content) {
if (content == null) return null;
PdfStream stream;
for (Iterator i = JBIG2Globals.keySet().iterator(); i.hasNext(); ) {
stream = (PdfStream) i.next();
if (Arrays.equals(content, stream.getBytes())) {
return (PdfIndirectReference) JBIG2Globals.get(stream);
}
}
stream = new PdfStream(content);
PdfIndirectObject ref;
try {
ref = addToBody(stream);
} catch (IOException e) {
return null;
}
JBIG2Globals.put(stream, ref.getIndirectReference());
return ref.getIndirectReference();
}
// [M4] Old table functionality; do we still need it?
/**
* Checks if a <CODE>Table</CODE> fits the current page of the <CODE>PdfDocument</CODE>.
*
* @param table the table that has to be checked
* @param margin a certain margin
* @return <CODE>true</CODE> if the <CODE>Table</CODE> fits the page, <CODE>false</CODE> otherwise.
*/
public boolean fitsPage(Table table, float margin) {
return pdf.bottom(table) > pdf.indentBottom() + margin;
}
/**
* Checks if a <CODE>Table</CODE> fits the current page of the <CODE>PdfDocument</CODE>.
*
* @param table the table that has to be checked
* @return <CODE>true</CODE> if the <CODE>Table</CODE> fits the page, <CODE>false</CODE> otherwise.
*/
public boolean fitsPage(Table table) {
return fitsPage(table, 0);
}
// [F12] tagged PDF
/**
* A flag indicating the presence of structure elements that contain user properties attributes.
*/
private boolean userProperties;
/**
* Gets the flag indicating the presence of structure elements that contain user properties attributes.
* @return the user properties flag
*/
public boolean isUserProperties() {
return this.userProperties;
}
/**
* Sets the flag indicating the presence of structure elements that contain user properties attributes.
* @param userProperties the user properties flag
*/
public void setUserProperties(boolean userProperties) {
this.userProperties = userProperties;
}
/**
* Holds value of property RGBTranparency.
*/
private boolean rgbTransparencyBlending;
/**
* Gets the transparency blending colorspace.
* @return <code>true</code> if the transparency blending colorspace is RGB, <code>false</code>
* if it is the default blending colorspace
* @since 2.1.0
*/
public boolean isRgbTransparencyBlending() {
return this.rgbTransparencyBlending;
}
/**
* Sets the transparency blending colorspace to RGB. The default blending colorspace is
* CMYK and will result in faded colors in the screen and in printing. Calling this method
* will return the RGB colors to what is expected. The RGB blending will be applied to all subsequent pages
* until other value is set.
* Note that this is a generic solution that may not work in all cases.
* @param rgbTransparencyBlending <code>true</code> to set the transparency blending colorspace to RGB, <code>false</code>
* to use the default blending colorspace
* @since 2.1.0
*/
public void setRgbTransparencyBlending(boolean rgbTransparencyBlending) {
this.rgbTransparencyBlending = rgbTransparencyBlending;
}
}
|