Search code examples
html2pdf

Display:none not working in html2pdf


   $content = "<div id='content'> <div style='display:block;border:1px solid red'>Display </div> 
            <div style='display:none;border:1px solid black'>No-Display </div></div>";
            $html2pdf = new HTML2PDF('P','A4','fr');
            $html2pdf->WriteHTML($content);
            $html2pdf->Output('example.pdf');
            $return = true;

This leads to the following: enter image description here

Obviously, I want the display:none section not to be displayed. What can I do?


Solution

  • According to this document (http://www.studentenwerk-goettingen.de/pdf/help/compatibility.css.2.1.html) css display support is only partial.

    A workaround would probably be to have some kind of conditional check to figure out what is actually needed and then construct your dynamic html accordingly, i guess. This way there would be no need to set anything to "display:none".