You can use DOMPDF for this and DOMPDF also supports PHP Code.You can enable php on dompdf_config.inc.php file DOMPDF_ENABLE_PHP = true by default it false.
Question
I have a PHP page, as you see on this page everybody can create schema for heating and cooling systems. I am at the end of my project, now I have a problem. I am trying to save as PDF my schema ( inside div). Firstly I tried to use TCPDF, unfortunately TCPDF does not support all CSS commands. Then I found DOMPDF, but it did not display PHP commands. Heere is a screenshot from my projects.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow