【问题标题】:How to call loadview() two or more times with DomPDF如何使用 DomPDF 调用 loadview() 两次或更多次
【发布时间】:2019-06-25 10:22:59
【问题描述】:

我想多次使用函数loadview() 加载同一个视图,以调用包含其他数据的数组。我想将第一个 $pdf1 添加到第二个 $pdf2。

$pdf = $pdf1 + $pdf2;

将 $pdf1 和 $pdf2 的所有数据传递给 $pdf 以发送到视图。有没有办法做到这一点?

控制器

public function store(Request $request)
{
    error_log('Some message here.');
    if (!empty ($nbrrowsol)) {
        $pdf1 = PDF::loadview('gestion_commandes.myPDF',
            ['commandesol' => $commandesol, 'nbrrowsol' => $nbrrowsol])->setPaper('a4', 'landscape');
    }

    if (!empty ($nbrroweau)) {
        $pdf2 = PDF::loadview('gestion_commandes.myPDF',
            ['commandeeau' => $commandeeau, 'nbrroweau' => $nbrroweau])->setPaper('a4', 'landscape');
    }

    $pdf = PDF::loadview('gestion_commandes.myPDF', [
        'clients' => $clients, 'commercial' => $commercial, 'datereception' => $datereception,
        'dateprelevement' => $dateprelevement
    ])->setPaper('a4', 'landscape');

    return $pdf->stream('hdtuto.pdf');//redirect('gestion_commandes/create'); 
}

【问题讨论】:

    标签: php laravel dompdf


    【解决方案1】:
    public function store(Request $request)
    {
        error_log('Some message here.');
        if (!empty ($nbrrowsol)) {
            $pdf1 = PDF::loadview('gestion_commandes.myPDF',
                ['commandesol' => $commandesol, 'nbrrowsol' => $nbrrowsol])->setPaper('a4', 'landscape');
     return $pdf1->stream('hdtuto.pdf');//redirect('gestion_commandes/create'); 
    }
        }
    
        if (!empty ($nbrroweau)) {
            $pdf2 = PDF::loadview('gestion_commandes.myPDF',
                ['commandeeau' => $commandeeau, 'nbrroweau' => $nbrroweau])->setPaper('a4', 'landscape');
     return $pdf2->stream('hdtuto.pdf');//redirect('gestion_commandes/create'); 
    }
    else{
        $pdf = PDF::loadview('gestion_commandes.myPDF', [
            'clients' => $clients, 'commercial' => $commercial, 'datereception' => $datereception,
            'dateprelevement' => $dateprelevement
        ])->setPaper('a4', 'landscape');
        return $pdf->stream('hdtuto.pdf');//redirect('gestion_commandes/create'); 
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-02-21
      • 1970-01-01
      • 2015-12-18
      • 1970-01-01
      • 2021-04-10
      • 2013-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多