PDF generation working much better. Still to do: the Products table etc

This commit is contained in:
Karl Cordes 2009-10-09 18:10:41 +11:00
parent 60e569cddc
commit 7a5ab3343c
3 changed files with 72 additions and 20 deletions

55
vendors/xtcpdf.php vendored
View file

@ -38,11 +38,13 @@ class XTCPDF extends TCPDF
$this->Cell(0,0, $this->xheadertext, 0,1,'C', 1); $this->Cell(0,0, $this->xheadertext, 0,1,'C', 1);
$this->SetFontSize(10); $this->SetFontSize(10);
$this->Cell(30); $this->Cell(30);
$this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224, ABN 47 085 991 224", 0, 1, 'C', 1); $this->Cell(0,0, "PTY LIMITED ACN: 47 085 991 224 ABN: 47 085 991 224", 0, 1, 'C', 1);
$this->Rect($this->GetX()+20, $this->GetY(), 180, 2, 'DF', array('width'=>0), array(0, 0, 152));
/* Start the contact details */ /* Start the contact details */
$this->SetTextColor(0); //Set the Text Color to Black $this->SetTextColor(0); //Set the Text Color to Black
$this->MultiCell(18, 0, "Phone:\nFax:\nEmail:\nWeb Site:\n", 0, 'L', 0, 0, 45, 23); $this->MultiCell(18, 0, "Phone:\nFax:\nEmail:\nWeb Site:\n", 0, 'L', 0, 0, 45, 25);
@ -82,8 +84,57 @@ class XTCPDF extends TCPDF
*/ */
function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber) { function DetailsBox($companyName, $emailTo, $attention, $fromName, $fromEmail, $enquiryNumber) {
$this->SetTextColor(0); //Black Text
$boxYstart = 45;
$boxXstart = 5;
$firstColWidth = 40;
$secondColWidth = 80;
$thirdColWidth = 30;
$fourthColWidth = 45;
$pageNo = $this->PageNoFormatted();
//$pageOf = $this->getAliasNbPages();
/* Debugging Vars */
$companyName = "SomeBigCompanyCorp";
$emailTo = "theman@theman.com";
$attention = "Joe Bloggs";
$fromName = "Mr Sales Man";
$fromEmail = "SalesMan@cmctechnologies.com.au";
$enquiryNumber = "CMC1234NE22656-41";
$this->SetXY($boxXstart, 45);
$this->Cell($firstColWidth, 0, "QUOTATION TO:", 'LTRB', 0, 'L', 0, null, 0, false);
$this->Cell($secondColWidth, 0, $companyName, 'LTRB', 0, 'L', 0, null, 0, false);
$this->Cell($thirdColWidth, 0, "FROM:", 'LTB', 0, 'L', 0, null, 0, false);
$this->Cell($fourthColWidth, 0, $fromName, 'TBR', 1, 'L', 0, null, 0, false); //Start a new line after this.
$this->SetX($boxXstart);
$this->Cell($firstColWidth, 0, "EMAIL TO:", 'LTRB', 0, 'L', 0, null, 0, false);
$this->Cell($secondColWidth, 0, $emailTo, 'LTRB', 0, 'L', 0, "mailto:$emailTo", 0, false);
$this->Cell($thirdColWidth, 0, "CMC REF#:", 'LTB', 0, 'L', 0, null, 0, false);
$this->Cell($fourthColWidth, 0, $enquiryNumber, 'TBR', 1, 'L', 0, null, 0, false); //Start a new line after thi
$this->SetX($boxXstart);
$this->Cell($firstColWidth, 0, "ATTENTION:", 'LTRB', 0, 'L', 0, null, 0, false);
$this->Cell($secondColWidth, 0, $attention, 'LTRB', 0, 'L', 0, "mailto:$emailTo", 0, false);
$this->Cell($thirdColWidth, 0, "PAGE: ", 'LTB', 0, 'L', 0, null, 0, false);
$this->Cell($fourthColWidth, 0, "$pageNo of {nb}", 'TBR', 1, 'L', 0, null, 0, false); //Start a new line after thi
$this->lastPage();
//$this->Cell($w, $h, $txt, $border, $ln, $align, $fill, $link, $stretch, $ignore_min_height)
// $this->MultiCell($firstColWidth, 0, "QUOTATION TO:", 'LTRB', 'L', 0, 0, $boxXstart, $boxYstart, false, false, true, false, 0);
//Next Cell to the right.
//$this->MultiCell(50, 0, "COMPANY NAME", 'LTRB', 'L', 0, 0, $boxXstart, $boxYstart+$firstColWidth, true, false, true, true, 0);
//$this->MultiCell($w, $h, $txt, $border, $align, $fill, $ln, $x, $y, $reseth, $stretch, $ishtml, $autopadding, $maxh)
} }
} }
?> ?>

View file

@ -1,7 +1,7 @@
<?php <?php
App::import('Vendor','xtcpdf'); App::import('Vendor','xtcpdf');
$tcpdf = new XTCPDF(); $tcpdf = new XTCPDF();
$textfont = 'freeserif'; // looks better, finer, and more condensed than 'dejavusans' $textfont = 'times'; // looks better, finer, and more condensed than 'dejavusans'
$tcpdf->SetTopMargin(0); $tcpdf->SetTopMargin(0);
@ -15,6 +15,7 @@ $tcpdf->xfootertext = 'Copyright © %d CMC Technologies. All rights reserved.';
$tcpdf->Header(); $tcpdf->Header();
// Now you position and print your page content // Now you position and print your page content
// example: // example:
/*$tcpdf->SetTextColor(0, 0, 0); /*$tcpdf->SetTextColor(0, 0, 0);
@ -24,6 +25,8 @@ $tcpdf->Cell(0,14, "Hello World", 0,1,'L');
$tcpdf->AddPage(); $tcpdf->AddPage();
$tcpdf->DetailsBox();
$content = <<<ENDCONTENT $content = <<<ENDCONTENT
<p> <p>
@ -32,27 +35,21 @@ $content = <<<ENDCONTENT
<br /> <br />
<strong>RE: Awesome Products</strong></p> <strong>RE: Awesome Products</strong></p>
<p> <p>
Thank you for your enquiry regarding our Products. Please see the following quotation for:</p> Thank you for your enquiry regarding our Awesome Products. Please see the following quotation for:</p>
<table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 100%;"> <table align="center" border="0" cellpadding="1" cellspacing="1" style="width: 100%;">
<tbody> <tbody>
<tr> <tr>
<td> <td>Item</td>
Item</td> <td>Product</td>
<td>
Product</td>
</tr> </tr>
<tr> <tr>
<td> <td>1.0</td>
&nbsp;</td> <td>A Product (TM)</td>
<td>
&nbsp;</td>
</tr> </tr>
<tr> <tr>
<td> <td>2.0</td>
&nbsp;</td> <td>Another Product</td>
<td>
&nbsp;</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
@ -80,14 +77,18 @@ $content = <<<ENDCONTENT
&nbsp;</p> &nbsp;</p>
<p> <p>
&nbsp;</p> &nbsp;</p>
<p>
<em>SOMEONE</em></p>
ENDCONTENT; ENDCONTENT;
$currentX = $tcpdf->GetX();
$currentY = $tcpdf->GetY();
$tcpdf->SetTextColor(0); $tcpdf->SetTextColor(0);
$tcpdf->writeHTMLCell(0, 0, $currentX, 50, $content, 'LTRB', 1, 0, true, 'L', true); $tcpdf->SetFont('times', '', 12);
$tcpdf->writeHTMLCell(0, 0, $currentX, $currentY+5, $content, 'LTRB', 1, 0, true, 'L', true);
$tcpdf->lastPage(); $tcpdf->lastPage();
@ -95,7 +96,7 @@ $tcpdf->AddPage();
//$tcpdf->writeHTML($content, true, 0, true, 0); //$tcpdf->writeHTML($content, true, 0, true, 0);
$tcpdf->lastPage(); $tcpdf->lastPage();
$tcpdf->AliasNbPages();
$tcpdf->Output('/var/www/cake/app/webroot/pdf/filename1.pdf', 'F'); $tcpdf->Output('/var/www/cake/app/webroot/pdf/filename1.pdf', 'F');
?> ?>

Binary file not shown.