Op de 1 of andere manier doe ik iets fout met het toevoegen van een plaatje in een pdf bestand. Ik probeer het volgende:
public function drawImage()
{
$image = Zend_Pdf_Image::imageWithPath('/home/**/domains/**/public_html/***.png');
$this->drawImage($image, 10, 10 , 211, 64);
}
Maar ik krijg de volgende foutmelding over de max execution time. En als ik die verleng krijg ik een error dat ik te weinig geheugen heb.
Waarschijnlijk zie ik iets over het hoofd, dat ik iets niet afsluit o.i.d. want een .png van een paar kb moet toch geen problemen geven.
Script:
<?php
class VWM_Invoice extends VWM_Pdf implements VWM_Templates_Interface
{
/**
* Generate PDF
*
* @param int $orderCode
* @param array $orderData
* @param array $orderItems
* @param array $orderPaper
* @return void
*/
public function generatePdf($orderCode, $orderData, $orderItems, $orderPaper = false)
{
// Order data
$oDebtors = new Debtors();
$debtorData = $oDebtors -> find($orderData['invoice_debID']) -> current() -> toArray();
$oSettings = new Settings();
$this -> _data['company']['name'] = $oSettings -> get('companyName');
$this -> _data['company']['website'] = $oSettings -> get('companyWebsite');
$this -> _data['company']['email'] = $oSettings -> get('companyEmail');
$this -> _data['company']['address'] = $oSettings -> get('companyAddress');
$this -> _data['company']['zipcode'] = $oSettings -> get('companyZipcode');
$this -> _data['company']['place'] = $oSettings -> get('companyPlace');
$this -> _data['company']['phonenr'] = $oSettings -> get('companyPhonenr');
$this -> _data['company']['faxnr'] = $oSettings -> get('companyFaxnr');
$this -> _data['company']['kvknr'] = $oSettings -> get('companyKvknr');
$this -> _data['company']['vatnr'] = $oSettings -> get('companyVatnr');
$this -> _data['company']['ibannr'] = $oSettings -> get('companyPaymentIBANnr');
$this -> _data['company']['bicnr'] = $oSettings -> get('companyPaymentBICnr');
$this -> _data['company']['billnr'] = $oSettings -> get('companyPaymentBillnr');
$this -> _data['company']['tnv'] = $oSettings -> get('companyPaymentTNV');
$this -> _data['customer']['code'] = $debtorData['debCode'];
$this -> _data['customer']['companyName'] = $debtorData['debCompanyname'];
$this -> _data['customer']['firstName'] = $debtorData['debFirstname'];
$this -> _data['customer']['lastName'] = $debtorData['debSurname'];
$this -> _data['customer']['address'] = $debtorData['debAddress'];
$this -> _data['customer']['zipcode'] = $debtorData['debZipcode'];
$this -> _data['customer']['place'] = $debtorData['debPlace'];
$this -> _data['customer']['country'] = $debtorData['debCountry'];
$this -> _data['customer']['vatnr'] = $debtorData['debVatnr'];
$this -> _data['order']['code'] = $orderCode;
$this -> _data['order']['date'] = date('d-m-Y', strtotime($orderData['invoiceDate']));
$this -> _data['order']['priceExcl'] = number_format($orderData['invoicePriceExcl'], 2, ',', '.');
$this -> _data['order']['priceVat'] = number_format($orderData['invoicePriceVat'], 2, ',', '.');
$this -> _data['order']['priceIncl'] = number_format($orderData['invoicePriceIncl'], 2, ',', '.');
$this -> _data['order']['discount'] = ($orderData['invoiceDiscount'] != 0) ? $orderData['invoiceDiscount'] : 0;
$this -> _data['order']['paymentTerms'] = 'Te betalen binnen ' . $orderData['invoicePayment'] . ' dagen na de factuurdatum op rekeningnummer ' . $this -> _data['company']['billnr'] . ' t.n.v. ' . $this -> _data['company']['tnv'] . ' onder vermelding van klantnummer en factuurnummer.';
//$this -> _data['columns'][] = array('value' => 'Prodnr', 'size' => 40, 'align' => 'right', 'font' => Zend_Pdf_Font::FONT_HELVETICA_BOLD, 'fontSize' => 12);
$this -> _data['columns'][] = array('value' => 'Aantal', 'size' => 40, 'align' => 'center', 'font' => Zend_Pdf_Font::FONT_HELVETICA_BOLD, 'fontSize' => 12);
$this -> _data['columns'][] = array('value' => 'Omschrijving', 'margin' => 10, 'font' => Zend_Pdf_Font::FONT_HELVETICA_BOLD, 'fontSize' => 12);
$this -> _data['columns'][] = array('value' => 'Prijs / stuk', 'size' => 60, 'align' => 'right', 'font' => Zend_Pdf_Font::FONT_HELVETICA_BOLD, 'fontSize' => 12);
$this -> _data['columns'][] = array('value' => 'Subtotaal', 'size' => 60, 'align' => 'right', 'font' => Zend_Pdf_Font::FONT_HELVETICA_BOLD, 'fontSize' => 12);
$this -> _data['recordsFont'] = array('font' => 'Helvetica', 'fontSize' => 12, 'fontColor' => '#000000');
foreach($orderItems as $orderItem)
{
if(!isset($orderItem['invoiceprodPriceRow']))
{
$orderItem['invoiceprodPriceRow'] = $orderItem['invoiceprodCount'] * $orderItem['invoiceprodPriceExcl'];
}
$this -> _data['records'][] = array(
//$orderItem['invoiceprod_prodCode'],
$orderItem['invoiceprodCount'],
$orderItem['invoiceprodDesc'],
number_format($orderItem['invoiceprodPriceExcl'], 2, ',', '.'),
number_format($orderItem['invoiceprodPriceRow'], 2, ',', '.')
);
}
// Generate pdf
$file = APPLICATION_PATH . '/data/templates/template.pdf';
if(file_exists($file) && $orderPaper === false)
{
$this -> setPdf(Zend_Pdf::load($file));
$this -> setTemplate($this -> getPdf() -> pages[0]);
$this -> setPage(new Zend_Pdf_Page($this -> getTemplate()));
$this -> getPdf() -> pages[] = $this -> getPage();
unset($this -> getPdf() -> pages[0]);
}
else
{
$this -> setPdf(new Zend_Pdf());
$this -> setPage($this -> getPdf() -> newPage(Zend_Pdf_Page::SIZE_A4));
$this -> getPdf() -> pages[] = $this -> getPage();
}
$this -> createPageHeader();
$this -> createCustomerBox();
$this -> createOrderDetails();
$this -> createOrderGrid();
$this -> createPageFooter();
//$this -> drawImage();
$this -> getPdf() -> save(APPLICATION_PATH . '/data/invoices/' . $this -> _data['order']['code'] . '.pdf');
}
/**
* Create page header
*
* @return void
*/
public function drawImage()
{
$image = Zend_Pdf_Image::imageWithPath('/home/**/domains/**/public_html/**.png');
$this->drawImage($image, 10, 10 , 211, 64);
}
public function createPageHeader()
{
$topPosition = self::HEADER_TOP;
$this -> setFontAndSize('Helvetica', 8);
$this -> write($this -> _data['company']['name'], 270, $topPosition);
$this -> write($this -> _data['company']['address'], 270, $topPosition - 10);
$this -> write($this -> _data['company']['zipcode'] . ' ' . $this -> _data['company']['place'], 270, $topPosition - 20);
$this -> write('Email', 270, $topPosition - 30);
$this -> write($this -> _data['company']['email'], 270, $topPosition - 40);
$this -> write('Telefoon', 390, $topPosition);
$this -> write($this -> _data['company']['phonenr'], 390, $topPosition - 10);
$this -> write('Fax', 390, $topPosition - 20);
$this -> write($this -> _data['company']['faxnr'], 390, $topPosition - 30);
$this -> write('Web', 390, $topPosition - 40);
$this -> write($this -> _data['company']['website'], 390, $topPosition - 50);
$this -> write('BTW nr', 490, $topPosition);
$this -> write($this -> _data['company']['vatnr'], 490, $topPosition - 10);
$this -> write('KVK nr', 490, $topPosition - 20);
$this -> write($this -> _data['company']['kvknr'], 490, $topPosition - 30);
$this -> setPageHeight($topPosition - 90);
}
/**
* Create customer box
*
* @return void
*/
public function createCustomerBox()
{
$topPosition = $this -> getPageHeight();
$this -> setFontAndSize('Helvetica', 12);
if(!empty($this -> _data['customer']['companyName']))
{
$this -> write($this -> _data['customer']['companyName'], 300, $topPosition - 15);
}
else
{
$this -> write($this -> _data['customer']['firstName'] . ' ' . $this -> _data['customer']['lastName'], 300, $topPosition - 15);
}
$this -> write($this -> _data['customer']['address'], 300, $topPosition - 27);
$this -> write($this -> _data['customer']['zipcode'] . ' ' . $this -> _data['customer']['place'], 300, $topPosition - 39);
$this -> write($this -> _data['customer']['country'], 300, $topPosition - 50);
$pageHeight = $this -> getPageHeight();
$this -> setPageHeight($pageHeight -= 130);
}
/**
* Create order details
*
* @return void
*/
public function createOrderDetails()
{
$topPosition = $this -> getPageHeight();
$this -> setFontAndSize(Zend_Pdf_Font::FONT_HELVETICA_BOLD, 22);
$this -> write('Factuur', self::PAGE_BOTH_MARGIN + 10, $topPosition + 40);
$this -> setFontAndSize('Helvetica', 12);
$topPosition += 20;
$this -> write('Factuurnr', self::PAGE_BOTH_MARGIN + 10, $topPosition);
$this -> write($this -> _data['order']['code'], self::PAGE_BOTH_MARGIN + 100, $topPosition);
$this -> write('Klantnr', self::PAGE_BOTH_MARGIN + 280, $topPosition);
$this -> write($this -> _data['customer']['code'], self::PAGE_BOTH_MARGIN + 370, $topPosition);
$topPosition -= 12;
$this -> write('Factuurdatum', self::PAGE_BOTH_MARGIN + 10, $topPosition);
$this -> write($this -> _data['order']['date'], self::PAGE_BOTH_MARGIN + 100, $topPosition);
$this -> setPageHeight($topPosition -= 10);
}
/**
* Create summary
*
* @return void
*/
public function createSummary()
{
$topPosition = $this -> getPageHeight();
$this -> getPage() -> setLineWidth(0.5);
$this -> getPage() -> setLineColor(new Zend_Pdf_Color_Html('#000000'));
$this -> getPage() -> drawLine(510, $topPosition + 10, self::PAGE_WIDTH - self::PAGE_BOTH_MARGIN, $topPosition + 10);
$this -> setFontAndSize('Helvetica', 12);
$this -> writeText('Subtotaal €', 450, $topPosition, 50, 'right', Zend_Pdf_Font::FONT_HELVETICA, 12);
$this -> writeText($this -> _data['order']['priceExcl'], 565, $topPosition, 0, 'right', Zend_Pdf_Font::FONT_HELVETICA, 12);
$topPosition -= 15;
$this -> writeText('BTW €', 450, $topPosition, 50, 'right', Zend_Pdf_Font::FONT_HELVETICA, 12);
$this -> writeText($this -> _data['order']['priceVat'], 565, $topPosition, 0, 'right', Zend_Pdf_Font::FONT_HELVETICA, 12);
$topPosition -= 15;
if($this -> _data['order']['discount'] != 0)
{
$this -> setFontAndSize('Helvetica', 12);
$this -> writeText('Korting %', 450, $topPosition, 50, 'right', Zend_Pdf_Font::FONT_HELVETICA, 12);
$this -> writeText($this -> _data['order']['discount'], 565, $topPosition, 0, 'right', Zend_Pdf_Font::FONT_HELVETICA, 12);
$topPosition -= 15;
}
$this -> getPage() -> drawLine(510, $topPosition + 10, self::PAGE_WIDTH - self::PAGE_BOTH_MARGIN, $topPosition + 10);
$this -> setFontAndSize('Helvetica', 12);
$this -> writeText('Totaal €', 450, $topPosition, 50, 'right', Zend_Pdf_Font::FONT_HELVETICA_BOLD, 12);
$this -> writeText($this -> _data['order']['priceIncl'], 565, $topPosition, 0, 'right', Zend_Pdf_Font::FONT_HELVETICA_BOLD, 12);
$pageHeight = $this -> getPageHeight();
$this -> setPageHeight($pageHeight -= 100);
}
/**
* Create page footer
*
* @return void
*/
public function createPageFooter()
{
$topPosition = $this -> getPageHeight() - 10;
$this -> setFontAndSize('Helvetica', 12);
$this -> writeText($this -> _data['order']['paymentTerms'], self::PAGE_BOTH_MARGIN * 2, $topPosition, (self::PAGE_WIDTH - (self::PAGE_BOTH_MARGIN * 2)) - 45, 'center', Zend_Pdf_Font::FONT_HELVETICA, 10);
}
/**
* Create page
*
* @return void
*/
public function createNewPage()
{
$template = $this -> getTemplate();
if(!empty($template))
{
$this -> setPage(new Zend_Pdf_Page($template));
}
else
{
$this -> setPage($this -> getPdf() -> newPage(Zend_Pdf_Page::SIZE_A4));
}
$this -> getPdf() -> pages[] = $this -> getPage();
$this -> createPageHeader();
}
/**
* Download PDF
*
* @param int $invoiceID
* @return void | bool
*/
public function downloadPdf($invoiceID)
{
$oInvoices = new Invoices();
$invoiceData = $oInvoices -> find($invoiceID) -> current();
if($invoiceData)
{
$invoiceData -> toArray();
if($invoiceData['invoice_debID'] == VWM_Auth::getIdentity() -> user_debID)
{
if($invoiceData['invoiceStatus'] != 1)
{
header('Content-type:application/x-pdf');
header('Content-Disposition: attachment; filename=factuur_' . $invoiceData['invoiceCode'] . '.pdf');
readfile(APPLICATION_PATH . '/data/invoices/' . $invoiceData['invoiceCode'] . '.pdf');
exit;
}
return false;
}
elseif(VWM_Auth::getIdentity() -> userRole == VWM_Acl::ADMIN)
{
header('Content-type:application/x-pdf');
header('Content-Disposition: attachment; filename=factuur_' . $invoiceData['invoiceCode'] . '.pdf');
readfile(APPLICATION_PATH . '/data/invoices/' . $invoiceData['invoiceCode'] . '.pdf');
exit;
}
return false;
}
return false;
}
}
?>