5 # PHP Objects for Generating PostScript and PDF Documents 7 # Copyright 1999-2001 Axis Data 8 # This code is free software that can be used or redistributed under the 9 # terms of Version 2 of the GNU General Public License, as published by the 10 # Free Software Foundation (http://www.fsf.org). 12 # Author: Edward Almasy (almasy@axisdata.com) 14 # Part of the AxisPHP library v1.2.4 15 # For more information see http://www.axisdata.com/AxisPHP/ 21 # ---- PUBLIC INTERFACE -------------------------------------------------- 26 # print document header 31 # set default font for document 32 $this->
SetFont(
"Times-Roman", 12);
34 # set reasonable default starting coordinates 40 # increment our internal page number value 48 $SpacingMultiplier = 1.35;
52 $this->YPos -= (int)($this->
GetFontHeight() * $SpacingMultiplier);
56 $this->XPos -= (int)($this->
GetFontHeight() * $SpacingMultiplier);
62 $this->XPos = $NewXPos;
67 $this->YPos = $NewYPos;
99 $OutputFilePointer = fopen($FileName,
"w+") or die(
"unable to open PostScript output file ".$FileName);
101 # write out document header 102 fwrite($OutputFilePointer,
"%!PS-Adobe-2.0 104 %%Orientation: Landscape 106 /UseFont { findfont exch scalefont setfont } bind def 110 # for each page that has text 113 # if there is text on the page 114 if (strlen($this->PageText[$Index]) > 0)
116 # write out page text 117 fwrite($OutputFilePointer, $this->PageText[$Index]);
119 # write out page footer 120 fwrite($OutputFilePointer,
" 128 # write out document footer 129 fwrite($OutputFilePointer,
" 135 fclose($OutputFilePointer);
140 # create PostScript file 141 $PSFileName = tempnam(
"/tmp", $FileNamePrefix) or die(
"unable to generate temporary file name for PostScript file for PDF generation");
144 # build PostScript-to-PDF command string 145 $Command = sprintf(
"cat %s | gs -q -sDEVICE=pdfwrite -sOutputFile=%s - ",
146 $PSFileName, $OutputFileName);
148 # run PostScript-to-PDF command 151 # remove PostScript file 152 system(sprintf(
"rm %s", $PSFileName));
157 $this->PrintCommand = $NewPrintCommand;
163 $OutputFileName = tempnam(
"/tmp", $FileNamePrefix) or die(
"unable to generate temporary file name for PostScript file");
165 # dump document to file 168 # substitute file name into print command 169 $Command = str_replace(
"%f", $OutputFileName, $this->PrintCommand);
171 # issue print command 172 system(EscapeShellCmd($Command));
174 # return file name to caller 175 return $OutputFileName;
180 $this->PageHeightInPoints = $PointsHigh;
181 $this->PageWidthInPoints = $PointsWide;
186 $this->TextWrapLength = $NewLength;
193 ", $FontSize, $FontName));
195 $this->FontSize = $FontSize;
200 return (
int)($this->FontSize * 0.8);
205 if ($NewPageNumber != -1)
209 if ($this->
PageNumber > $this->HighestPageNumber)
219 # trim off any leading or trailing whitespace in string 220 $TextToPrint = trim($TextToPrint);
222 # split string into pieces delineated by newlines 223 $TextArray = split(
"\n", $TextToPrint);
225 # for each string in array 226 for ($Index = 0; $Index < count($TextArray); $Index++)
228 # trim off any leading or trailing whitespace in string 229 $Text = trim($TextArray[$Index]);
231 # if string is not empty 232 if (strlen($Text) > 0)
234 # if text wrap length is set and string is longer than that 235 if (($this->TextWrapLength > 0)
236 && (strlen($Text) > $this->TextWrapLength))
238 # append portion of string beyond wrap len to next string 239 $TextArray[$Index + 1] = substr($Text, $this->TextWrapLength)
240 .
" ".$TextArray[$Index + 1];
242 # trim off portion of string beyond wrap len 243 $Text = substr($Text, 0, $this->TextWrapLength);
246 # escape any Postscript delimiters in string 247 $Text = str_replace(
"(",
"\(", $Text);
248 $Text = str_replace(
")",
"\)", $Text);
253 $this->
PrintRaw(sprintf(
"%s %s moveto\n",
259 $this->
PrintRaw(sprintf(
"%s %s moveto\n",
265 $this->
PrintRaw(sprintf(
"-%s rotate\n",
268 $this->
PrintRaw(sprintf(
"(%s) show\n", $Text));
271 $this->
PrintRaw(sprintf(
"%s rotate\n",
277 if ($Index < (count($TextArray) - 1))
306 ", (0 - $this->PageWidthInPoints)));
311 $this->StyleInfo[$StyleName][
"FontName"] = $FontName;
312 $this->StyleInfo[$StyleName][
"FontSize"] = $FontSize;
320 $this->StyleInfo[$StyleName][
"FontSize"],
321 $this->StyleInfo[$StyleName][
"FontName"]));
323 $this->FontSize = $this->StyleInfo[$StyleName][
"FontSize"];
328 # add string to page text 333 # ---- PRIVATE INTERFACE ------------------------------------------------- 335 # array of text for each page 338 # current print position 342 # current page number 345 # highest page number with text on it 348 # current text rotation angle 351 # values for last table printed 357 # values for last font set 360 # default to letter size (792x612) 367 # font style settings 370 # current string wrap length
WritePDFToFile($OutputFileName)
SetTextWrapLength($NewLength=0)
SetFont($FontName, $FontSize)
SetPrintCommand($NewPrintCommand)
PrintDocument($FileNamePrefix="PSDocument")
PrintTextAt($XPos, $YPos, $TextToPrint)
WritePostscriptToFile($FileName)
UseLandscapeOrientation()
PageNumber($NewPageNumber=-1)
DefineStyle($StyleName, $FontName, $FontSize)
MoveTo($NewXPos, $NewYPos)
SetPageSize($PointsHigh, $PointsWide)