首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >转换为pdf ( yii2)

转换为pdf ( yii2)
EN

Stack Overflow用户
提问于 2016-11-10 22:32:18
回答 1查看 973关注 0票数 0

如何使当用户点击配置文件按钮,它将显示在pdf文件中。我已经安装了mpdf扩展。下面是我尝试将personalinfo.php页面转换为pdf的代码。

代码语言:javascript
复制
class MpdfController extends Controller
{
    public function actionPersonalinfo() {
        // Your SQL query here
        $content = $this->renderPartial('personalinfo', ['model' => $model]);

        // setup kartik\mpdf\Pdf component
        $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' => 'ProfileStudent'],
            // call mPDF methods on the fly
            'methods' => [
                'SetHeader'=>['Profile'],
                'SetFooter'=>['{PAGENO}'],
            ]
        ]);

        /*------------------------------------*/
        Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
        $headers = Yii::$app->response->headers;
        $headers->add('Content-Type', 'application/pdf');
        /*------------------------------------*/

        // return the pdf output as per the destination setting
        return $pdf->render();
    }
    ...
}

谢谢

EN

回答 1

Stack Overflow用户

发布于 2016-11-10 23:03:15

看起来你没有模型。尝试在调用此操作时传递id,并使用id在$model中检索信息

代码语言:javascript
复制
public function actionPersonalinfo($id) {

  $model = $this->findModel($id);


  $content = $this->renderPartial('personalinfo', ['model' => $model]);

  // setup kartik\mpdf\Pdf component
  $pdf = new Pdf([
  // set to use core fonts only
  'mode' => Pdf::MODE_CORE,
  ....
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40530088

复制
相关文章

相似问题

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