kartik-v / yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
http://demos.krajee.com/mpdf
Other
163 stars 149 forks source link

QR code in PDF #50

Closed DBX12 closed 6 years ago

DBX12 commented 7 years ago

Prerequisites

Steps to reproduce the issue

See below

Expected behavior and actual behavior

When I follow those steps, I see... a "missing image" icon in the PDF

I was expecting... the QR code

Environment

Browsers

Operating System

Libraries

Isolating the problem

I'm using your PDF extension and the QR-Code extension from 2amigos. The issue I run into is the following: In my view _pdf I "include" the QR code by <img src="<?= Url::to(['route/qrcode','text'=>$model->qr_code_content]) ?>" /> In my Controller I have this function

public function actionQrcode($text){
    Yii::$app->response->format = Response::FORMAT_RAW;
    Yii::$app->response->headers->set('Content-Type','image/png');
    return QrCode::png($text)
}

The Controller renders the view in the actionPdf

public function actionPdf($id) {
        $model = $this->findModel($id);
        #return $this->renderPartial('_pdf', ['model' => $model]);
        $content = $this->renderPartial('_pdf', ['model' => $model]);
        $pdf = new Pdf([
            'content' => $content,
            'filename' => 'Ticket_' . $model->id . '.pdf',
            'options' => [
                'title' => 'Your ticket as '
            ],
            'cssFile' => '@webroot/css/pdf.css'
        ]);
        $pdf->render();
    }

In the PDF the QR code is displayed as "missing image" icon, if I uncomment the third line (return $this->renderPartial(... the page renders as normal HTML and the QR code is displayed correctly. I will also open an issue for the mpdf extension. Please look up the issue together with 2amigos, thx See also my comment on the issue in the 2amigos/yii2-qrcode-helper repo

kartik-v commented 7 years ago

You may need to check and understand how image embedding in PDF output is handled by mPDF library. Note that PDF output and HTML output handling are entirely different. Unlike HTML, you cannot provide a image link to embed images in PDF - it typically must be a base64 encoded image data for embedding images.

Refer mPDF library docs for image processing. You can set $mpdf->showImageErrors to true to debug image processing errors.

dwisuseno commented 7 years ago

I get same problem here. how to solve it? @kartik-v

qomarsuroradi commented 6 years ago

i get same problem..

kartik-v commented 6 years ago

Folks as i mentioned you need to configure the mPDF extension library to achieve your needs. This issue is not related to this extension as it just wraps the mPDF library for use in yii2. If you have suggestions to.improve please open a new issue.