0

Given stylized HTML e.g.

<div class="panel panel-count">
         <div class="panel-heading">{{plug_in_value}}</div>
          <div class="panel-body">
          ...

enter image description here

enter image description here

How can I export this HTML document into a PDF using PHP?

I took a look at a similar question:

Convert HTML + CSS to PDF with PHP?

But many of the replies involved exporting a screenshot of the page or didn't involve CSS. Maybe I am tackling this the wrong way but I could use some guidance on how to accomplish this.

Jebathon
  • 4,310
  • 14
  • 57
  • 108
  • Have you looked [at this one](https://wkhtmltopdf.org) - note, I haven't! It uses WebKit to render, so it should handle just about anything. – Ken Y-N Aug 31 '17 at 01:21
  • maybe this one would be of help [How rto convert web page to PDF](https://stackoverflow.com/questions/18119481/how-to-convert-a-php-web-page-to-pdf) – Pink Ninja Aug 31 '17 at 01:27

1 Answers1

2

There are a couple of ways to do this however they all depend on your requirements. The most common methods make use of wkhtmltopdf, which creates an instance of the webkit rendering engine (Used in both Google Chrome and Apple Safari) to generate the rendering of the page, which is then converted to PDF somehow (I think they use magic here). If you have access to install wkhtmltopdf on your server, and are familiar with Composer, then there are plenty of options.

If however, you do not have access to this, you can use FPDF (I use this myself and like it very much) to convert HTML to PDF, however I am unsure exactly how much support it has for CSS. You can use FPDF with Composer or the good old include style.

Michael Thompson
  • 541
  • 4
  • 21