2

こんにちは、私は現在 Cake 2.1 を使用しています。ブラウザーでページを PDF としてレンダリングしようとしていますが、エンジンを正しくロードしていないと思います。に何もロードしていないためだと思いroutes.phpます。

ここに関連するコードがありますroutes.php

   Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
 * ...and connect the rest of 'Pages' controller's urls.
 */
        Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

/**
 * Load all plugin routes.  See the CakePlugin documentation on
 * how to customize the loading of plugin routes.
 */
        CakePlugin::routes();
        Router::mapResources(array('Invoices'));


/**
 * Load the CakePHP default routes. Remove this if you do not want to use
 * the built-in default routes.
 */
        require CAKE . 'Config' . DS . 'routes.php';

ここはboostrap.php

<?php CakePlugin::load('DebugKit');
    CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => true));
     CakePlugin::loadAll();

ここにコントローラーの関数があります

 public function view($id = null) {
    $this->set('title_for_layout', 'Invoices');
    $this->set('stylesheet_used', 'homestyle');
    $this->set('image_used', 'eBOXLogoHome.png');
    $this->layout='adminpdf';

    Configure::write('CakePdf', array(
        'engine' => 'CakePdf.WkHtmlToPdf',
        'download'=>true,
        'binary'=>'C:\Program Files (x86)\wkhtmltopdf\wkhtmltopdf.exe'));
    $this->pdfConfig = array('engine' => 'CakePdf.WkHtmlToPdf');

            $this->Invoice->id = $id;
            if (!$this->Invoice->exists()) {
                throw new NotFoundException(__('Invalid invoice'));
            }
            $this->pdfConfig = array(
                'orientation' => 'potrait',
                'filename' => 'Invoice_' . $id
            );

            $this->set('invoice', $this->Invoice->read(null, $id));
        //Retrieve Account Id of current User       
        $accountid=$this->Auth->user('account_id');




        //Find all Invoices where $conditions are satisfied
        $invoicedetails=$this->Invoice->find('first', array(
        'conditions' => array('Invoice.id'=>$id)));

        //prints fieldsInvoice details, including invoice and field information
        $invoices=$this->FieldsInvoice->find('all',array(
        'conditions'=>array(
        'invoice_id'=>$id)));

        $itemInvoice=$this->InvoicesItem->find('all',array('conditions'=>array('invoice_id'=>$id)));

        //Set variables
        $this->set('invoicedetails', $invoicedetails);  
        $this->set('invoice', $invoices);   
        $this->set('accountid', $accountid);
        $this->set('itemInvoice', $itemInvoice);

    }

私はpdfをロードするこの方法を使用しています - https://github.com/ceeram/CakePdf/

このエンジンwkhtmltopdfを使用しています

私はこれに数日間立ち往生しているので、どんな助けも大歓迎です。

4

1 に答える 1

0

デフォルトではないため、そのエンジンをダウンロードする必要がある WkHtmlToPdf を使用します。ここをチェックしてください:app/plugin/cakepdf/Vendor. default : dompdf 、 mpdf 、および tcpdf が表示されます。

私はDomPdfを使用しています。あなたの bootstrap.php で、次のようにエンジンをロードします。

  Configure::write('CakePdf', array(
        'engine' => 'CakePdf.DomPdf',

       'pageSize'=>'A4',

        'orientation' => 'landscape',

    ));

コントローラー内で使用します:

$this -> pdfConfig = array (
            'orientation' => 'landscape',
            'download' => true,
            'filename' => 'Invoice_' . $id
        );

あなたも見ることができます: http://www.slideshare.net/jellehenkens/building-php-documents-with-cakepdf-cakefest-2012

頑張ってくださいこれが役立つことを願っています。

于 2013-04-11T09:58:10.533 に答える