io utilizzo una libreria chiamata dompdf

Dal loro sito:
dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) CSS 2.1 compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements. It also supports most presentational HTML attributes.
in pratica ti permette di passare codice html e trasformarlo direttamente in un pdf, da poter visualizzare subito od esportare, o salvare in una cartella.

dompdf