> This code sample serves as a helpful starting point to get an idea. <?php
> /*
> mPDF: Creating PDFs from HTML/CSS (Full Code)
> */
> require_once( 'mpdf/mpdf.php'); // Including mdpf
> $stylesheet = file_get_contents('assets/css/pdf.css'); // Retrieving css content
> $html = '<div id="pdf-content">
> Insert your PDF Content here (Text/HTML)
> </div>';
> // Setting up the PDF
> $mpdf = new mPDF('utf-8', 'A4-L'); // Creating new PDF object with encoding & page size
> $mpdf->setAutoTopMargin = 'stretch'; // Setting pdf top margin to stretch to prevent content overlap
> $mpdf->setAutoBottomMargin = 'stretch'; // Setting pdf bottom margin to stretch to prevent content overlap
> // Adding PDF header content
> $mpdf->SetHTMLHeader('<div class="pdf-header">
> <img class="left" src="assets/img/pdf_header.png"/>
> </div>');
> // Adding PDF footer content
> $mpdf->SetHTMLFooter('<div class="pdf-footer">
> <a href="http://www.lubus.in">www.lubus.in</a>
> </div>');
>
> $mpdf->WriteHTML($stylesheet,1); // Writing style to pdf
> $mpdf->WriteHTML($html); // Writing html to pdf
> // FOR EMAILING
> $content = $mpdf->Output('', 'S'); // Saving pdf for email attachment
> $content = chunk_split(base64_encode($content));
> // Email configuration
> $mailto = $email;
> $from_name = 'LUBUS PDF Test';
> $from_mail = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7d18101c14113d1912101c14...';
> $replyto = '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b3d6ded2dadff3d7dcded2da...';
> $uid = md5(uniqid(time()));
> $subject = 'mdpf email with PDF';
> $message = 'Download the attached pdf';
> $filename = 'lubus_mpdf_demo.pdf';
> $header = "From: ".$from_name." <".$from_mail.">\r\n";
> $header .= "Reply-To: ".$replyto."\r\n";
> $header .= "MIME-Version: 1.0\r\n";
> $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
> $header .= "This is a multi-part message in MIME format.\r\n";
> $header .= "--".$uid."\r\n";
> $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
> $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
> $header .= $message."\r\n\r\n";
> $header .= "--".$uid."\r\n";
> $header .= "Content-Type: application/pdf; name=\"".$filename."\"\r\n";
> $header .= "Content-Transfer-Encoding: base64\r\n";
> $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
> $header .= $content."\r\n\r\n";
> $header .= "--".$uid."--";
> $is_sent = @mail($mailto, $subject, "", $header);
> //$mpdf->Output(); // For sending Output to browser
> $mpdf->Output('lubus_mdpf_demo.pdf','D'); // For Download
> exit;
> ?>