dongxun5349 2016-12-05 18:56
浏览 46
已采纳

在cakephp中查看浏览器dompdf上的pdf

I have create a function php to download pdf in cakephp but I this download works just when I have IDM in my browser, when I disabled IDM I get nothing, this is my code pages: controller function:

public function admin_pdf()
{
 $this->layout="pdf";
 $tpl_dash = array();
 $date = "";
 if(isset($_POST['month']) && isset($_POST['year'])){
  .....
 }
  $this->set('tpl_dash',$tpl_dash);
}

this is my view pdf file:

<div class="container">
<div class="row">
    <div class="gap"></div>
    <div class="product-thumb product-thumb-horizontal">
        <h2 class="pull-left">Statistiques des Etablissements</h2>
        <table  class="table table-hover table-striped table-bordered" id="tpl-dashboard">
            <thead>
                <tr>
                    <th colspan="2" class="first-th"></th>
                    <th colspan="3" class="first-th">Winz</th>
                    <th colspan="3" class="first-th">Réservation</th>
                    <th colspan="3" class="first-th">Avis et Notes</th>
                </tr>
                <tr>
                    <th>Etablissement</th>
                    <th>Ville</th>   
                    <th>Nbre de Winz validés</th>
                    <th>Nbre de Winz consommés</th>
                    <th>Nbre de Winz non consommés</th>
                    <th>Nbre des Réservations validées</th>
                    <th>Nbre des Réservations consommées</th>
                    <th>Nbre des Réservations non consommées</th>
                    <th>Nbre Avis</th>
                    <th>Nbre Notes</th>
                    <th>Nbre Favoris</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($tpl_dash as $key => $value): ?>
                    <tr>
                        <td><?php echo $value['nom'] ?></td>
                        <td><?php echo $value['ville'] ?></td>
                        <td><?php echo $value['avis'] ?></td>
                        <td><?php echo $value['notes'] ?></td>
                        <td><?php echo $value['favoris'] ?></td>
                        <td><?php echo $value['winzsValides'] ?></td>
                        <td><?php echo $value['winzsConsommes'] ?></td>
                        <td><?php echo $value['winzsNonConsommes'] ?></td>
                        <td><?php echo $value['reservationValidees'] ?></td>
                        <td><?php echo $value['reservationConsommees'] ?></td>
                        <td><?php echo $value['reservationNonConsommees'] ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

and this is my pdf lyaout:

require_once (APP . 'Plugin' . DS . 'dompdf' . DS . 'autoload.inc.php');

$dompdf = new Dompdf\Dompdf();
$dompdf->load_html($this->fetch('content'));
//$dompdf->loadHtml($this->fetch('content'););
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();

I was trying to make this $dompdf->stream('my.pdf',array('Attachment'=>0)); and I was trying to make Attachment on ture but both still not work

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-12-07 14:32
    关注

    I solve the problem, in first script I was working with ajax to download pdf but it working just with IDM.

    function printPdf () {
        var m = document.getElementById("month");
        var y = document.getElementById("year");
        var month = m.options[m.selectedIndex].value;
        var year = y.options[y.selectedIndex].value;
        var monthText = m.options[m.selectedIndex].text;
        var  dataString = 'month='+month+'&year='+year+'&monthText='+monthText;
        $.ajax({
            type: "POST",
            url: "/admin/pages/pdf",
            data: dataString,
            cache: false,
            success: function(result){
    
            }
        });  
    }
    

    if I haven't IDM in my browser I can't download it,But now I delete printPdf() function and I put the pdf buttom generator in form, now the PDF was loaded in browser

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型