kartik-v / mpdf

Fork of the mPDF latest DEV library (unofficial) with composer and packagist support.
GNU General Public License v2.0
40 stars 55 forks source link

Unable to render HTML to PDF #28

Open fasi1208 opened 4 years ago

fasi1208 commented 4 years ago

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!](https://www.bountysource.com/issues/92251868-unable-to-render-html-to-pdf?utm_campaign=plugin&utm_content=tracker%2F7827090&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F7827090&utm_medium=issues&utm_source=github).