2017-12-23 20 views
0

Yii2 MPDF 테이블을 렌더링하지.PHP - 나는 PDF (<a href="http://www.yiiframework.com/extension/yii2-mpdf/" rel="nofollow noreferrer">http://www.yiiframework.com/extension/yii2-mpdf/</a>)</p> <p>이 코드는 아래와 같습니다를 생성 Yii2에 mpdf 확장을 사용하고

$fileName = 'tst.pdf'; 
    $invoiceHtml = " 
    <table style = 'height:500px;width:500px' border='1'> 
     <tr> 
     <td>Test 
     </td> 
     <td>Test2 
     </td> 
     </tr> 
     <tr> 
      <td>Test 
      </td> 
      <td>Test2 
      </td> 
     </tr> 
    <table> 
    "; 
    $pdf = new Pdf([ 
     // set to use core fonts only 
     'mode' => Pdf::MODE_CORE, 
     // A4 paper format 
     'orientation' => Pdf::ORIENT_LANDSCAPE, 
     // stream to browser inline 
     'destination' => Pdf::DEST_DOWNLOAD, 
     // your html content input 
     'content' => $invoiceHtml, 
     'filename' =>$fileName, 
     'cssInline' => ' @page{size: 500mm 200mm}', 

      // set mPDF properties on the fly 
     'options' => ['title' => 'Krajee Report Title'], 
      // call mPDF methods on the fly 
     'methods' => [ 
      'SetHeader'=>['New Horizon Travel And Tours LLC'], 
     ] 
    ]); 
    return $pdf->render(); 

코드가 빈 PDF 파일을 생성 중입니다. 다른 HTML 태그 및 기타 태그를 시도하고 일반 텍스트가 예상대로 작동합니다. 표 태그가 사용되면 작동합니다. 이 문제의 해결책을 찾고있다

+0

스타일 속성없이 시도하십시오. –

+0

이미 시도했습니다. 작동하지 않습니다. –

답변

0

이것은 귀하의 질문에 대한 답변이 아닐 수도 있습니다. 그러나 나는 전에 이미 같은 문제에 직면 해있다. 당신은 나의 대안을 사용할 수 있습니다. ...

1 - HTML 파일에 별도의 HTML 코드를 넣으십시오. 2 - 아래 코드를 사용하여 코드를 파기하십시오.

$invoiceHtml = Yii::$app->controller->renderPartial('_yourHtmlFile'); 
$pdf = new Pdf([ 
    // set to use core fonts only 
    'mode' => Pdf::MODE_CORE, 
    // A4 paper format 
    'orientation' => Pdf::ORIENT_LANDSCAPE, 
    // stream to browser inline 
    'destination' => Pdf::DEST_DOWNLOAD, 
    // your html content input 
    'content' => $invoiceHtml, 
    'filename' =>$fileName, 
    'cssInline' => ' @page{size: 500mm 200mm}', 

     // set mPDF properties on the fly 
    'options' => ['title' => 'Krajee Report Title'], 
     // call mPDF methods on the fly 
    'methods' => [ 
     'SetHeader'=>['New Horizon Travel And Tours LLC'], 
    ] 
]); 
return $pdf->render();