/home/mjc1/public_html/db_admin/libraries/fpdf/fpdf.php


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
<?php
/* $Id: fpdf.php,v 2.3 2004/05/20 16:14:13 nijel Exp $ */
// vim: expandtab sw=4 ts=4 sts=4:

/****************************************************************************
* Software : FPDF                                                           *
* Version :  1.51                                                           *
* Date :     2002/08/03                                                     *
* Author :   Olivier PLATHEY                                                *
* Website :  http://www.fpdf.org                                            *
* Licence :  Freeware                                                       *
*                                                                           *
* You are entitled to modify this soft as you want to.                      *
****************************************************************************/


$FPDF_version = (string) '1.51';


/**
 * The FPDF class
 */
class FPDF
{
    
/**
     * Defines private properties
     */
    
var $page;               // current page number
    
var $n;                  // current object number
    
var $offsets;            // array of object offsets
    
var $buffer;             // buffer holding in-memory PDF
    
var $pages;              // array containing pages
    
var $state;              // current document state
    
var $compress;           // compression flag
    
var $DefOrientation;     // default orientation
    
var $CurOrientation;     // current orientation
    
var $OrientationChanges// array indicating orientation changes
    
var $fwPt$fhPt;        // dimensions of page format in points
    
var $fw$fh;            // dimensions of page format in user unit
    
var $wPt$hPt;          // current dimensions of page in points
    
var $k;                  // scale factor (number of points in user unit)
    
var $w$h;              // current dimensions of page in user unit
    
var $lMargin;            // left margin
    
var $tMargin;            // top margin
    
var $rMargin;            // right margin
    
var $bMargin;            // page break margin
    
var $cMargin;            // cell margin
    
var $x$y;              // current position in user unit for cell positionning
    
var $lasth;              // height of last cell printed
    
var $LineWidth;          // line width in user unit
    
var $CoreFonts;          // array of standard font names
    
var $fonts;              // array of used fonts
    
var $FontFiles;          // array of font files
    
var $diffs;              // array of encoding differences
    
var $images;             // array of used images
    
var $PageLinks;          // array of links in pages
    
var $links;              // array of internal links
    
var $FontFamily;         // current font family
    
var $FontStyle;          // current font style
    
var $CurrentFont;        // current font info
    
var $FontSizePt;         // current font size in points
    
var $FontSize;           // current font size in user unit
    
var $DrawColor;          // commands for drawing color
    
var $FillColor;          // commands for filling color
    
var $TextColor;          // commands for text color
    
var $ColorFlag;          // indicates whether fill and text colors are different
    
var $ws;                 // word spacing
    
var $underline;          // whether underline is current state or not
    
var $AutoPageBreak;      // automatic page breaking
    
var $PageBreakTrigger;   // threshold used to trigger page breaks
    
var $InFooter;           // flag set when processing footer
    
var $ZoomMode;           // zoom display mode
    
var $LayoutMode;         // layout display mode
    
var $title;              // title
    
var $subject;            // subject
    
var $author;             // author
    
var $keywords;           // keywords
    
var $creator;            // creator
    
var $AliasNbPages;       // alias for total number of pages



    /**************************************************************************
    *                                                                         *
    *      Public methods below are used by some private ones. Then they      *
    *      are placed at the top of the class.                                *
    *                                                                         *
    **************************************************************************/

    /**
     * Gets the width of a string in the current font
     *
     * @param   string   The string to check
     *
     * @return  double  The string width
     *
     * @access  public
     */
    
function GetStringWidth($s)
    {
        
$s     = (string) $s;
        
// loic1: PHP3 compatibility
        // $cw    = &$this->CurrentFont['cw'];
        
$w     0;
        
$l     strlen($s);
        for (
$i 0$i $l$i++) {
            
// $w += $cw[$s[$i]];
            
$w += $this->CurrentFont['cw'][$s[$i]];
        } 
// end for

        
return $w $this->FontSize 1000;
    } 
// end of the "GetStringWidth()" method


    /**
     * Displays an error message then exists
     *
     * @param  string  The error message
     *
     * @access public
     */
    
function Error($msg)
    {
        die(
'<b>FPDF error: </b>' $msg);
    } 
// end of the "Error()" method



    /**************************************************************************
    *                                                                         *
    *                             Private methods                             *
    *                                                                         *
    **************************************************************************/

    /**
     * Adds a line to the document
     *
     * @param   string   The string to add
     *
     * @access  private
     */
    
function _out($s)
    {
        if (
$this->state == 2) {
            
$this->pages[$this->page] .= $s "\n";
        } else {
            
$this->buffer             .= $s "\n";
        }
    } 
// end of the "_out()" method


    /**
     * Starts a new object
     *
     * @access private
     */
    
function _newobj()
    {
        
$this->n++;
        
$this->offsets[$this->n] = strlen($this->buffer);
        
$this->_out($this->' 0 obj');
    } 
// end of the "_newobj()" method


    /**
     * Adds a "\" before "\", "(" and ")" characters
     *
     * @param   string   The string to slash
     *
     * @return  integer  The slashed string
     *
     * @access  private
     */
    
function _escape($s)
    {
        return 
str_replace(')''\\)'str_replace('(''\\('str_replace('\\''\\\\'$s)));
    } 
// end of the "_escape()" method


    /**
     * Formats a text stringrs
     *
     * @param   string   The string to format
     *
     * @return  integer  The formatted string
     *
     * @access  private
     *
     * @see     _escape()
     */
    
function _textstring($s)
    {
        return 
'(' $this->_escape($s) . ')';
    } 
// end of the "_textstring()" method


    /**
     * Outputs a stream
     *
     * @param   string   The stream to ouput
     *
     * @access  private
     *
     * @see     _out()
     */
    
function _putstream($s)
    {
        
$this->_out('stream');
        
$this->_out($s);
        
$this->_out('endstream');
    } 
// end of the "_putstream()" method


    /**
     * Starts document
     *
     * @access private
     */
    
function _begindoc()
    {
        
$this->state 1;
        
$this->_out('%PDF-1.3');
    } 
// end of the "_begindoc()" method


    /**
     * Puts pages
     *
     * @access private
     */
    
function _putpages()
    {
        
$nb $this->page;

        if (!empty(
$this->AliasNbPages)) {
            
// Replaces number of pages
            
for ($n 1$n <= $nb$n++) {
                
$this->pages[$n] = str_replace($this->AliasNbPages$nb$this->pages[$n]);
            }
        }
        if (
$this->DefOrientation == 'P') {
            
$wPt $this->fwPt;
            
$hPt $this->fhPt;
        } else {
            
$wPt $this->fhPt;
            
$hPt $this->fwPt;
        }
        
$filter = ($this->compress) ? '/Filter /FlateDecode ' '';

        for (
$n=1$n <= $nb$n++) {
            
// Page
            
$this->_newobj();
            
$this->_out('<</Type /Page');
            
$this->_out('/Parent 1 0 R');
            if (isset(
$this->OrientationChanges[$n])) {
                
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]'$hPt$wPt));
            }
            
$this->_out('/Resources 2 0 R');
            if (isset(
$this->PageLinks[$n])) {
                
// Links
                
$annots         '/Annots [';
                
reset($this->PageLinks[$n]);
                while (list(, 
$pl) = each($this->PageLinks[$n])) {
                    
$rect       sprintf('%.2f %.2f %.2f %.2f'$pl[0], $pl[1], $pl[0] + $pl[2], $pl[1] - $pl[3]);
                    
$annots     .= '<</Type /Annot /Subtype /Link /Rect [' $rect '] /Border [0 0 0] ';
                    if (
is_string($pl[4])) {
                        
$annots .= '/A <</S /URI /URI ' $this->_textstring($pl[4]) . '>>>>';
                    }
                    else {
                        
$l      $this->links[$pl[4]];
                        
$h      = isset($this->OrientationChanges[$l[0]]) ? $wPt $hPt;
                        
$annots .= sprintf('/Dest [%d 0 R /XYZ 0 %.2f null]>>'$l[0], $h $l[1] * $this->k);
                    }
                } 
// end while
                
$this->_out($annots ']');
            } 
// end if
            
$this->_out('/Contents ' . ($this->n+1).' 0 R>>');
            
$this->_out('endobj');

            
// Page content
            
$p = ($this->compress) ? gzcompress($this->pages[$n]) : $this->pages[$n];
            
$this->_newobj();
            
$this->_out('<<' $filter '/Length ' strlen($p) . '>>');
            
$this->_putstream($p);
            
$this->_out('endobj');
        } 
// end for

        // Pages root
        
$this->offsets[1]=strlen($this->buffer);
        
$this->_out('1 0 obj');
        
$this->_out('<</Type /Pages');
        
$kids     '/Kids [';
        for (
$i 0$i $nb$i++) {
            
$kids .= ($i) . ' 0 R ';
        }
        
$this->_out($kids ']');
        
$this->_out('/Count ' $nb);
        
$this->_out(sprintf('/MediaBox [0 0 %.2f %.2f]'$wPt$hPt));
        
$this->_out('>>');
        
$this->_out('endobj');
    } 
// end of the "_putpages()" method


    /**
     * Puts font faces
     *
     * @access private
     */
    
function _putfonts()
    {
        
$nf $this->n;

        foreach (
$this->diffs AS $diff) {
            
// Encodings
            
$this->_newobj();
            
$this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences [' $diff ']>>');
            
$this->_out('endobj');
        } 
// end while

        
$mqr get_magic_quotes_runtime();
        
set_magic_quotes_runtime(0);

        foreach (
$this->FontFiles AS $file => $info) {
            
// Font file embedding
            
$this->_newobj();
            
$this->FontFiles[$file]['n'] = $this->n;
            if (isset(
$GLOBALS['FPDF_font_path'])) {
                
$file $GLOBALS['FPDF_font_path'] . $file;
            }
            
$size     filesize($file);
            if (!
$size) {
                
$this->Error('Font file not found');
            }
            
$this->_out('<</Length ' $size);
            if (
substr($file, -2) == '.z') {
                
$this->_out('/Filter /FlateDecode');
            }
            
$this->_out('/Length1 ' $info['length1']);
            if (isset(
$info['length2'])) {
                
$this->_out('/Length2 ' $info['length2'] . ' /Length3 0');
            }
            
$this->_out('>>');
            
$f fopen($file'rb');
            
$this->_putstream(fread($f$size));
            
fclose($f);
            
$this->_out('endobj');
        } 
// end while
        
set_magic_quotes_runtime($mqr);

        foreach (
$this->fonts AS $k => $font) {
            
// Font objects
            
$this->_newobj();
            
$this->fonts[$k]['n'] = $this->n;
            
$name                 $font['name'];
            
$this->_out('<</Type /Font');
            
$this->_out('/BaseFont /' $name);
            if (
$font['type'] == 'core')  {
                
// Standard font
                
$this->_out('/Subtype /Type1');
                if (
$name != 'Symbol' && $name != 'ZapfDingbats') {
                    
$this->_out('/Encoding /WinAnsiEncoding');
                }
            }
            else {
                
// Additional font
                
$this->_out('/Subtype /' $font['type']);
                
$this->_out('/FirstChar 32');
                
$this->_out('/LastChar 255');
                
$this->_out('/Widths ' . ($this->1) . ' 0 R');
                
$this->_out('/FontDescriptor ' . ($this->2) . ' 0 R');
                if (
$font['enc']) {
                    if (isset(
$font['diff'])) {
                        
$this->_out('/Encoding ' . ($nf $font['diff']) . ' 0 R');
                    } else {
                        
$this->_out('/Encoding /WinAnsiEncoding');
                    }
                }
            } 
// end if... else...
            
$this->_out('>>');
            
$this->_out('endobj');
            if (
$font['type'] != 'core')  {
                
// Widths
                
$this->_newobj();
                
$s     '[';
                for (
$i 32$i <= 255$i++) {
                    
$s .= $font['cw'][chr($i)] . ' ';
                }
                
$this->_out($s ']');
                
$this->_out('endobj');
                
// Descriptor
                
$this->_newobj();
                
$s     '<</Type /FontDescriptor /FontName /' $name;
                foreach (
$font['desc'] AS $k => $v) {
                    
$s .= ' /' $k ' ' $v;
                }
                
$file $font['file'];
                if (
$file) {
                    
$s .= ' /FontFile' . ($font['type'] == 'Type1' '' '2') . ' ' $this->FontFiles[$file]['n'] . ' 0 R';
                }
                
$this->_out($s '>>');
                
$this->_out('endobj');
            } 
// end if
        
// end while
    
// end of the "_putfonts()" method


    /**
     * Puts images
     *
     * @access private
     */
    
function _putimages()
    {
        
$filter = ($this->compress) ? '/Filter /FlateDecode ' '';

        foreach (
$this->images AS $file => $info) {
            
$this->_newobj();
            
$this->images[$file]['n'] = $this->n;
            
$this->_out('<</Type /XObject');
            
$this->_out('/Subtype /Image');
            
$this->_out('/Width ' $info['w']);
            
$this->_out('/Height ' $info['h']);
            if (
$info['cs'] == 'Indexed') {
                
$this->_out('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal'])/ 1) . ' ' . ($this->1) . ' 0 R]');
            }
            else {
                
$this->_out('/ColorSpace /' $info['cs']);
                if (
$info['cs'] == 'DeviceCMYK') {
                    
$this->_out('/Decode [1 0 1 0 1 0 1 0]');
                }
            } 
// end if... else...
            
$this->_out('/BitsPerComponent ' $info['bpc']);
            
$this->_out('/Filter /' $info['f']);
            if (isset(
$info['parms'])) {
                
$this->_out($info['parms']);
            }
            if (isset(
$info['trns']) && is_array($info['trns'])) {
                
$trns     '';
                
$trns_cnt count($info['trns']);
                for (
$i 0$i $trns_cnt$i++) {
                    
$trns .= $info['trns'][$i] . ' ' $info['trns'][$i] . ' ';
                }
                
$this->_out('/Mask [' $trns ']');
            } 
// end if
            
$this->_out('/Length ' strlen($info['data']) . '>>');
            
$this->_putstream($info['data']);
            
$this->_out('endobj');

            
// Palette
            
if ($info['cs'] == 'Indexed') {
                
$this->_newobj();
                
$pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];
                
$this->_out('<<' $filter '/Length ' strlen($pal) . '>>');
                
$this->_putstream($pal);
                
$this->_out('endobj');
            } 
// end if
        
// end while
    
// end of the "_putimages()" method


    /**
     * Puts resources
     *
     * @access private
     */
    
function _putresources()
    {
        
$this->_putfonts();
        
$this->_putimages();
        
// Resource dictionary
        
$this->offsets[2] = strlen($this->buffer);
        
$this->_out('2 0 obj');
        
$this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');
        
$this->_out('/Font <<');
        foreach (
$this->fonts AS $font) {
            
$this->_out('/F' $font['i'] . ' ' $font['n'] . ' 0 R');
        }
        
$this->_out('>>');
        if (
count($this->images)) {
            
$this->_out('/XObject <<');
            foreach (
$this->images AS $image) {
                
$this->_out('/I' $image['i'] . ' ' $image['n'] . ' 0 R');
            }
            
$this->_out('>>');
        }
        
$this->_out('>>');
        
$this->_out('endobj');
    } 
// end of the "_putresources()" method


    /**
     * Puts document informations
     *
     * @access private
     */
    
function _putinfo()
    {
        
// loic1: PHP3 compatibility
        // $this->_out('/Producer ' . $this->_textstring('FPDF ' . FPDF_VERSION));
        
$this->_out('/Producer ' $this->_textstring('FPDF ' $GLOBALS['FPDF_version']));
        if (!empty(
$this->title)) {
            
$this->_out('/Title ' $this->_textstring($this->title));
        }
        if (!empty(
$this->subject)) {
            
$this->_out('/Subject ' $this->_textstring($this->subject));
        }
        if (!empty(
$this->author)) {
            
$this->_out('/Author ' $this->_textstring($this->author));
        }
        if (!empty(
$this->keywords)) {
            
$this->_out('/Keywords ' $this->_textstring($this->keywords));
        }
        if (!empty(
$this->creator)) {
            
$this->_out('/Creator ' $this->_textstring($this->creator));
        }
        
$this->_out('/CreationDate ' $this->_textstring('D:' date('YmdHis')));
    } 
// end of the "_putinfo()" method


    /**
     * Puts catalog informations
     *
     * @access private
     */
    
function _putcatalog()
    {
        
$this->_out('/Type /Catalog');
        
$this->_out('/Pages 1 0 R');
        if (
$this->ZoomMode == 'fullpage') {
            
$this->_out('/OpenAction [3 0 R /Fit]');
        } else if (
$this->ZoomMode == 'fullwidth') {
            
$this->_out('/OpenAction [3 0 R /FitH null]');
        } else if (
$this->ZoomMode == 'real') {
            
$this->_out('/OpenAction [3 0 R /XYZ null null 1]');
        } else if (!
is_string($this->ZoomMode)) {
            
$this->_out('/OpenAction [3 0 R /XYZ null null ' . ($this->ZoomMode 100) . ']');
        }
        if (
$this->LayoutMode == 'single') {
            
$this->_out('/PageLayout /SinglePage');
        } else if (
$this->LayoutMode == 'continuous') {
            
$this->_out('/PageLayout /OneColumn');
        } else if (
$this->LayoutMode == 'two') {
            
$this->_out('/PageLayout /TwoColumnLeft');
        }
    } 
// end of the "_putcatalog()" method


    /**
     * Puts trailer
     *
     * @access private
     */
    
function _puttrailer()
    {
        
$this->_out('/Size ' . ($this->1));
        
$this->_out('/Root ' $this->' 0 R');
        
$this->_out('/Info ' . ($this->1) . ' 0 R');
    } 
// end of the "_puttrailer()" method


    /**
     * Terminates document
     *
     * @access private
     */
    
function _enddoc()
    {
        
$this->_putpages();
        
$this->_putresources();

        
// Info
        
$this->_newobj();
        
$this->_out('<<');
        
$this->_putinfo();
        
$this->_out('>>');
        
$this->_out('endobj');

        
// Catalog
        
$this->_newobj();
        
$this->_out('<<');
        
$this->_putcatalog();
        
$this->_out('>>');
        
$this->_out('endobj');

        
// Cross-ref
        
$o strlen($this->buffer);
        
$this->_out('xref');
        
$this->_out('0 ' . ($this->1));
        
$this->_out('0000000000 65535 f ');
        for (
$i 1$i <= $this->n$i++) {
            
$this->_out(sprintf('%010d 00000 n '$this->offsets[$i]));
        }

        
// Trailer
        
$this->_out('trailer');
        
$this->_out('<<');
        
$this->_puttrailer();
        
$this->_out('>>');
        
$this->_out('startxref');
        
$this->_out($o);
        
$this->_out('%%EOF');
        
$this->state=3;
    } 
// end of the "_enddoc()" method


    /**
     * Starts a new page
     *
     * @param  string   The page orientation
     *
     * @access private
     */
    
function _beginpage($orientation)
    {
        
$this->page++;
        
$this->pages[$this->page] = '';
        
$this->state              2;
        
$this->x                  $this->lMargin;
        
$this->y                  $this->tMargin;
        
$this->lasth              0;
        
$this->FontFamily         '';

        
// Page orientation
        
if (!$orientation) {
            
$orientation $this->DefOrientation;
        } else {
            
$orientation strtoupper($orientation[0]);
        }
        if (
$orientation != $this->DefOrientation) {
            
$this->OrientationChanges[$this->page] = TRUE;
        }
        if (
$orientation != $this->CurOrientation) {
            
// Changes orientation
            
if ($orientation == 'P') {
                
$this->wPt $this->fwPt;
                
$this->hPt $this->fhPt;
                
$this->w   $this->fw;
                
$this->h   $this->fh;
            }
            else {
                
$this->wPt $this->fhPt;
                
$this->hPt $this->fwPt;
                
$this->w   $this->fh;
                
$this->h   $this->fw;
            }
            
$this->PageBreakTrigger $this->$this->bMargin;
            
$this->CurOrientation   $orientation;
        } 
// end if
    
// end of the "_beginpage()" method


    /**
     * Ends page contents
     *
     * @access private
     */
    
function _endpage()
    {
        
$this->state=1;
    } 
// end of the "_endpage()" method


    /**
     * Underlines text
     *
     * @param   double  The x position
     * @param   double  The y position
     * @param   string  The text
     *
     * @return  string  The underlined text
     *
     * @access  private
     */
    
function _dounderline($x,$y,$txt)
    {
        
$up $this->CurrentFont['up'];
        
$ut $this->CurrentFont['ut'];
        
$w  $this->GetStringWidth($txt) + $this->ws substr_count($txt' ');

        return 
sprintf('%.2f %.2f %.2f %.2f re f'$x $this->k, ($this->- ($y $up 1000 $this->FontSize)) * $this->k$w $this->k, -$ut 1000 $this->FontSizePt);
    } 
// end of the "_dounderline()" method


    /**
     * Extracts info from a JPEG file
     *
     * @param   string  The file name and path
     *
     * @return  array   The images informations
     *
     * @access  private
     */
    
function _parsejpg($file)
    {
        
$a GetImageSize($file);
        if (!
$a) {
            
$this->Error('Missing or incorrect image file: ' $file);
        }
        if (
$a[2] != 2) {
            
$this->Error('Not a JPEG file: ' $file);
        }
        if (!isset(
$a['channels']) || $a['channels'] == 3) {
            
$colspace 'DeviceRGB';
        }
        else if (
$a['channels'] == 4) {
            
$colspace 'DeviceCMYK';
        }
        else {
            
$colspace 'DeviceGray';
        }
        
$bpc = isset($a['bits']) ? $a['bits'] : 8;

        
// Reads whole file
        
$f    fopen($file'rb');
        
$data fread($ffilesize($file));
        
fclose($f);

        return array(
'w'    => $a[0],
                     
'h'    => $a[1],
                     
'cs'   => $colspace,
                     
'bpc'  => $bpc,
                     
'f'    => 'DCTDecode',
                     
'data' => $data);
    } 
// end of the "_parsejpg()" method


    /**
     * Reads a 4-byte integer from a file
     *
     * @param   string   The file name and path
     *
     * @return  integer  The 4-byte integer
     *
     * @access  private
     *
     * @see     _parsepng()
     */
    
function _freadint($f)
    {
        
$i ord(fread($f1)) << 24;
        
$i += ord(fread($f1)) << 16;
        
$i += ord(fread($f1)) << 8;
        
$i += ord(fread($f1));

        return 
$i;
    } 
// end of the "_freadint()" method


    /**
     * Extracts info from a PNG file
     *
     * @param   string  The file name and path
     *
     * @return  array   The images informations
     *
     * @access  private
     *
     * @see     _freadint()
     */
    
function _parsepng($file)
    {
        
$f fopen($file'rb');
        if (!
$f) {
            
$this->Error('Can\'t open image file: ' $file);
        }

        
// Checks signature
        
if (fread($f8) != chr(137) . 'PNG' chr(13) . chr(10) . chr(26) . chr(10)) {
            
$this->Error('Not a PNG file: ' $file);
        }

        
// Reads header chunk
        
fread($f,4);
        if (
fread($f4) != 'IHDR') {
            
$this->Error('Incorrect PNG file: ' $file);
        }
        
$w   $this->_freadint($f);
        
$h   $this->_freadint($f);
        
$bpc ord(fread($f,1));
        if (
$bpc 8) {
            
$this->Error('16-bit depth not supported: ' $file);
        }
        
$ct  ord(fread($f1));
        if (
$ct == 0) {
            
$colspace 'DeviceGray';
        }
        else if (
$ct == 2) {
            
$colspace 'DeviceRGB';
        }
        else if (
$ct == 3) {
            
$colspace 'Indexed';
        }
        else {
            
$this->Error('Alpha channel not supported: ' $file);
        }
        if (
ord(fread($f1)) != 0) {
            
$this->Error('Unknown compression method: ' $file);
        }
        if (
ord(fread($f1)) != 0) {
            
$this->Error('Unknown filter method: ' $file);
        }
        if (
ord(fread($f1)) != 0) {
            
$this->Error('Interlacing not supported: ' $file);
        }
        
fread($f4);
        
$parms '/DecodeParms <</Predictor 15 /Colors ' . ($ct == 1)
               . 
' /BitsPerComponent ' $bpc
               
' /Columns ' $w '>>';

        
// Scans chunks looking for palette, transparency and image data
        
$pal  '';
        
$trns '';
        
$data '';
        do {
            
$n    $this->_freadint($f);
            
$type fread($f4);
            if (
$type == 'PLTE') {
                
// Reads palette
                
$pal fread($f$n);
                
fread($f4);
            }
            else if (
$type == 'tRNS') {
                
// Reads transparency info
                
$t            fread($f$n);
                if (
$ct == 0) {
                    
$trns     = array(ord(substr($t11)));
                }
                else if (
$ct == 2) {
                    
$trns     = array(ord(substr($t11)), ord(substr($t31)), ord(substr($t51)));
                }
                else {
                    
$pos      strpos(' ' $tchr(0));
                    if (
$pos) {
                        
$trns = array($pos 1);
                    }
                    
fread($f,4);
                } 
// end if... else if... else
            
}
            else if (
$type == 'IDAT') {
                
// Reads image data block
                
$data .= fread($f$n);
                
fread($f4);
            }
            else if (
$type == 'IEND') {
                break;
            }
            else {
                
fread($f$n 4);
            } 
// end if... else if... else
        
} while ($n); // end do

        
if ($colspace == 'Indexed' && empty($pal)) {
            
$this->Error('Missing palette in ' $file);
        }
        
fclose($f);

        return array(
'w'     => $w,
                     
'h'     => $h,
                     
'cs'    => $colspace,
                     
'bpc'   => $bpc,
                     
'f'     => 'FlateDecode',
                     
'parms' => $parms,
                     
'pal'   => $pal,
                     
'trns'  => $trns,
                     
'data'  => $data);
    } 
// end of the "_parsepng()" method



    /**************************************************************************
    *                                                                         *
    *                             Public methods                              *
    *                                                                         *
    **************************************************************************/

    /**
     * Sets auto page break mode and triggering margin
     *
     * @param  string  The auto page break mode
     * @param  double  Maximum size till the bottom of the page to start adding
     *                 page break
     *
     * @access public
     */
    
function SetAutoPageBreak($auto$margin 0)
    {
        
$this->AutoPageBreak    $auto;
        
$this->bMargin          $margin;
        
$this->PageBreakTrigger $this->$margin;
    } 
// end of the "SetAutoPageBreak()" method


    /**
     * Sets display mode in viewer
     *
     * @param  mixed   The zoom mode (fullpage, fullwidth, real, default,
     *                 zoom or an zoom factor -real-)
     * @param  string  The layout mode (single, continuous, two or default)
     *
     * @access public
     */
    
function SetDisplayMode($zoom 'default'$layout 'continuous')
    {
        if (
is_string($zoom)) {
            
$zoom strtolower($zoom);
        }
        
$layout   strtolower($layout);

        
// Zoom mode
        
if ($zoom == 'fullpage' || $zoom == 'fullwidth' || $zoom == 'real' || $zoom == 'default'
            
|| !is_string($zoom)) {
            
$this->ZoomMode $zoom;
        } else if (
$zoom == 'zoom') {
            
$this->ZoomMode $layout;
        } else {
            
$this->Error('Incorrect zoom display mode: ' $zoom);
        } 
// end if... else if... else...

        // Layout mode
        
if ($layout == 'single' || $layout == 'continuous' || $layout=='two' || $layout=='default') {
            
$this->LayoutMode $layout;
        } else if (
$zoom != 'zoom') {
            
$this->Error('Incorrect layout display mode: ' $layout);
        } 
// end if... else if...
    
// end of the "SetDisplayMode()" method


    /**
     * Sets page compression
     *
     * @param  boolean  whether to compress file or not
     *
     * @access public
     */
    
function SetCompression($compress)
    {
        if (
function_exists('gzcompress')) {
            
$this->compress $compress;
        } else {
            
$this->compress FALSE;
        } 
// end if... else...
    
// end of the "SetCompression()" method


    /**
     * Sets page margins
     *
     * @param  double  The left margin
     * @param  double  The top margin
     * @param  double  The right margin
     *
     * @access public
     */
    
function SetMargins($left$top$right = -1)
    {
        
$this->lMargin $left;
        
$this->tMargin $top;
        if (
$right == -1) {
            
$right $left;
        }
        
$this->rMargin $right;
    } 
// end of the "SetMargins()" method


    /**
     * The FPDF constructor
     *
     * @param  string  The page orientation (p, portrait, l or landscape)
     * @param  string  The unit for sizes (pt, mm, cm or in)
     * @param  mixed   The page format (A3, A4, A5, letter, legal or an array
     *                 with page sizes)
     *
     * @access public
     */
    
function FPDF($orientation 'P'$unit 'mm'$format 'A4')
    {
        
// Check for PHP locale-related bug
        
if (1.1 == 1) {
            
$this->Error('Don\'t call setlocale() before including class file');
        }

        
// Initialization of properties
        
$this->page               0;
        
$this->n                  2;
        
$this->buffer             '';
        
$this->pages              = array();
        
$this->OrientationChanges = array();
        
$this->state              0;
        
$this->fonts              = array();
        
$this->FontFiles          = array();
        
$this->diffs              = array();
        
$this->images             = array();
        
$this->links              = array();
        
$this->InFooter           FALSE;
        
$this->FontFamily         '';
        
$this->FontStyle          '';
        
$this->FontSizePt         12;
        
$this->underline          FALSE;
        
$this->DrawColor          '0 G';
        
$this->FillColor          '0 g';
        
$this->TextColor          '0 g';
        
$this->ColorFlag          FALSE;
        
$this->ws                 0;

        
// Standard fonts
        
$this->CoreFonts['courier']      = 'Courier';
        
$this->CoreFonts['courierB']     = 'Courier-Bold';
        
$this->CoreFonts['courierI']     = 'Courier-Oblique';
        
$this->CoreFonts['courierBI']    = 'Courier-BoldOblique';
        
$this->CoreFonts['helvetica']    = 'Helvetica';
        
$this->CoreFonts['helveticaB']   = 'Helvetica-Bold';
        
$this->CoreFonts['helveticaI']   = 'Helvetica-Oblique';
        
$this->CoreFonts['helveticaBI']  = 'Helvetica-BoldOblique';
        
$this->CoreFonts['times']        = 'Times-Roman';
        
$this->CoreFonts['timesB']       = 'Times-Bold';
        
$this->CoreFonts['timesI']       = 'Times-Italic';
        
$this->CoreFonts['timesBI']      = 'Times-BoldItalic';
        
$this->CoreFonts['symbol']       = 'Symbol';
        
$this->CoreFonts['zapfdingbats'] = 'ZapfDingbats';

        
// Scale factor
        
if ($unit == 'pt') {
            
$this->1;
        } else if (
$unit == 'mm') {
            
$this->72/25.4;
        } else if (
$unit == 'cm') {
            
$this->72/2.54;
        } else if (
$unit == 'in') {
            
$this->72;
        } else {
            
$this->Error('Incorrect unit: ' $unit);
        } 
// end if... else if... else...

        // Page format
        
if (is_string($format)) {
            
// 2002-07-24 - Nicola Asuni (info@tecnick.com)
            // Added new page formats (45 standard ISO paper formats and 4
            // american common formats).
            // Paper cordinates are calculated in this way:
            //    (inches * 72) where (1 inch = 2.54 cm)
            
switch (strtoupper($format)) {
                case 
'4A0':
                    
$format = array(4767.876740.79);
                    break;
                case 
'2A0':
                    
$format = array(3370.394767.87);
                    break;
                case 
'A0':
                    
$format = array(2383.943370.39);
                    break;
                case 
'A1':
                    
$format = array(1683.782383.94);
                    break;
                case 
'A2':
                    
$format = array(1190.551683.78);
                    break;
                case 
'A3':
                    
$format = array(841.891190.55);
                    break;
                case 
'A4':
                    
$format = array(595.28841.89);
                    break;
                case 
'A5':
                    
$format = array(419.53595.28);
                    break;
                case 
'A6':
                    
$format = array(297.64419.53);
                    break;
                case 
'A7':
                    
$format = array(209.76297.64);
                    break;
                case 
'A8':
                    
$format = array(147.40209.76);
                    break;
                case 
'A9':
                    
$format = array(104.88147.40);
                    break;
                case 
'A10':
                    
$format = array(73.70104.88);
                    break;
                case 
'B0':
                    
$format = array(2834.654008.19);
                    break;
                case 
'B1':
                    
$format = array(2004.092834.65);
                    break;
                case 
'B2':
                    
$format = array(1417.322004.09);
                    break;
                case 
'B3':
                    
$format = array(1000.631417.32);
                    break;
                case 
'B4':
                    
$format = array(708.661000.63);
                    break;
                case 
'B5':
                    
$format = array(498.90708.66);
                    break;
                case 
'B6':
                    
$format = array(354.33498.90);
                    break;
                case 
'B7':
                    
$format = array(249.45354.33);
                    break;
                case 
'B8':
                    
$format = array(175.75249.45);
                    break;
                case 
'B9':
                    
$format = array(124.72175.75);
                    break;
                case 
'B10':
                    
$format = array(87.87124.72);
                    break;
                case 
'C0':
                    
$format = array(2599.373676.54);
                    break;
                case 
'C1':
                    
$format = array(1836.852599.37);
                    break;
                case 
'C2':
                    
$format = array(1298.271836.85);
                    break;
                case 
'C3':
                    
$format = array(918.431298.27);
                    break;
                case 
'C4':
                    
$format = array(649.13918.43);
                    break;
                case 
'C5':
                    
$format = array(459.21649.13);
                    break;
                case 
'C6':
                    
$format = array(323.15459.21);
                    break;
                case 
'C7':
                    
$format = array(229.61323.15);
                    break;
                case 
'C8':
                    
$format = array(161.57229.61);
                    break;
                case 
'C9':
                    
$format = array(113.39161.57);
                    break;
                case 
'C10':
                    
$format = array(79.37113.39);
                    break;
                case 
'RA0':
                    
$format = array(2437.803458.27);
                    break;
                case 
'RA1':
                    
$format = array(1729.132437.80);
                    break;
                case 
'RA2':
                    
$format = array(1218.901729.13);
                    break;
                case 
'RA3':
                    
$format = array(864.571218.90);
                    break;
                case 
'RA4':
                    
$format = array(609.45864.57);
                    break;
                case 
'SRA0':
                    
$format = array(2551.183628.35);
                    break;
                case 
'SRA1':
                    
$format = array(1814.172551.18);
                    break;
                case 
'SRA2':
                    
$format = array(1275.591814.17);
                    break;
                case 
'SRA3':
                    
$format = array(907.091275.59);
                    break;
                case 
'SRA4':
                    
$format = array(637.80907.09);
                    break;
                case 
'LETTER':
                    
$format = array(612.00792.00);
                    break;
                case 
'LEGAL':
                    
$format = array(612.001008.00);
                    break;
                case 
'EXECUTIVE':
                    
$format = array(521.86756.00);
                    break;
                case 
'FOLIO':
                    
$format = array(612.00936.00);
                    break;
                default:
                    
$this->Error('Unknown page format: ' $format);
                    break;
            } 
// end switch
            
$this->fwPt $format[0];
            
$this->fhPt $format[1];
        }
        else {
            
$this->fwPt $format[0] * $this->k;
            
$this->fhPt $format[1] * $this->k;
        } 
// end if... else...
        
$this->fw       $this->fwPt $this->k;
        
$this->fh       $this->fhPt $this->k;

        
// Page orientation
        
$orientation    strtolower($orientation);
        if (
$orientation == 'p' || $orientation == 'portrait') {
            
$this->DefOrientation 'P';
            
$this->wPt            $this->fwPt;
            
$this->hPt            $this->fhPt;
        }
        else if (
$orientation == 'l' || $orientation == 'landscape') {
            
$this->DefOrientation 'L';
            
$this->wPt            $this->fhPt;
            
$this->hPt            $this->fwPt;
        }
        else {
            
$this->Error('Incorrect orientation: ' $orientation);
        } 
// end if... else if... else...
        
$this->CurOrientation     $this->DefOrientation;
        
$this->w                  $this->wPt $this->k;
        
$this->h                  $this->hPt $this->k;

        
// Page margins (1 cm)
        
$margin          28.35 $this->k;
        
$this->SetMargins($margin$margin);

        
// Interior cell margin (1 mm)
        
$this->cMargin   $margin 10;

        
// Line width (0.2 mm)
        
$this->LineWidth .567 $this->k;

        
// Automatic page break
        
$this->SetAutoPageBreak(TRUE$margin);

        
// Full width display mode
        
$this->SetDisplayMode('fullwidth');

        
// Compression
        
$this->SetCompression(TRUE);
    } 
// end of the "FPDF()" constructor


    /**
     * Sets left margin of the page
     *
     * @param  double  The left margin
     *
     * @access public
     */
    
function SetLeftMargin($margin)
    {
        
$this->lMargin $margin;
        if (
$this->page && $this->$margin) {
            
$this->x   $margin;
        }
    } 
// end of the "SetLeftMargin()" method


    /**
     * Sets top margin of the page
     *
     * @param  double  The top margin
     *
     * @access public
     */
    
function SetTopMargin($margin)
    {
        
$this->tMargin $margin;
    } 
// end of the "SetTopMargin()" method


    /**
     * Sets right margin of the page
     *
     * @param  double  The right margin
     *
     * @access public
     */
    
function SetRightMargin($margin)
    {
        
$this->rMargin $margin;
    } 
// end of the "SetRightMargin()" method


    /**
     * Sets the title of the document (among the document properties)
     *
     * @param  string  The title of the document
     *
     * @access public
     */
    
function SetTitle($title)
    {
        
$this->title $title;
    } 
// end of the "SetTitle()" method


    /**
     * Sets the subject of the document (among the document properties)
     *
     * @param  string  The subject of the document
     *
     * @access public
     */
    
function SetSubject($subject)
    {
        
$this->subject $subject;
    } 
// end of the "SetSubject()" method


    /**
     * Sets the author of the document (among the document properties)
     *
     * @param  string  The author of the document
     *
     * @access public
     */
    
function SetAuthor($author)
    {
        
$this->author $author;
    } 
// end of the "SetAuthor()" method


    /**
     * Sets keywords of the document (among the document properties)
     *
     * @param  string  The keyword list for the document
     *
     * @access public
     */
    
function SetKeywords($keywords)
    {
        
$this->keywords $keywords;
    } 
// end of the "SetKeywords()" method


    /**
     * Sets the creator of the document (among the document properties)
     *
     * @param  string  The creator of the document
     *
     * @access public
     */
    
function SetCreator($creator)
    {
        
$this->creator $creator;
    } 
// end of the "SetCreator()" method


    /**
     * Defines an alias for the total number of pages
     *
     * @param  string  The alias string
     *
     * @access public
     */
    
function AliasNbPages($alias '{nb}')
    {
        
$this->AliasNbPages $alias;
    } 
// end of the "AliasNbPages()" method


    /**
     * Selects a font
     *
     * @param   string   The font name
     * @param   string   The font style (B, I, BI)
     * @param   double   The font size (in points)
     *
     * @global  double   The character width
     *
     * @access  public
     */
    
function SetFont($family$style ''$size 0)
    {
        global 
$fpdf_charwidths;

        
$family     strtolower($family);
        if (
$family == '') {
            
$family $this->FontFamily;
        }
        if (
$family == 'arial') {
            
$family 'helvetica';
        }
        else if (
$family == 'symbol' || $family == 'zapfdingbats') {
            
$style  '';
        }
        
$style      strtoupper($style);

        if (
strpos(' ' $style'U')) {
            
$this->underline TRUE;
            
$style           str_replace('U'''$style);
        } else {
            
$this->underline FALSE;
        }
        if (
$style == 'IB') {
            
$style  'BI';
        }
        if (
$size == 0) {
            
$size   $this->FontSizePt;
        }

        
// Tests if the font is already selected
        
if ($this->FontFamily == $family && $this->FontStyle == $style && $this->FontSizePt == $size) {
            return;
        }

        
// Tests if used for the first time
        
$fontkey $family $style;
        if (!isset(
$this->fonts[$fontkey])) {
            
// Checks if one of the standard fonts
            
if (isset($this->CoreFonts[$fontkey])) {
                if (!isset(
$fpdf_charwidths[$fontkey])) {
                    
// Loads metric file
                    
$file     $family;
                    if (
$family == 'times' || $family == 'helvetica') {
                        
$file .= strtolower($style);
                    }
                    
$file     .= '.php';
                    if (isset(
$GLOBALS['FPDF_font_path'])) {
                        
$file $GLOBALS['FPDF_font_path'] . $file;
                    }
                    include(
$file);
                    if (!isset(
$fpdf_charwidths[$fontkey])) {
                        
$this->Error('Could not include font metric file');
                    }
                } 
// end if
                
$i count($this->fonts) + 1;
                
$this->fonts[$fontkey] = array('i'    => $i,
                                               
'type' => 'core',
                                               
'name' => $this->CoreFonts[$fontkey],
                                               
'up'   => -100,
                                               
'ut'   => 50,
                                               
'cw'   => $fpdf_charwidths[$fontkey]);
            }
            else {
                
$this->Error('Undefined font: ' $family ' ' $style);
            } 
// end if... else...
        
// end if

        // Selects it
        
$this->FontFamily  $family;
        
$this->FontStyle   $style;
        
$this->FontSizePt  $size;
        
$this->FontSize    $size $this->k;
        
$this->CurrentFont = &$this->fonts[$fontkey];
        if (
$this->page 0) {
            
$this->_out(sprintf('BT /F%d %.2f Tf ET'$this->CurrentFont['i'], $this->FontSizePt));
        }
    } 
// end of the "SetFont()" method


    /**
     * Sends the header of the page
     *
     * This method has to be implemented in your own inherited class
     *
     * @access public
     */
    
function Header()
    {
        
// void
    
// end of the "Header()" method


    /**
     * Sends the footer of the page
     *
     * This method has to be implemented in your own inherited class
     *
     * @access public
     */
    
function Footer()
    {
        
// void
    
// end of the "Footer()" method


    /**
     * Begin the document
     *
     * @access public
     */
    
function Open()
    {
        
$this->_begindoc();
    } 
// end of the "Open()" method


    /**
     * Starts a new page
     *
     * @param  string  The page orientation (p, portrait, l or landscape)
     *
     * @access public
     */
    
function AddPage($orientation '')
    {
        
// Backups some core variables
        
$family             $this->FontFamily;
        
$style              $this->FontStyle . ($this->underline 'U' '');
        
$size               $this->FontSizePt;
        
$lw                 $this->LineWidth;
        
$dc                 $this->DrawColor;
        
$fc                 $this->FillColor;
        
$tc                 $this->TextColor;
        
$cf                 $this->ColorFlag;

        
// If a page is already defined close it before starting the new one
        
if ($this->page 0) {
            
// Page footer
            
$this->InFooter TRUE;
            
$this->Footer();
            
$this->InFooter FALSE;
            
// Close page
            
$this->_endpage();
        }

        
// Do start the new page
        
$this->_beginpage($orientation);
        
// Sets line cap style to square
        
$this->_out('2 J');
        
// Sets line width
        
$this->LineWidth $lw;
        
$this->_out(sprintf('%.2f w'$lw $this->k));
        
// Sets font
        
if ($family) {
            
$this->SetFont($family$style$size);
        }
        
// Sets colors
        
$this->DrawColor $dc;
        if (
$dc != '0 G') {
            
$this->_out($dc);
        }
        
$this->FillColor $fc;
        if (
$fc != '0 g') {
            
$this->_out($fc);
        }
        
$this->TextColor $tc;
        
$this->ColorFlag $cf;
        
// Sets Page header
        
$this->Header();
        
// Restores line width
        
if ($this->LineWidth != $lw) {
            
$this->LineWidth $lw;
            
$this->_out(sprintf('%.2f w'$lw $this->k));
        }
        
// Restores font
        
if ($family) {
            
$this->SetFont($family$style$size);
        }
        
// Restores colors
        
if ($this->DrawColor!=$dc) {
            
$this->DrawColor $dc;
            
$this->_out($dc);
        }
        if (
$this->FillColor!=$fc) {
            
$this->FillColor $fc;
            
$this->_out($fc);
        }
        
$this->TextColor     $tc;
        
$this->ColorFlag     $cf;
    } 
// end of the "AddPage()" method


    /**
     * Terminates and closes the document
     *
     * @access public
     */
    
function Close()
    {
        
// Terminates document
        
if ($this->page == 0) {
            
$this->AddPage();
        }

        
// Displays the page footer
        
$this->InFooter TRUE;
        
$this->Footer();
        
$this->InFooter FALSE;

        
// Closes page and document
        
$this->_endpage();
        
$this->_enddoc();
    } 
// end of the "Close()" method


    /**
     * Gets the current page number
     *
     * @return  integer  The current page number
     *
     * @access  public
     */
    
function PageNo()
    {
        return 
$this->page;
    } 
// end of the "PageNo()" method


    /**
     * Sets color for all stroking operations
     *
     * @param  integer  The red level (0 to 255)
     * @param  integer  The green level (0 to 255)
     * @param  integer  The blue level (0 to 255)
     *
     * @access public
     */
    
function SetDrawColor($r$g = -1$b = -1)
    {
        if ((
$r == && $g == && $b == 0) || $g == -1) {
            
$this->DrawColor sprintf('%.3f G'$r 255);
        } else {
            
$this->DrawColor sprintf('%.3f %.3f %.3f RG'$r 255$g 255$b 255);
        } 
// end if... else...

        // If a page is defined, applies this property
        
if ($this->page 0) {
            
$this->_out($this->DrawColor);
        }
    } 
// end of the "SetDrawColor()" method


    /**
     * Sets color for all filling operations
     *
     * @param  integer  The red level (0 to 255)
     * @param  integer  The green level (0 to 255)
     * @param  integer  The blue level (0 to 255)
     *
     * @access public
     */
    
function SetFillColor($r$g = -1$b =-1)
    {
        if ((
$r == && $g == && $b == 0) || $g == -1) {
            
$this->FillColor sprintf('%.3f g'$r 255);
        } else {
            
$this->FillColor sprintf('%.3f %.3f %.3f rg'$r 255$g 255$b 255);
        } 
// end if... else...

        
$this->ColorFlag     = ($this->FillColor != $this->TextColor);

        
// If a page is defined, applies this property
        
if ($this->page 0) {
            
$this->_out($this->FillColor);
        }
    } 
// end of the "SetDrawColor()" method


    /**
     * Sets color for text
     *
     * @param  integer  The red level (0 to 255)
     * @param  integer  The green level (0 to 255)
     * @param  integer  The blue level (0 to 255)
     *
     * @access public
     */
    
function SetTextColor($r$g = -1$b =-1)
    {
        if ((
$r == && $g == && $b == 0) || $g == -1) {
            
$this->TextColor sprintf('%.3f g'$r 255);
        } else {
            
$this->TextColor sprintf('%.3f %.3f %.3f rg'$r 255$g 255$b 255);
        } 
// end if... else...

        
$this->ColorFlag     = ($this->FillColor != $this->TextColor);
    } 
// end of the "SetTextColor()" method


    /**
     * Sets the line width
     *
     * @param   double  The line width
     *
     * @access  public
     */
    
function SetLineWidth($width)
    {
        
$this->LineWidth $width;

        
// If a page is defined, applies this property
        
if ($this->page 0) {
            
$this->_out(sprintf('%.2f w'$width $this->k));
        }
    } 
// end of the "SetLineWidth()" method


    /**
     * Draws a line
     *
     * @param   double  The horizontal position of the starting point
     * @param   double  The vertical position of the starting point
     * @param   double  The horizontal position of the ending point
     * @param   double  The vertical position of the ending point
     *
     * @access  public
     */
    
function Line($x1$y1$x2$y2)
    {
        
$this->_out(sprintf('%.2f %.2f m %.2f %.2f l S'$x1 $this->k, ($this->$y1) * $this->k$x2 $this->k, ($this->$y2) * $this->k));
    } 
// end of the "Line()" method


    /**
     * Draws a rectangle
     *
     * @param   double  The horizontal position of the top left corner
     * @param   double  The vertical position of the top left corner
     * @param   double  The horizontal position of the bottom right corner
     * @param   double  The vertical position of the bottom right corner
     * @param   string  The rectangle style
     *
     * @access  public
     */
    
function Rect($x$y$w$h$style '')
    {
        if (
$style == 'F') {
            
$op 'f';
        } else if (
$style == 'FD' || $style=='DF') {
            
$op 'B';
        } else {
            
$op 'S';
        } 
// end if... else if... else

        
$this->_out(sprintf('%.2f %.2f %.2f %.2f re %s'$x $this->k, ($this->$y) * $this->k$w $this->k, -$h $this->k$op));
    } 
// end of the "Rect()" method


    /**
     * Adds a TrueType or Type1 font
     *
     * @param   string  The font name
     * @param   string  The font style (B, I, BI)
     * @param   string  The font file definition
     *
     * @access  public
     */
    
function AddFont($family$style ''$file '')
    {
        
$family     strtolower($family);
        if (
$family == 'arial') {
            
$family 'helvetica';
        }

        
$style  strtoupper($style);
        if (
$style == 'IB') {
            
$style 'BI';
        }
        if (isset(
$this->fonts[$family $style])) {
            
$this->Error('Font already added: ' $family ' ' $style);
        }
        if (
$file == '') {
            
$file str_replace(' '''$family) . strtolower($style) . '.php';
        }
        if (isset(
$GLOBALS['FPDF_font_path'])) {
            
$file $GLOBALS['FPDF_font_path'] . $file;
        }
        include(
$file);
        if (!isset(
$name)) {
            
$this->Error('Could not include font definition file');
        }

        
$i count($this->fonts) + 1;
        
$this->fonts[$family $style] = array('i'    => $i,
                                               
'type' => $type,
                                               
'name' => $name,
                                               
'desc' => $desc,
                                               
'up'   => $up,
                                               
'ut'   => $ut,
                                               
'cw'   => $cw,
                                               
'enc'  => $enc,
                                               
'file' => $file);
        
// Searches existing encodings
        
if ($diff) {
            
$d  0;
            
$nb count($this->diffs);
            for (
$i 1$i <= $nb$i++) {
                if (
$this->diffs[$i] == $diff) {
                    
$d $i;
                    break;
                } 
// end if
            
// end for
            
if ($d == 0) {
                
$d               $nb 1;
                
$this->diffs[$d] = $diff;
            } 
// end if
            
$this->fonts[$family $style]['diff'] = $d;
        } 
// end if

        
if ($file) {
            if (
$type == 'TrueType') {
                
$this->FontFiles[$file] = array('length1' => $originalsize);
            } else {
                
$this->FontFiles[$file] = array('length1' => $size1'length2' => $size2);
            }
        } 
// end if
    
// end of the "AddFont()" method


    /**
     * Sets font size
     *
     * @param   double   The font size (in points)
     *
     * @access  public
     */
    
function SetFontSize($size)
    {
        if (
$this->FontSizePt == $size) {
            return;
        }
        
$this->FontSizePt $size;
        
$this->FontSize   $size $this->k;
        if (
$this->page 0) {
            
$this->_out(sprintf('BT /F%d %.2f Tf ET'$this->CurrentFont['i'], $this->FontSizePt));
        }
    } 
// end of the "SetFontSize()" method


    /**
     * Creates a new internal link
     *
     * @return  integer  The link id
     *
     * @access  public
     */
    
function AddLink()
    {
        
$n count($this->links) + 1;
        
$this->links[$n] = array(00);
        return 
$n;
    } 
// end of the "AddLink()" method


    /**
     * Sets destination of internal link
     *
     * @param   integer  The link id
     * @param   double   The y position on the page
     * @param   integer  The page number
     *
     * @access  public
     */
    
function SetLink($link$y 0$page = -1)
    {
        if (
$y == -1) {
            
$y    $this->y;
        }
        if (
$page == -1) {
            
$page $this->page;
        }
        
$this->links[$link] = array($page$y);
    } 
// end of the "SetLink()" method


    /**
     * Put a link inside a rectangular area of the page
     *
     * @param   double   The top left x position
     * @param   double   The top left y position
     * @param   double   The rectangle width
     * @param   double   The rectangle height
     * @param   mixed    The link id or an url
     *
     * @access  public
     */
    
function Link($x$y$w$h$link)
    {
        
$this->PageLinks[$this->page][] = array($x $this->k,
                                                
$this->hPt $y $this->k,
                                                
$w $this->k,
                                                
$h $this->k,
                                                
$link);
    } 
// end of the "Link()" method


    /**
     * Outputs a string
     *
     * @param   double  The x position
     * @param   double  The y position
     * @param   string  The string
     *
     * @access  public
     */
    
function Text($x$y$txt)
    {
        
$txt   str_replace(')''\\)'str_replace('(''\\('str_replace('\\''\\\\'$txt)));
        
$s     sprintf('BT %.2f %.2f Td (%s) Tj ET'$x $this->k, ($this->$y) * $this->k$txt);
        if (
$this->underline && $txt != '') {
            
$s .= ' ' $this->_dounderline($x$y$txt);
        }
        if (
$this->ColorFlag) {
            
$s 'q ' $this->TextColor ' ' $s ' Q';
        }
        
$this->_out($s);
    } 
// end of the "Text()" method


    /**
     * Gets whether automatic page break is on or not
     *
     * @return  boolean  Whether automatic page break is on or not
     *
     * @access  public
     */
    
function AcceptPageBreak()
    {
        return 
$this->AutoPageBreak;
    } 
// end of the "AcceptPageBreak()" method


    /**
     * Output a cell
     *
     * @param   double   The cell width
     * @param   double   The cell height
     * @param   string   The text to output
     * @param   mixed    Wether to add borders or not (see the manual)
     * @param   integer  Where to put the cursor once the output is done
     * @param   string   Align mode
     * @param   integer  Whether to fill the cell with a color or not
     * @param   mixed    The link id or an url
     *
     * @access  public
     */
    
function Cell($w$h 0$txt ''$border 0$ln 0$align ''$fill 0$link '')
    {
        
$k $this->k;

        if (
$this->$h $this->PageBreakTrigger
            
&& !$this->InFooter
            
&& $this->AcceptPageBreak()) {
            
$x  $this->x;
            
$ws $this->ws;
            if (
$ws 0) {
                
$this->ws 0;
                
$this->_out('0 Tw');
            }
            
$this->AddPage($this->CurOrientation);
            
$this->$x;
            if (
$ws 0) {
                
$this->ws $ws;
                
$this->_out(sprintf('%.3f Tw'$ws $k));
            }
        } 
// end if

        
if ($w == 0) {
            
$w $this->$this->rMargin $this->x;
        }

        
$s          '';
        if (
$fill == || $border == 1) {
            if (
$fill == 1) {
                
$op = ($border == 1) ? 'B' 'f';
            } else {
                
$op 'S';
            }
            
$s      sprintf('%.2f %.2f %.2f %.2f re %s '$this->$k, ($this->$this->y) * $k$w $k, -$h $k$op);
        } 
// end if

        
if (is_string($border)) {
            
$x     $this->x;
            
$y     $this->y;
            if (
strpos(' ' $border'L')) {
                
$s .= sprintf('%.2f %.2f m %.2f %.2f l S '$x $k, ($this->$y) * $k$x $k, ($this->- ($y+$h)) * $k);
            }
            if (
strpos(' ' $border'T')) {
                
$s .= sprintf('%.2f %.2f m %.2f %.2f l S '$x $k, ($this->$y) * $k, ($x $w) * $k, ($this->$y) * $k);
            }
            if (
strpos(' ' $border'R')) {
                
$s .= sprintf('%.2f %.2f m %.2f %.2f l S ', ($x $w) * $k, ($this->$y) * $k, ($x $w) * $k, ($this->- ($y $h)) * $k);
            }
            if (
strpos(' ' $border'B')) {
                
$s .= sprintf('%.2f %.2f m %.2f %.2f l S '$x $k, ($this->- ($y $h)) * $k, ($x $w) * $k, ($this->- ($y $h)) * $k);
            }
        } 
// end if

        
if ($txt != '') {
            if (
$align == 'R') {
                
$dx $w $this->cMargin $this->GetStringWidth($txt);
            }
            else if (
$align == 'C') {
                
$dx = ($w $this->GetStringWidth($txt)) / 2;
            }
            else {
                
$dx $this->cMargin;
            }
            
$txt    str_replace(')''\\)'str_replace('(''\\('str_replace('\\''\\\\'$txt)));
            if (
$this->ColorFlag) {
                
$s  .= 'q ' $this->TextColor ' ';
            }
            
$s      .= sprintf('BT %.2f %.2f Td (%s) Tj ET', ($this->$dx) * $k, ($this->- ($this->.5 $h .3 $this->FontSize)) * $k$txt);
            if (
$this->underline) {
                
$s  .= ' ' $this->_dounderline($this->x+$dx$this->.5 $h .3 $this->FontSize$txt);
            }
            if (
$this->ColorFlag) {
                
$s  .= ' Q';
            }
            if (
$link) {
                
$this->Link($this->$dx$this->.5 $h .5 $this->FontSize$this->GetStringWidth($txt), $this->FontSize$link);
            }
        } 
// end if

        
if ($s) {
            
$this->_out($s);
        }
        
$this->lasth $h;

        if (
$ln 0) {
            
// Go to next line
            
$this->y     += $h;
            if (
$ln == 1) {
                
$this->$this->lMargin;
            }
        } else {
            
$this->x     += $w;
        }
    } 
// end of the "Cell()" method


    /**
     * Output text with automatic or explicit line breaks
     *
     * @param   double   The cell width
     * @param   double   The cell height
     * @param   string   The text to output
     * @param   mixed    Wether to add borders or not (see the manual)
     * @param   string   Align mode
     * @param   integer  Whether to fill the cell with a color or not
     *
     * @access  public
     */
    
function MultiCell($w$h$txt$border 0$align 'J'$fill 0)
    {
        
// loic1: PHP3 compatibility
        // $cw    = &$this->CurrentFont['cw'];
        
if ($w == 0) {
            
$w $this->$this->lMargin $this->x;
        }
        
$wmax  = ($w $this->cMargin) * 1000 $this->FontSize;
        
$s     str_replace("\r"''$txt);
        
$nb    strlen($s);
        if (
$nb>&& $s[$nb 1] == "\n") {
            
$nb--;
        }

        
$b              0;
        if (
$border) {
            if (
$border == 1) {
                
$border 'LTRB';
                
$b      'LRT';
                
$b2     'LR';
            }
            else {
                
$b2     '';
                if (
strpos(' ' $border'L')) {
                    
$b2 .= 'L';
                }
                if (
strpos(' ' $border'R')) {
                    
$b2 .= 'R';
                }
                
$b      = (strpos(' ' $border'T')) ? $b2 'T' $b2;
            } 
// end if... else...
        
// end if

        
$sep = -1;
        
$i   0;
        
$j   0;
        
$l   0;
        
$ns  0;
        
$nl  1;
        while (
$i $nb) {
            
// Gets next character
            
$c $s[$i];

            
// Explicit line break
            
if ($c == "\n") {
                if (
$this->ws 0) {
                    
$this->ws 0;
                    
$this->_out('0 Tw');
                }
                
$this->Cell($w$hsubstr($s$j$i $j), $b2$align$fill);
                
$i++;
                
$sep   = -1;
                
$j     $i;
                
$l     0;
                
$ns    0;
                
$nl++;
                if (
$border && $nl == 2) {
                    
$b $b2;
                }
                continue;
            } 
// end if

            // Space character
            
if ($c == ' ') {
                
$sep $i;
                
$ls  $l;
                
$ns++;
            } 
// end if

            
$l += $this->CurrentFont['cw'][$c];
            if (
$l $wmax) {
                
// Automatic line break
                
if ($sep == -1) {
                    if (
$i == $j) {
                        
$i++;
                    }
                    if (
$this->ws 0) {
                        
$this->ws 0;
                        
$this->_out('0 Tw');
                    }
                    
$this->Cell($w$hsubstr($s$j$i $j), $b2$align$fill);
                }
                else {
                    if (
$align == 'J') {
                        
$this->ws = ($ns 1)
                                  ? (
$wmax $ls) / 1000 $this->FontSize / ($ns 1)
                                  : 
0;
                        
$this->_out(sprintf('%.3f Tw'$this->ws $this->k));
                    }
                    
$this->Cell($w$hsubstr($s$j$sep $j), $b2$align$fill);
                    
$i $sep 1;
                } 
// end if... else...

                
$sep   = -1;
                
$j     $i;
                
$l     0;
                
$ns    0;
                
$nl++;
                if (
$border && $nl == 2) {
                    
$b $b2;
                }
            }
            else {
                
$i++;
            } 
// end if... else
        
// end while

        // Last chunk
        
if ($this->ws 0) {
            
$this->ws 0;
            
$this->_out('0 Tw');
        }

        if (
$border && strpos(' ' $border'B')) {
            
$b .= 'B';
        }
        
$this->Cell($w$hsubstr($s$j$i), $b2$align$fill);
        
$this->$this->lMargin;
    } 
// end of the "MultiCell()" method


    /**
     * Output text in flowing mode
     *
     * @param   double   The line height
     * @param   string   The text to output
     * @param   mixed    The link id or an url
     *
     * @access  public
     */
    
function Write($h$txt$link '')
    {
        
$w    $this->$this->rMargin $this->x;
        
$wmax = ($w $this->cMargin) * 1000 $this->FontSize;
        
$s    str_replace("\r"''$txt);
        
$nb   strlen($s);
        
$sep  = -1;
        
$i    0;
        
$j    0;
        
$l    0;
        
$nl   1;

        while (
$i $nb) {
            
// Gets next character
            
$c $s[$i];

            
// Explicit line break
            
if ($c == "\n") {
                
$this->Cell($w$hsubstr($s$j$i $j), 02''0$link);
                
$i++;
                
$sep = -1;
                
$j   $i;
                
$l   0;
                if (
$nl == 1) {
                    
$this->$this->lMargin;
                    
$w       $this->$this->rMargin $this->x;
                    
$wmax    = ($w $this->cMargin) * 1000 $this->FontSize;
                }
                
$nl++;
                continue;
            }

            
// Space character
            
if ($c == ' ') {
                
$sep $i;
                
$ls  $l;
            } 
// end if

            
$l += $this->CurrentFont['cw'][$c];
            if (
$l $wmax) {
                
// Automatic line break
                
if ($sep == -1) {
                    if (
$this->$this->lMargin)  {
                        
// Move to next line
                        
$this->=$this->lMargin;
                        
$this->+=$h;
                        
$w       $this->$this->rMargin $this->x;
                        
$wmax    =($w $this->cMargin) * 1000 $this->FontSize;
                        
$i++;
                        
$nl++;
                        continue;
                    }
                    if (
$i == $j) {
                        
$i++;
                    }
                    
$this->Cell($w$hsubstr($s$j$i $j), 02''0$link);
                }
                else {
                    
$this->Cell($w$hsubstr($s$j$sep $j), 02''0$link);
                    
$i $sep 1;
                } 
// end if... else...

                
$sep         = -1;
                
$j           $i;
                
$l           0;
                if (
$nl == 1) {
                    
$this->$this->lMargin;
                    
$w       $this->$this->rMargin $this->x;
                    
$wmax    = ($w $this->cMargin) * 1000 $this->FontSize;
                }
                
$nl++;
            }
            else {
                
$i++;
            } 
// end if... else...
        
// end while

        // Last chunk
        
if ($i != $j) {
            
$this->Cell($l 1000 $this->FontSize$hsubstr($s$j$i), 00''0$link);
        }
    } 
// end of the "Write()" method


    /**
     * Puts an image on the page
     *
     * @param   string   The image file (JPEG or PNG format)
     * @param   double   The top left x position
     * @param   double   The top left y position
     * @param   double   The image width
     * @param   double   The image height
     * @param   string   The image type (JPG, JPEG or PNG)
     * @param   mixed    The link id or an url
     *
     * @access  public
     */
    
function Image($file$x$y$w$h 0$type ''$link '')
    {
        if (!isset(
$this->images[$file])) {
            
// First use of image, get info
            
if ($type == '') {
                
$pos strrpos($file'.');
                if (!
$pos) {
                    
$this->Error('Image file has no extension and no type was specified: ' $file);
                }
                
$type substr($file$pos 1);
            } 
// end if

            
$type strtolower($type);
            
$mqr  get_magic_quotes_runtime();
            
set_magic_quotes_runtime(0);
            if (
$type == 'jpg' || $type == 'jpeg') {
                
$info $this->_parsejpg($file);
            }
            else if (
$type == 'png') {
                
$info $this->_parsepng($file);
            }
            else {
                
$this->Error('Unsupported image file type: ' $type);
            }
            
set_magic_quotes_runtime($mqr);
            
$info['i']           = count($this->images) + 1;
            
$this->images[$file] = $info;
        }
        else {
            
$info                $this->images[$file];
        } 
// end if... else...

        // Automatic width or height calculation
        
if ($w == 0) {
            
$w $h $info['w'] / $info['h'];
        }
        if (
$h == 0) {
            
$h $w $info['h'] / $info['w'];
        }
        
$this->_out(sprintf('q %.2f 0 0 %.2f %.2f %.2f cm /I%d Do Q'$w $this->k$h $this->k$x $this->k, ($this->- ($y $h)) * $this->k$info['i']));

        if (
$link) {
            
$this->Link($x$y$w$h$link);
        }
    } 
// end of the "Image()" method


    /**
     * Appends a line feed
     *
     * @param   double   The line height
     *
     * @access  public
     */
    
function Ln($h '')
    {
        
$this->$this->lMargin;
        
// Sets default line height to last cell height
        
if (is_string($h)) {
            
$this->+= $this->lasth;
        }
        else {
            
$this->+= $h;
        }
    } 
// end of the "Ln()" method


    /**
     * Gets x position
     *
     * @return  double  The x position
     *
     * @access  public
     */
    
function GetX()
    {
        return 
$this->x;
    } 
// end of the "GetX()" method


    /**
     * Sets x position
     *
     * @param   double  The x position
     *
     * @access  public
     */
    
function SetX($x)
    {
        if (
$x >= 0) {
            
$this->$x;
        } else {
            
$this->$this->$x;
        }
    } 
// end of the "SetX()" method


    /**
     * Gets y position
     *
     * @return  double  The y position
     *
     * @access  public
     */
    
function GetY()
    {
        return 
$this->y;
    } 
// end of the "GetY()" method


    /**
     * Sets y position and resets x
     *
     * @param   double  The y position
     *
     * @access  public
     */
    
function SetY($y)
    {
        
$this->$this->lMargin;
        if (
$y >= 0) {
            
$this->$y;
        } else {
            
$this->$this->$y;
        }
    } 
// end of the "SetY()" method


    /**
     * Sets x and y positions
     *
     * @param   double  The x position
     * @param   double  The y position
     *
     * @access  public
     */
    
function SetXY($x,$y)
    {
        
$this->SetY($y);
        
$this->SetX($x);
    } 
// end of the "SetXY()" method


    /**
     * Outputs PDF to file or browser
     *
     * @param   string   The file name
     * @param   boolean  Whether to display the document inside the browser
     *                   (with Acrobat plugin), to enforce download as file or
     *                   to save it on the server
     *
     * @global  string   The browser id string
     *
     * @access  public
     */
    
function Output($file ''$download FALSE)
    {
        global 
$HTTP_USER_AGENT;

        if (
$this->state 3) {
            
$this->Close();
        }

        
// Send to browser
        
if ($file == '') {
            
header('Content-Type: application/pdf');
            if (
headers_sent()) {
                
$this->Error('Some data has already been output to browser, can\'t send PDF file');
            }
            
header('Content-Length: ' strlen($this->buffer));
            
header('Content-Disposition: inline; filename=doc.pdf');
            echo 
$this->buffer;
        }
        
// Download file
        
else if ($download) {
            if (!empty(
$HTTP_USER_AGENT)
                && (
strpos($HTTP_USER_AGENT'MSIE 5.5') || strpos($HTTP_USER_AGENT'Opera'))) {
                
header('Content-Type: application/dummy');
            }
            
// fix for Gecko-based browsers < 1.1
            
else if (!empty($HTTP_USER_AGENT)
                  &&  (
strpos($HTTP_USER_AGENT'Gecko') &&
                  (
strpos($HTTP_USER_AGENT'rv:0.') || strpos($HTTP_USER_AGENT'rv:1.0') || strpos($HTTP_USER_AGENT'rv:1.1')))) {
                     
header('Content-Type: application/');
            }
            else {
                
header('Content-Type: application/pdf');
            }
            if (
headers_sent()) {
                
$this->Error('Some data has already been output to browser, can\'t send PDF file');
            }
            
header('Content-Length: ' strlen($this->buffer));
            
header('Content-Disposition: attachment; filename=' $file);
            echo 
$this->buffer;
        }
        
// Save file locally
        
else {
            
$f fopen($file'wb');
            if (!
$f) {
                
$this->Error('Unable to create output file: ' $file);
            }
            
fwrite($f$this->bufferstrlen($this->buffer));
            
fclose($f);
        } 
// end if... else if... else
    
// end of the "Output()" method

// End of the "FPDF" class



/**
 * Handles silly IE contype request
 */
if (!empty($_ENV) && isset($_ENV['HTTP_USER_AGENT'])) {
    
$HTTP_USER_AGENT $_ENV['HTTP_USER_AGENT'];
}
else if (!empty(
$_SERVER) && isset($_SERVER['HTTP_USER_AGENT'])) {
    
$HTTP_USER_AGENT $_SERVER['HTTP_USER_AGENT'];
}
else if (@
getenv('HTTP_USER_AGENT')) {
    
$HTTP_USER_AGENT getenv('HTTP_USER_AGENT');
}

if (
$HTTP_USER_AGENT == 'contype') {
    
header('Content-Type: application/pdf');
    exit();
}
?>