Zend PDF:打印时抛出异常

时间:2014-07-24 09:54:19

标签: php apache codeigniter zend-framework pdf

我正在使用带有zend框架的codeigniter。我遇到了稳定性问题的麻烦,因为它有时会抛出这些异常。可能是什么问题?

Fatal error: Uncaught exception 'Zend_Pdf_Exception' 
with message 'Invalid file path: ' 
in C:\xampp\htdocs\copyncc2\application\libraries\Zend\Pdf\FileParserDataSource\File.php:79 

Stack trace: 
#0 C:\xampp\htdocs\copyncc2\application\libraries\Zend\Pdf\Font.php(603): Zend_Pdf_FileParserDataSource_File->__construct(NULL) 
#1 C:\xampp\htdocs\copyncc2\application\libraries\Zend\Barcode\Renderer\Pdf.php(196): Zend_Pdf_Font::fontWithPath(NULL) 
#2 C:\xampp\htdocs\copyncc2\application\libraries\Zend\Barcode\Renderer\RendererAbstract.php(481): Zend_Barcode_Renderer_Pdf->_drawText('ERROR:', 10, Array, NULL, 0, 'left', 0) 
#3 C:\xampp\htdocs\copyncc2\application\libraries\Zend\Barcode\Renderer\RendererAbstract.php(445): Zend_Barcode_Renderer_RendererAbstract->_drawInstructionList() 
#4 C:\xampp\htdocs\copyncc2\application\models\sbp_model.php(261): Zend_Barcode_Renderer_RendererAbstract->draw() 
#5 C:\xampp\htdocs\copyncc2\application\controllers\sbp.php(72): Sbp_model->printpermit('1187244') 
#6 [internal function]: Sbp->printpermit('11 in C:\xampp\htdocs\copyncc2\application\libraries\Zend\Pdf\FileParserDataSource\File.php on line 79

这是我生成PDF的功能:

    function printpermit($businessId){
        $this->load->library('zend');
        $a=$this->load->library('amount_to_words');
        $this->zend->load('Zend/Pdf');
        $this->zend->load('Zend/Barcode');
        $sbp_type=$this->uri->segment(4);

        if(isset($sbp_type)&&!empty($sbp_type)){
            $fileName =APPPATH.'assets/reports/sbp/NCCProvisionalPermit.pdf'; 
        }else {
            $fileName =APPPATH.'assets/reports/sbp/NCCPermit.pdf';
        };


        $vals=$this->sbp_model->print_sbp_preview($businessId);
        $permit_no=$vals['sbpnumber'];
        $permit_year=$vals['year'];
        $biz_name=$vals['bizname'];
        $pin_no=$vals['pinno']; 
        $biz_id=$vals['bizzid']; 
        $activity=$vals['biztype']; 
        $description=$vals['bizactivityname']; 
        $activity_code=$vals['activitycode'];;
        $amount=$vals['paidfee'];

        $amount = str_replace( ',', '', $amount);
        if( is_numeric( $amount) ) {
            $amount_in_words="** ".strtoupper($this->amount_to_words->convert_number($amount))." SHILLINGS ONLY **";
        }else $amount_in_words="NOT AVAILABLE";

        $box=$vals['pobox'];
        $plot_no=$vals['plotnumber'];
        $road_street=$vals['street'];
        $issue_date=$vals['issuedate'];
        $barcode_text=$vals['receiptno'];


        $pdf = Zend_Pdf::load($fileName);
        $page=$pdf->pages[0];

        // Draw something on a page 
        // Set font 
        $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); 
        $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); 
        $page->drawText($permit_no, 473, 647); 
        $page->drawText($permit_year, 473, 624);
        $page->drawText($biz_name, 35, 530);
        $page->drawText($pin_no, 110, 502);
        $page->drawText($biz_id, 460, 530);
        $page->drawText($activity, 35, 430);
        $page->drawText($description, 35, 406);
        $page->drawText($activity_code, 500, 423);
        $page->drawText(number_format($amount,2), 255, 359);
        $page->drawText($amount_in_words, 135, 338);
        $page->drawText($box, 115, 267);  
        $page->drawText($plot_no, 340, 267);
        $page->drawText($road_street, 120, 245);
        $page->drawText($issue_date, 120, 198);
        $barcodeOptions = array('text' => $barcode_text,'barHeight' => 40,'factor'=>2.5,'font' =>APPPATH.'assets/fonts/SWANSEBI.TTF');
        $rendererOptions = array(
            'topOffset' => 590,
            'leftOffset' =>285
            );
        $pdf = Zend_Barcode::factory('code128', 'pdf', $barcodeOptions, $rendererOptions)->setResource($pdf)->draw();

        $pdfData = $pdf->render(); 

        header("Content-Disposition: inline; filename=sbp.pdf"); 
        header("Content-type: application/x-pdf"); 
        echo $pdfData;

    }

0 个答案:

没有答案