robregonm / yii2-pdf

PDF Reports from HTML Views (Html to PDF formatter) for Yii 2.0
BSD 3-Clause "New" or "Revised" License
46 stars 36 forks source link

For new mpdf version does not work #2

Closed githubjeka closed 10 years ago

githubjeka commented 10 years ago

My last version which works

{
            "name": "mpdf/mpdf",
            "version": "dev-master",
            "source": {
                "type": "git",
                "url": "https://github.com/finwe/mpdf.git",
                "reference": "1627f9e7d2ef0f635a886f611079216ed2929717"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/finwe/mpdf/zipball/1627f9e7d2ef0f635a886f611079216ed2929717",
                "reference": "1627f9e7d2ef0f635a886f611079216ed2929717",
                "shasum": ""
            },
            "require": {
                "ext-mbstring": "*",
                "php": ">=4.3.10"
            },
            "type": "library",
            "autoload": {
                "classmap": [
                    "mpdf.php",
                    "classes"
                ]
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "GPL-1.0+"
            ],
            "authors": [
                {
                    "name": "Ian Back"
                }
            ],
            "description": "A PHP class to generate PDF files from HTML with Unicode/UTF-8 and CJK support",
            "homepage": "http://www.mpdf1.com/mpdf/index.php",
            "keywords": [
                "pdf",
                "php",
                "utf-8"
            ],
            "time": "2014-08-24 08:33:20"
        },

Now mpdf version ace190986978df40b9c416cf7ba8761945fc1758 and my code

public function actionReport($id)
    {
        $model = $this->findModel($id);
        Yii::$app->response->format = 'pdf';
        $this->layout = '//print';      
        return $this->render('reportMts');      
    }

outputs

HTML contains invalid UTF-8 character(s)
mPDF error:
//reportMts has
<em>Title</em>

If del tag <em> then it works.

The code works:

protected function formatPdf($response)
    {
        $mpdf = new \mPDF();
        if ($this->rotated) {
            $mpdf->AddPage('L');
        }
        $mpdf->WriteHTML('<em>Title</em>'); 
        return $mpdf->Output('', 'S');
    }

Whats wrong?

robregonm commented 10 years ago

Try removing all mpdf references in your repositories section in composer.json file and just put: "robregonm/yii2-pdf": "dev-master" into require section. This will use the latest version of mpdf by default.

githubjeka commented 10 years ago

my composer.json

 "require": {
        "php": ">=5.4.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-imagine": "*",
        "yiisoft/jquery": "~1.10",
        "yiisoft/yii2-jui": "*",
        "2amigos/yii2-grid-view-library": "*",
        "robregonm/yii2-pdf": "dev-master"
    },

mpdf version is latest 5.7.3. And my code does not work. If setted version 5.7.2 then my code works.

robregonm commented 10 years ago

Do you have repositories block into your composer.json file?

githubjeka commented 10 years ago

No

githubjeka commented 10 years ago

I add in my composer.json. It work fine, but why <em> and other some tags not work with new version 5.7.3 from render view file?

"require": {        
        "robregonm/yii2-pdf": "dev-master"
    },    
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "robregonm/yii2-pdf",
                "version": "dev-master",
                "source": {
                    "url": "https://github.com/robregonm/yii2-pdf",
                    "type": "git",
                    "reference": "ff3a6e7"
                },
                "require": {
                    "mpdf/mpdf": "5.7.2"
                },
                "autoload": {
                    "psr-4": {
                        "robregonm\\pdf\\": ""
                    }
                }
            }

        }
    ]
robregonm commented 10 years ago

Please remove the repositories block, it is not necessary for yii-pdf2 nor mpdf to work

robregonm commented 10 years ago

Also, please check that your files are utf8 encoded.

githubjeka commented 10 years ago

When "mpdf/mpdf": "5.7.2" then my code works . When "mpdf/mpdf": "5.7.3" then the code does not work. Why? My files is same, not changed.

The problem appeared after upgrade "mpdf/mpdf" to latest version 11 days ago.

githubjeka commented 10 years ago

Please try to have a code

//SiteController

public function actionIndex()
    {       
        Yii::$app->response->format = 'pdf';
        $this->layout = '//print';      
        return $this->render('report');      
    }

//print


<?php
/* @var $content */
$this->beginPage() ?>
    <!DOCTYPE html>
    <html>
    <head>
        <title>Title</title>       
    </head>
    <body>
    <?php $this->beginBody() ?>
    <?= $content ?>
    <?php $this->endBody() ?>
    </body>
    </html>
<?php
$this->endPage();

//report


<p class="text-right"><em>Title</em></p>
robregonm commented 10 years ago

I test on a big view file, and I use all kind of HTML tags (even mpdf-only tags). This error is pretty weird because by default yii-pdf uses lates version of mpdf ("mpdf/mpdf": "dev-master"). I'll test using specific version in order to see what happens.

robregonm commented 10 years ago

I executed a quick test and no issues so far. Take a look to composer.json file I use for a personal project where I'm using yii2-pdf package:

    "minimum-stability": "dev",
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "ace-editor",
                "version": "1.1.2",
                "source": {
                    "url": "https://github.com/ajaxorg/ace-builds.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        },
        {
            "type": "package",
            "package": {
                "name": "cropper",
                "version": "0.3.0",
                "source": {
                    "url": "https://github.com/fengyuanchen/cropper.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        },
    ],
    "require": {
        "php": ">=5.5.0",
        "yiisoft/yii2": "*",
        "yiisoft/yii2-bootstrap": "*",
        "yiisoft/yii2-redis": "*",
        "yiisoft/yii2-debug": "*",
        "yiisoft/yii2-gii": "*",
        "yiisoft/yii2-swiftmailer": "*",
        "yiisoft/yii2-jui": "*",
        "robregonm/yii2-auth": "*",
        "cebe/yii2-gravatar": "*",
        "FortAwesome/Font-Awesome": "*",
        "ckeditor/ckeditor": "*",
        "ace-editor": "*",
        "cropper": "*",
        "bootstrap-select/bootstrap-select": "*",
        "twig/twig": "*",
        "twitter/typeahead.js": "dev-master",
        "yiisoft/yii2-imagine": "*",
        "robregonm/yii2-pdf": "dev-master"
    },

Please compare, and tell me if it still fails for you. Also, please ensure you are using UTF8 encoding in your files.

robregonm commented 10 years ago

It seems that this is a mpdf related bug. Please report it in mpdf1.com/forum Thanks.

githubjeka commented 10 years ago

$mpdf->WriteHTML('<em>Title</em>'); it code works. From view the code oes not work, i wrote above. Okay, i will look to find problem.

githubjeka commented 10 years ago

I caught a bug https://github.com/finwe/mpdf/issues/28