mpdf only displays on firerox

2

I am using mPDF and it is only generating the reports correctly in FireFox or opening by IE. If I try to open the file with PDF reader it returns the error when loading PDF document.

<?php 
 include("../crud/_views/plugins/mpdf60/mpdf.php");

 $html = "
teste
 ";



$mpdf = new mPDF('','', '', '', 55, 18, 19, 15, 0, 0, '');
$css = file_get_contents('../crud/_views/plugins/mpdf60/estilo.css');
$mpdf->WriteHTML($css,1);
$mpdf->WriteHTML($html,2);
$mpdf->Output('');

By the code I noticed that the error is generated in line $mpdf->WriteHTML($css,1); , if I remove it the PDF is displayed normally, but does not stay with the css style.

Style.css file

    .titulo{
    font-size: 14px;
    font-family: Times, "Times New Roman";
    font-weight: bold;
}
.sub-titulo{
 font-size: 12px;
 font-family: Times, "Times New Roman";
 font-weight: bold;
}
.numero{
    text-decoration: underline;
}

.direita{
 text-align: right;
}

.center{
 text-align: center;
}

.alinhamento{
 margin-right: : 10%;
}

.direita{
 text-align: right;
}
    
asked by anonymous 19.09.2017 / 16:35

2 answers

3

From what I understand, you are trying to generate a PDF by putting a code in .css in it, so the error.

Try to reference the css within your html, and remove the line $mpdf->WriteHTML($css,1); .

To reference the css within your html, just put the following line:

<link rel="stylesheet" type="text/css" href="[CAMINHO_DO_ARQUIVO_CSS]">

    
19.09.2017 / 16:40
0

Probably the version you are using from mpdf is not the last version as you stated, since the most up-to-date version of MPDF has namespace:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();

Or:

use Mpdf\Mpdf;

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new Mpdf();

It does not mean that you can not use versions 5 and 6 of MPDF, I'm just commenting on this because you stated convincingly that you were using the latter, and for your code I do not think it is.

You also claimed to be using the 6.0 version, but the most up-to-date version within "6" is 6.1 and not 6.0 , ie there may be BUGs in the version you downloaded.

The official installation of MPDF 5.7, 6.1 and 7 (the 7 still in beta) are done via composer and link (version 6 or lower), if you did not install via composer or not under the official repository then you probably downloaded a unofficial version of MPDF third party site, so it could be a version with Bugs and soon you are risking.

  

Note: You have downloaded link and the site itself has two notes saying:

     
  • Updated 16/03/2016
  •   
  • This mPDF website is now closed down.
  •   

In other words, these versions that you downloaded do not have update to a year and this site will not receive any updates and is "inactivated", that is probably will not update, only via github now or composer.

If you are using PHP 5.6 or higher you may prefer to install the latest version using composer:

 composer require mpdf/mpdf

To install version 6.1 manually download:

One important detail is that the failure still continues, according to the official manual:

The use of WriteHtml was like this:

<?php

$stylesheet = file_get_contents('style.css');

$mpdf->WriteHTML($stylesheet,1);

$mpdf->WriteHTML($html,2);

That is, if you are going to inject CSS directly then WriteHTML might have to use 2 mode if HTML does not contain the HEAD tag, if it contains what I did not need .

    
19.09.2017 / 16:38