First of all, you should download the library of here and host it on your server, I recommend you save all the files in a folder Call mpdf .
Once installed, you can test its operation with the following code.
<?php
include_once("mpdf/mpdf.php");
$mpdf = new mPDF('R','A4', 11,'Arial');
$mpdf -> SetTitle('Ejemplo de generación de PDF');
$mpdf -> WriteHTML('<body>');
$mpdf -> WriteHTML('Aquí puedes poner todas las etiquetas HTML que mpdf te permite utilizar.');
$mpdf -> WriteHTML('</body>');
$mpdf -> Output('NombreDeTuArchivo.pdf', 'I');
exit;
?>
I explain roughly, you include the library through its main file with include_once
, you create a new PDF with the function new mPDF
there you can assign the type of paper to use and the source, the function SetTitle();
allows you to change the title of the document that is seen in the browser, everything else is simple HTML, the last function Output();
allows you to assign the default name with which the user can save the file if desired.
As you are new to the library, I recommend using only HTML tags to format your pdf, which you can add in the WriteHTML();
function.
If it is installed correctly, the result will be the following:
To make a more elaborate design you can use tables within the WriteHTML();
functions, you know, with the <table>
tags and all that.
I show you an example of how you can make a clean design through HTML tags and tables.