Skip to content

Unable to render HTML to PDF #28

@fasi1208

Description

@fasi1208

I have created an HTML page using bootstrap and CSS. When I try to render it I am getting error

      `$content = $this->renderPartial('_bill', ['dataProvider' => $dataProvider]);

        $pdf = new Pdf([
            // set to use core fonts only
            'mode' => Pdf::MODE_UTF8,
            // A4 papr format
            'format' => Pdf::FORMAT_A4,
            // portrait orientation
            'orientation' => Pdf::ORIENT_PORTRAIT,
            // stream to browser inline
            'destination' => Pdf::DEST_DOWNLOAD,
            // 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:14px}',
            // set mPDF properties on the fly
            'options' => ['title' => 'Bill'],
            // call mPDF methods on the fly
            'methods' => [
                'SetHeader' => ['Generated On: ' . date("Y-m-d h:i:sa")],
                'SetFooter' => ['{PAGENO}']
            ]
        ]);

        $pdf->filename = "Bill.pdf";

        try {
            return $pdf->render();
        } catch (MpdfException $e) {
            print_r('MPDF Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (CrossReferenceException $e) {
            print_r('Cross Reference Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (PdfTypeException $e) {
            print_r('Pdf Type Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (PdfParserException $e) {
            print_r('Pdf Parser Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        } catch (InvalidConfigException $e) {
            print_r('(Invalid Config Execption ');
            echo '<br/>';
            print_r($e->getMessage());
            exit();
        }
        `

image

Here is the Fiddle


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions