How to include generated php file in mpdf

Asked

Viewed 496 times

3

I’m using the library mpdfto try to display in pdf a file created in php But I’m having a hard time making the same thing work, and I think the way I’m trying to be is not the right way. The archive php contains php and html in its structure and will not have to be different, but if this is a hindrance to the functioning would also like some guidance.

What I got is this:

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

Where is the:

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

I tried to put a include, but it didn’t work, then I tried it with an iframe, but nothing either.

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

inserir a descrição da imagem aqui

  • Already tried using the function file_get_contents specifying the URL to access the desired PHP file? This way the server will parse the file and return only the generated HTML code.

  • Hello @Andersoncarloswoss, yes I did a test, but the page is coming all messed up with php, I will put what returns in the pegunta. Thanks for the tip.

  • You are using a PHP server, such as Apache?

  • Because it seems that you are trying to recover the contents of the file without interpreting it. You can also use the native PHP server itself, via the command php -S and call file_get_contents("http://localhost:8000/arquivo.php").

1 answer

1


I suggest you do the searches outside of include and use str_replace to swap the file variables file_get_contents took. The file 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();
$mpdf->WriteHTML($file);
$mpdf->Output();
exit();

This way, PHP will change the part where %ADDRESS is% to the one it has in $Return->Address, and thus display the address and not the code in PHP.

  • 1

    Perfect, thanks for the great help @Bruno Folle.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.