Skip to content

Instantly share code, notes, and snippets.

@malpaso
Forked from ajitbohra/index.php
Created December 5, 2016 23:17

Revisions

  1. @ajitbohra ajitbohra revised this gist May 25, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion index.php
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,11 @@
    mPDF: Generate PDF from HTML/CSS (Complete Code)
    */

    require_once( 'inc/vendors/mpdf/mpdf.php'); // Include mdpf
    require_once( 'mpdf/mpdf.php'); // Include mdpf
    $stylesheet = file_get_contents('assets/css/pdf.css'); // Get css content
    $html = '<div id="pdf-content">
    Your PDF Content goes here (Text/HTML)
    </div>';

    // Setup PDF
    $mpdf = new mPDF('utf-8', 'A4-L'); // New PDF object with encoding & page size
  2. @ajitbohra ajitbohra created this gist May 24, 2015.
    60 changes: 60 additions & 0 deletions index.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    <?php
    /*
    mPDF: Generate PDF from HTML/CSS (Complete Code)
    */

    require_once( 'inc/vendors/mpdf/mpdf.php'); // Include mdpf
    $stylesheet = file_get_contents('assets/css/pdf.css'); // Get css content

    // Setup PDF
    $mpdf = new mPDF('utf-8', 'A4-L'); // New PDF object with encoding & page size
    $mpdf->setAutoTopMargin = 'stretch'; // Set pdf top margin to stretch to avoid content overlapping
    $mpdf->setAutoBottomMargin = 'stretch'; // Set pdf bottom margin to stretch to avoid content overlapping
    // PDF header content
    $mpdf->SetHTMLHeader('<div class="pdf-header">
    <img class="left" src="assets/img/pdf_header.png"/>
    </div>');
    // 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 EMAIL
    $content = $mpdf->Output('', 'S'); // Saving pdf to attach to email
    $content = chunk_split(base64_encode($content));

    // Email settings
    $mailto = $email;
    $from_name = 'LUBUS PDF Test';
    $from_mail = 'email@domain.com';
    $replyto = 'email@domain.com';
    $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;
    ?>
    1 change: 1 addition & 0 deletions pdf.css
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    // Coming Soon