Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Convert html to PDF with dompdf using PHP.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 167
    Comment on it

    Hello Readers , 

    Below is the explanation of how we can create any HTML into PDF and then further send it to emails as an attachment etc.

    Install the Dompdf library from github https://github.com/dompdf/dompdf/releases and then put it into your project.

    With Dompdf downloaded, let’s write a short example that will generate a simple PDF.

    <?php
    set_include_path(get_include_path() . PATH_SEPARATOR . "/path/to/dompdf");
    
    require_once "dompdf_config.inc.php";
    
    $dompdf = new DOMPDF();
    
    $html = <<<'ENDHTML'
    <html>
     <body>
      <h1>Hello Dompdf</h1>
     </body>
    </html>
    ENDHTML;
    
    $dompdf->load_html($html);
    $dompdf->render();
    $output = $dompdf->output();
    file_put_contents("/path/to/file.pdf", $output);
    ?>

    That's it.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: