Liad Livnat Liad Livnat - 1 month ago 26
AngularJS Question

Is it possible to export html content to PDF from client side?

I'm facing an issue trying to add my website export to PDF function.

When browsing the net, i found some solution, but non of them is just printing the page as is to PDF.

http://parall.ax/products/jspdf can't take pure html and make it into pdf file.

I know there is many questions regarding the issue, but there is no one clear answer to the question: Is it possible to export html content to PDF from client side.

if it's possible i will be glad to know how.

if not please suggest how should i do it from server side (java / php / node.js) .

please note that the page contains highcharts charts and images: you can have a look in here:

http://angularjs.liadlivnat.com:8080/campaign

Answer

I use DOMPDF which takes inline PHP and uses it to convert all of your HTML markup (CSS as well) to PDF. You can implement it client side using a button at the end of your page.

Example:

THE PHP:

<?php

if(isset($_POST['submit'])) 

{   

$content = $_POST['html'];

    if(empty($page))

    {   

        $error = 'Please include at least ONE completed field.';

        }

    else

    {

        include_once('dompdf/dompdf_config.inc.php');

        $dompdf = new DOMPDF();

        $dompdf->load_html($html);

        $dompdf->render();

        $dompdf->stream('Completed_Form.pdf');

        }

}

?>

The HTML:

<input type="submit" name="submit" id="submit" value="Generate PDF" class="submitButton">

Here is an informative video on how to use DOMPDF and where to download the necessary files.

https://www.youtube.com/watch?v=PENbtWrVUjI&index=7&list=FLR4e8kAlnW4FkgpQrGrOfMg

Comments