2016-05-03 21 views
0

yiiのマイページからpdfを生成したい。 私は私だけ"test"文字列 がある場合ビューpdf.phpを作成した。そして、私はリンクを介して、このconrollerに行くとき、私はのような文字列を取得yii2 mpdf pdfが正しくレンダリングされない

public function actionGeneratePdf() 
{ 
    $content = $this->renderPartial('pdf'); 
    $pdf = new Pdf([ 
     // set to use core fonts only 
     'mode' => Pdf::MODE_CORE, 
     // A4 paper format 
     'format' => Pdf::FORMAT_A4, 
     // portrait orientation 
     'orientation' => Pdf::ORIENT_PORTRAIT, 
     // stream to browser inline 
     'destination' => Pdf::DEST_BROWSER, 
     // your html content input 
     'content' => $content, 
     // format content from your own css file if needed or use the 
     // enhanced bootstrap css built by Krajee for mPDF formatting 
     'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css', 
     // any css to be embedded if required 
     'cssInline' => '.kv-heading-1{font-size:18px}', 
     // set mPDF properties on the fly 
     'options' => ['title' => 'Krajee Report Title'], 
     // call mPDF methods on the fly 
     'methods' => [ 
      'SetHeader'=>['Krajee Report Header'], 
      'SetFooter'=>['{PAGENO}'], 
     ] 
    ]); 
    return $pdf->render(); 
} 

をPDFコントローラを作成しました、だから、github instructions を使用していますこの:

%PDF-1.4 %���� 3 0 obj <> /Contents 4 0 R>> endobj 4 0 obj <> stream x��R=O�0��+n�ŵ_⏬HPS�H���nQE�����y�W�R�21�I.��绠��J��Z�����dF�W���>��+��)0�#h% o*V�-D���S1��5�;~7�� x_%�_�����:)|MidJ�U;��7uJf�'RN:�(���c�؄�Y������e��QlXy�V��DJ�P�H��[��(�CC��_��cox�X�|O�c�ٔ����ah╏�C���\����I�< S�a��[��6��N���V�ce&�2��m�qmc��z�Hôc;�ag�H�k5z���3��#��۹��p[�:䮉%����������4O��\:�K*��n�R endstream endobj 1 0 obj <> endobj 5 0 obj <> endobj 6 0 obj <> endobj 7 0 obj <> endobj 8 0 obj <> endobj 9 0 obj <> endobj 2 0 obj <> /ExtGState << /GS1 5 0 R >> >> endobj 10 0 obj << /Producer (��mPDF 6.1) /Title (��Krajee Report Title) /CreationDate (20160503174102+03'00') /ModDate (20160503174102+03'00') >> endobj 11 0 obj << /Type /Catalog /Pages 1 0 R /OpenAction [3 0 R /XYZ null null 1] /PageLayout /OneColumn >> endobj xref 0 12 0000000000 65535 f 0000000640 00000 n 0000001193 00000 n 0000000015 00000 n 0000000223 00000 n 0000000729 00000 n 0000000790 00000 n 0000000888 00000 n 0000000984 00000 n 0000001085 00000 n 0000001339 00000 n 0000001513 00000 n trailer << /Size 12 /Root 11 0 R /Info 10 0 R /ID [ ] >> startxref 1623 %% 

誰でもそのライブラリを使用していましたか? 追加し忘れました。私は作曲家経由でインストールしました。

php composer.phar require kartik-v/yii2-mpdf "*" 
php composer.phar update 

何よりも

答えて

2

が変る 'モード' を試してみてください

public function actionGeneratePdf() 
{ 
    $content = $this->renderPartial('pdf'); 
    $pdf = new Pdf([ 
    // set to use core fonts only 
    'mode' => Pdf::MODE_BLANK, 
    // A4 paper format 
+0

OMGどのようにして見つけましたか? – Adobe

+0

@Adobe多くの時間のテストとドキュメントの学習 – scaisEdge

0

問題は、誤ったコンテンツタイプ(text/htmlの代わりのアプリケーション/ PDF)によって引き起こされます。 別の解決策は、応答ヘッダーを自分で設定することです。

public function actionGeneratePdf() 
{ 
    // set response header 
    \yii::$app->response->format = \yii\web\Response::FORMAT_RAW; 
    \yii::$app->response->headers->add('Content-Type', 'application/pdf'); 

    // create pdf as described in demo 
    $content = $this->renderPartial('pdf'); 
    $pdf = new Pdf([ 
    :: 
    ]); 
    return $pdf->render(); 
} 
関連する問題