How to include generated php file in mpdf

Posted on

Question :

I’m using the mpdf library to try to display in pdf a file created in php but I’m having trouble doing the same thing, I think the way I’m trying is not the correct one.
The file php contains php and html in its structure and it will not be possible to be different, but if this is a hindrance to the operation I would also like some guidance.

What I have is this:

  define('MPDF_PATH', 'class/mpdf/');
  // include(MPDF_PATH.'mpdf.php');
  $mpdf = new mPDF();
  $mpdf->WriteHTML('Hello World');

Where is the:

$mpdf->WriteHTML('Hello World');

I tried to include an include, but it did not work, then I tried an iframe, but nothing too.

I tried to use file_get_contents () as suggested, but the return is that.


Answer :

I suggest you do the searches outside the include and use str_replace to change the file variables that file_get_contents has picked up. In the file it would look like this:

// seu arquivo que o file get contents pega
Endere├žo: %ENDERECO%
// seu php:
$file = file_get_contents('arquivo');
$file = str_replace(%ENDERECO%,$Retorno->Endereco, $file);

$mpdf = new mPDF();

In this way, PHP will change the part where it is% ENDERECO% by what it has in the $ – Return address, and thus display the address and not the PHP code.


Leave a Reply

Your email address will not be published. Required fields are marked *