Implemented PDF page counter using FPDI. Wont work on all types of PDF attachments. Error message will need to be manually removed, and such PDFs will need to be re-encoded by acrobat

This commit is contained in:
Karl Cordes 2013-03-29 17:58:00 +11:00
parent 296336e431
commit da23179673
3 changed files with 38 additions and 2 deletions

View file

@ -621,6 +621,7 @@ class DocumentsController extends AppController {
$document = $this->Document->read(null, $id);
$this->set('document',$document);
$this->set('attachments', $this->Document->DocumentAttachment->find('all', array('conditions'=>array('document_id'=> $id))));
$enquiry = $this->Document->Quote->Enquiry->read(null, $document['Quote']['enquiry_id']);
$this->set('enquiry', $enquiry);
}
@ -643,6 +644,8 @@ class DocumentsController extends AppController {
$document = $this->Document->read(null,$id);
if(empty($document['Document']['pdf_filename'])) {
$this->Session->setFlash(__('Error. Please generate the PDF before attempting to email it', true));
return;
}

24
app/vendors/pagecounter.php vendored Executable file
View file

@ -0,0 +1,24 @@
<?php
App::import('Vendor','tcpdf/tcpdf');
App::import('Vendor', 'fpdi/fpdi');
/* Count pages of the PDF attachments using FPDI */
class PageCounter extends FPDI {
function count($file) {
$pdf = new FPDI();
$count = $pdf->setSourceFile($file);
if(is_numeric($count)) {
return $count;
}
else {
return;
}
}
}
?>

View file

@ -1,3 +1,9 @@
<?
App::import('Vendor','pagecounter');
$pagecounter = new PageCounter();
?>
<p>Dear <?=$enquiry['Contact']['first_name']?>,</p>
<p>Thank you for your enquiry. The following quotation is for:</p>
@ -27,4 +33,7 @@
<?=$enquiry['User']['job_title'];?><br />
<br />
<u><b>Attachments:</b></u><br />
CMC Technologies Terms & Conditions of Sale 1/7/06 (attached)<br />
CMC Technologies Terms & Conditions of Sale 1/7/06 (attached)<br>
<?php foreach($attachments as $attachment) {; ?>
<?php echo $attachment['Attachment']['name']; ?> (<?=$pagecounter->count($attachment['Attachment']['file']); ?> pages)<br>
<?php } ?>