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
161 stars 150 forks source link

Cannot open PDF in Chrome mobile #34

Closed re1naldo closed 7 years ago

re1naldo commented 8 years ago

Configuration:

'pdf' => [
        'class' => Pdf::classname(),
        'format' => Pdf::FORMAT_LETTER,
        'orientation' => Pdf::ORIENT_LANDSCAPE,
        'destination' => Pdf::DEST_BROWSER,
        'cssFile' => '@webroot/css/document.css',
        'marginTop' => 10,
],

Controller:

$pdf = Yii::$app->pdf;
$pdf->methods = ['SetFooter' => ['{PAGENO}']];
$pdf->content = $this->renderpartial('_tracker', [
       'year' => $year,
       'customer' => $models['customer'],
       'totals' => $models['totals']
]);
$pdf->filename = 'Tracker.pdf';

return Yii::$app->pdf->render();

The script above works well in desktop browsers (Chrome, Opera, Firefox, IE) and mobile browsers (Firefox, Opera). However, it showed an error when I opened the page using Chrome mobile (Android): Cannot display PDF (index.php is of invalid format)

Could this be related to Google Drive PDF Viewer issue (https://productforums.google.com/forum/#!topic/drive/xkkVSoLSIxo;context-place=topicsearchin/drive/category$3Adrive-mobile-app%7Csort:relevance%7Cspell:false)? I opened the mPDF demo page (http://demos.krajee.com/site/mpdf#demo) and it was displayed properly on Chrome mobile. Did I make a mistake in the configuration?

Yii: 2.0.9 Chrome mobile: 52.0.2743.98

mile-janev commented 7 years ago

@re1naldo How you fix this? I have the same issue.

re1naldo commented 7 years ago

@mile-janev Couldn't fix this. I had to install external PDF viewer in order to display PDF correctly.

kartik-v commented 7 years ago

You need to check and control this via your PDF Content, Characters, and Content Formatting that you are rendering, which should be understood by all PDF viewers.

For example, the PDF on the demo page uses simple formatting and normal roman characters and content formatting, that will be understood by most PDF viewers.