While you can display HTML using various tools, you cannot be sure that these tools will display HTML the way your browser does.
If your ultimate goal is to generate an image with text on it , then solve this problem instead of trying to get the proposed solution to work.
Take a look at php imagettftext () . It contains example # 1, which creates a small simple image from text that can be saved in any variable ... including a form variable.
Using this example and adding several other PHP GD functions , you can make a decent replica of the table and make sure that it looks exactly the way you want it, and not like html2ps or some other tool.
<?php // Set the content-type header('Content-Type: image/png'); // Create the image $im = imagecreatetruecolor(400, 30); // Create some colors $white = imagecolorallocate($im, 255, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); // The text to draw $text = isset($_POST['name']) ? $_POST['name'] : "name"; // Replace path by your own font path $font = 'arial.ttf'; // Add some shadow to the text imagettftext($im, 20, 0, 11, 21, $grey, $font, $text); // Add the text imagettftext($im, 20, 0, 10, 20, $black, $font, $text); // Using imagepng() results in clearer text compared with imagejpeg() imagepng($im); imagedestroy($im); ?>
Here's the sample output generated by the above script:
Please note that you need to provide arial.ttf
in accordance with the instructions at the link above.
If everything does not work, look for errors both on the screen and in the error log of the FIRST web server before monitoring it. Perhaps the PHP GD module is not installed on your web server. If so, you should check with your server administrator to make sure what you need.