Please follow the below steps for creating pdf file in php using html2pdf php library

1. Download the html2pdf php library from the following link –
Click here

2. Create a new php file and copy and paste the following code

    include $_SERVER['DOCUMENT_ROOT'].'/html2pdf/vendor/autoload.php';   //set autoload.php file path
    use Spipu\Html2Pdf\Html2Pdf;
    $html2pdf = new Html2Pdf('L','A4');  //create new object
    $htmlcode = "<h1> MY First PDF File" ;
    $html2pdf->writeHTML( $htmlcode );
    $html2pdf->output($_SERVER['DOCUMENT_ROOT'].'/myfirstfile.pdf', 'F');  //set file location


Leave a Comment