首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WKHTMLTOPDF内部错误

问WKHTMLTOPDF内部错误
EN

Stack Overflow用户
提问于 2012-10-25 12:56:15
回答 2查看 3.5K关注 0票数 4

我有一个页面,它应该呈现为pdf在WKHTMLTOPDF引擎的帮助下。当我点击链接加载页面时,我得到了这个错误:

代码语言:javascript
复制
WKHTMLTOPDF didn't return any data
Error: An Internal Error Has Occurred.

堆栈跟踪如下:

输出行234→WkHtmlToPdfEngine-> APP\Plugin\CakePdf\Pdf\CakePdf.php ()

代码语言:javascript
复制
    }
}

$output = $Engine->output();

输出行97→CakePdf-> APP\Plugin\CakePdf\View\PdfView.php (字符串)

打印此内容

$this->response->download($this->getFilename());}

代码语言:javascript
复制
$this->Blocks->set('content', $this->renderer()->output($content));

return $this->Blocks->get('content');

然后打印出我想要的页面

CORE\Cake\Controller\Controller.php行956→PdfView->render(null,null)

代码语言:javascript
复制
null
null

渲染第193行→控制器-> CORE\Cake\Routing\Dispatcher.php ()

代码语言:javascript
复制
 }

        if ($render && $controller->autoRender) {
            $response = $controller->render();

        } elseif ($response->body() === null) {

CORE\Cake\Routing\Dispatcher.php第161行invoke Dispatcher->_→(InvoicesController,CakeRequest,CakeResponse)

代码语言:javascript
复制
object(InvoicesController) {
    helpers => array(
        [maximum depth reached]
    )
    uses => array(
        [maximum depth reached]
    )
    paginate => array(
        [maximum depth reached]
    )
    components => array(
        [maximum depth reached]
    )
    name => 'Invoices'
    request => object(CakeRequest) {}
    response => object(CakeResponse) {}
    viewPath => 'Invoices'
    layoutPath => 'pdf'
    viewVars => array(
        [maximum depth reached]
    )
    view => 'view'
    layout => 'adminpdf'
    autoRender => false
    autoLayout => true
    Components => object(ComponentCollection) {}
    viewClass => 'Pdf'
    View => object(PdfView) {}
    ext => '.ctp'
    plugin => null
    cacheAction => false
    passedArgs => array(
        [maximum depth reached]
    )
    scaffold => false
    methods => array(
        [maximum depth reached]
    )
    modelClass => 'Invoice'
    modelKey => 'invoice'
    validationErrors => null
    Toolbar => object(ToolbarComponent) {}
    Session => object(SessionComponent) {}
    Auth => object(AuthComponent) {}
    RequestHandler => object(RequestHandlerComponent) {}
    pdfConfig => array(
        [maximum depth reached]
    )
    Invoice => object(Invoice) {}
    FieldsInvoice => object(FieldsInvoice) {}
    InvoicesItem => object(InvoicesItem) {}
}
object(CakeRequest) {
    params => array(
        [maximum depth reached]
    )
    data => array([maximum depth reached])
    query => array([maximum depth reached])
    url => 'Invoices/view/1.pdf'
    base => '/pra'
    webroot => '/pra/'
    here => '/pra/Invoices/view/1.pdf'
}
object(CakeResponse) {

}

APP\webroot\index.php线路92调度程序->调度(CakeRequest,CakeResponse)

代码语言:javascript
复制
object(CakeRequest) {
    params => array(
        [maximum depth reached]
    )
    data => array([maximum depth reached])
    query => array([maximum depth reached])
    url => 'Invoices/view/1.pdf'
    base => '/pra'
    webroot => '/pra/'
    here => '/pra/Invoices/view/1.pdf'
}
object(CakeResponse) {

}

这是我的bootstrap.php

代码语言:javascript
复制
<?php
    CakePlugin::loadAll();  
    CakePlugin::load('DebugKit');
     CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => true));
     Configure::write('CakePdf', array(
        'engine' => 'CakePdf.WkHtmlToPdf',
        'download'=>true,
        'binary'=>'C:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe'));

    // Enable the Dispatcher filters for plugin assets, and
    // CacheHelper.
    Configure::write('Dispatcher.filters', array(
    'AssetDispatcher',
    'CacheDispatcher'
    ));

    // Add logging configuration.
    CakeLog::config('debug', array(
    'engine' => 'FileLog',
    'types' => array('notice', 'info', 'debug'),
    'file' => 'debug',
    ));
    CakeLog::config('error', array(
    'engine' => 'FileLog',
    'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
    'file' => 'error',
    ));

我的控制器中的视图

代码语言:javascript
复制
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';


    $this->pdfConfig = array('engine' => 'CakePdf.WkHtmlToPdf');

            $this->Invoice->id = $id;
            if (!$this->Invoice->exists()) {
                throw new NotFoundException(__('Invalid invoice'));
            }
            $this->pdfConfig = array(
                'engine'=>'CakePdf.WkHtmlToPdf',
                '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);

    }



//End of Controller


    }

我的应用控制器

代码语言:javascript
复制
class AppController extends Controller {

    public $components = array(
        'DebugKit.Toolbar',
        'Session', 
        'Auth'=>array(
            'loginRedirect'=>array('controller'=>'users', 'action'=>'login'),
            'logoutRedirect'=>array('controller'=>'users', 'action'=>'login'),
            'invoiceRedirect'=>array('controller'=>'invoices', 'action'=>'viewinvoice'),
            'authError'=>"You can't access this page",
            'authorize'=>array('Controller')
        ),
        'RequestHandler'
    );

routes.php

代码语言:javascript
复制
 */
    CakePlugin::routes();
    Router::mapResources(array('Invoices'));
    Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**

下面是我想要呈现为pdf的视图

代码语言:javascript
复制
<div id = "content">
<h2>View Invoice</h2>
                <table id="data">


    <?php

        if($invoicedetails['Invoice']['scheduled']==1)
        {
            $status = 'Scheduled';  
            $fcol = 'Black';
            $bgcol = '#EBD8E8';
            $pay = NULL;
            $dispute = NULL;
        }
        else if($invoicedetails['Invoice']['paid']==1)
        {
            $status = 'Paid';
            $fcol = 'Black';
            $bgcol = '#B9FAEA';
            $pay = NULL;
            $dispute = NULL;
        }
        else if($invoicedetails['Invoice']['sender_id']==$accountid)
        {
            $status = 'Sent';
            $fcol = 'Black';
            $bgcol = '#F8FAC0';
            $pay = NULL;
            $dispute = NULL;
        }
        else if($invoicedetails['Invoice']['receiver_id']==$accountid)
        {
            $status = 'Received';
            $fcol = 'Black';
            $bgcol = '#FAB9B9';
            $pay = $this->Html->link('Pay', array('controller' => 'Invoices','action'=>'pay_admin',$invoicedetails['Invoice']['id'] )) ;
            $dispute = $this->Html->link('Dispute', array('controller' => 'Disputes','action'=>'add_admin',$invoicedetails['Invoice']['id'] ));
        }



    ?>                      
                <tr>
                <th>Sender: </th>
                <td><?php echo $invoicedetails['SenderAccount']['account_name'];?> </td>
                </tr>

                <tr>
                <th>Receiver: </th>
                <td><?php echo $invoicedetails['ReceiverAccount']['account_name'];?> </td>
                </tr>

                <tr>
                <th>Invoice ID: </th>
                <td><?php echo $invoicedetails['Invoice']['id'];?> </td>
                </tr>

                <tr>
                <th>Invoice Date: </th>
                <td><?php echo date('d.m.Y', strtotime($invoicedetails['Invoice']['created'])); ?></td>
                </tr>

                <tr>
                <th>Due Date: </th>
                <td><?php echo date('d.m.Y', strtotime($invoicedetails['Invoice']['expiry_date'])); ?></td>
                </tr>

                <tr>
                <th>Status: </th>
                <td bgcolor='<?php echo $bgcol ?>'><?php echo $status ;?> </td>
                </tr>

                <tr>
                <th>Actions: </th>
                <td><?php echo $pay ?> <?php echo  $dispute ?></td>
                </tr>               


                </table>
                <br>
                <table id="data">
                <tr>
                    <th>Item Name</th>
                    <th>Description</th>
                    <th>Price Per Unit</th>
                    <th>Quantity</th>
                </tr>
                <?php foreach($itemInvoice as $itemInvoices):?>
                <tr>
                <td><?php echo $itemInvoices['Item']['name']; ?></td>
                <td><?php echo $itemInvoices['Item']['description']; ?></td>
                <td>$<?php echo number_format($itemInvoices['Item']['price'], 2, '.', ','); ?></td>
                <td><?php echo $itemInvoices['InvoicesItem']['quantity']; ?></td>
                </tr>
    <?php endforeach; ?>
                </table>

                <br>

                <table id="data">
                <tr>
                    <th>Field Name</th>
                    <th>Entered Value</th>
                </tr>


        <?php foreach($invoice as $invoices):?>
<tr>
<td><?php echo $invoices['Field']['name']; ?> :</td>
<td><?php echo $invoices['FieldsInvoice']['entered_value']; ?></td>
</tr>
    <?php endforeach; ?>



            </table>
            <br><br>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-10-27 16:32:12

这段代码有两个问题需要解决

  1. 是bootstrap.php原始版本中的二进制文件:

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

新的

代码语言:javascript
复制
 Configure::write('CakePdf', array(
    'engine' => 'CakePdf.WkHtmlToPdf',
    'download'=>false,
    'binary'=>'C:\\wkhtmltopdf\\wkhtmltopdf.exe',
    'orientation'=>'portrait'));

  1. 在我的发票控制器中,我的单词
    1. 有一个拼写错误。
票数 0
EN

Stack Overflow用户

发布于 2013-08-28 06:13:50

在Windows和CakePdf正在使用的php proc_open上,一个巨大的问题是二进制文件中的空格,而https://github.com/ceeram/CakePdf/blob/master/Pdf/Engine/WkHtmlToPdfEngine.php#L35中的异常只是返回了一个通用消息,而不是所发生的错误。

在/WkHtmlToPdfEngine.php#L36上,使用content‘’stderr扩展以查看真正的错误:

代码语言:javascript
复制
throw new CakeException("WKHTMLTOPDF didn't return any data. Returned Error: ".$content['stderr']);

简单的解决方案:

无法使用

代码语言:javascript
复制
'binary'=> 'C:\\Program Files\\wkhtmltopdf\\wkhtmltopdf.exe'

WORKS

代码语言:javascript
复制
'binary'=> 'C:\\Progra~1\\wkhtmltopdf\\wkhtmltopdf.exe'
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13061815

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档