I have a php script that reads in the contents of an existing html file and saves it to a variable called $home_page.

For a test I displayed this by printing variable out and the output displays as expected.

Then using fpdf I wrote this variable out to create a pdf and email it.

'When I received the pdf the output I get is the contents of the html file raw code instead of the displayed output.

How do I resolve this?

    $the_file       = "/temp/your-app-test.html";
    $myfile         = fopen($the_file, "r") or die("Unable to open file!!!!<br><br><br>");
    $homepage   = file_get_contents($the_file);
    $pdf = new FPDF();
    $pdf->Cell(40,10, $homepage);


    code to email pdf

So, there seems to be some misunderstanding.

When you open a file and read it in this way, what you get is the HTML source. When a browser receives the HTML source, it interprets it and comes up with a graphical rendering of that HTML source.

What you seem to want is the graphical rendering rather than the HTML source, and you’ve done nothing to get that. The program does exactly what you’ve asked it to do.

To get a graphical representation takes a lot more work. Fortunately, some of it has been done for you. See python-webkit2png.