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
|
<?php //=================================================================================================== // this is the php file which creates the readme.pdf file, this is not seriously // suggested as a good way to create such a file, nor a great example of prose, // but hopefully it will be useful // // adding ?d=1 to the url calling this will cause the pdf code itself to ve echoed to the // browser, this is quite useful for debugging purposes. // there is no option to save directly to a file here, but this would be trivial to implement. // // note that this file comprisises both the demo code, and the generator of the pdf documentation // //===================================================================================================
// don't want any warnings turning up in the pdf code if the server is set to 'anal' mode. //error_reporting(7); error_reporting(E_ALL); set_time_limit(1800);
include 'class.ezpdf.php';
// define a clas extension to allow the use of a callback to get the table of contents, and to put the dots in the toc class Creport extends Cezpdf {
var $reportContents = array();
function Creport($p,$o){ $this->Cezpdf($p,$o); }
function rf($info){ // this callback records all of the table of contents entries, it also places a destination marker there // so that it can be linked too $tmp = $info['p']; $lvl = $tmp[0]; $lbl = rawurldecode(substr($tmp,1)); $num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber()); $this->reportContents[] = array($lbl,$num,$lvl ); $this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']); }
function dots($info){ // draw a dotted line over to the right and put on a page number $tmp = $info['p']; $lvl = $tmp[0]; $lbl = substr($tmp,1); $xpos = 520;
switch($lvl){ case '1': $size=16; $thick=1; break; case '2': $size=12; $thick=0.5; break; }
$this->saveState(); $this->setLineStyle($thick,'round','',array(0,10)); $this->line($xpos,$info['y'],$info['x']+5,$info['y']); $this->restoreState(); $this->addText($xpos+5,$info['y'],$size,$lbl);
}
} // I am in NZ, so will design my page for A4 paper.. but don't get me started on that. // (defaults to legal) // this code has been modified to use ezpdf.
//$pdf = new Cezpdf('a4','portrait'); $pdf = new Creport('a4','portrait');
$pdf -> ezSetMargins(50,70,50,50);
//$mainFont = './fonts/Helvetica.afm'; $mainFont = './fonts/Times-Roman.afm'; $codeFont = './fonts/Courier.afm'; // select a font $pdf->selectFont($mainFont);
$pdf->openHere('Fit');
if (file_exists('ros.jpg')){ $pdf->addJpegFromFile('ros.jpg',199,$pdf->y-100,200,0); } else { // comment out these two lines if you do not have GD jpeg support // I couldn't quickly see a way to test for this support from the code. // you could also copy the file from the locatioin shown and put it in the directory, then // the code above which doesn't use GD will be activated. $img = ImageCreatefromjpeg('http://www.ros.co.nz/pdf/ros.jpg'); $pdf-> addImage($img,199,$pdf->y-100,200,0); }
//----------------------------------------------------------- // load up the document content //$data=file('./data.txt');
// try adding the faq's to the document, this will not work for people re-building the file from the // download as I am not going to put in the faq file with that
if (isset($d) && $d){ $pdfcode = $pdf->ezOutput(1); $pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode)); echo '<html><body>'; echo trim($pdfcode); echo '</body></html>'; } else { $pdf->ezStream(); } ?>
|