Saving pdf in the background using html2pdf

html2pdf, pdf

Solution

You can try calling this script everytime a new product is added, although then you wouldn't really do it in the "background"...

For more information, please note the question "How can I run a PHP script in the background after a form is submitted?"

EDIT:

If you wish to save the file on the server instead of outputting it to the browser, you can use different parameters. See also the html2pdf-wiki. Be aware that you cannot save the file on the user's computer unnoticed!

$html2pdf->Output('directory/file_xxxx.pdf', 'F');

Problem

Am tryng to automatically generate pdfs using html2pdf class. I got the following code which is working fine, only that someone has to save the pdf manually. However, Whenever a new product is added, I would like to automatically save the pdf to some folder without user intervention, and store this value in a database for future reference. How do I go about saving the pdf 'silently' i.e. in the background without showing any popups or requiring the user to intervene? Thanks in advance. ``` include('pdf_content.php'); $content = ob_get_clean(); // convert to PDF require_once('html2pdf/html2pdf.class.php'); try { $html2pdf = new HTML2PDF('P', 'A4', 'en'); $html2pdf->pdf->SetDisplayMode('fullpage'); $html2pdf->setDefaultFont('Arial'); $html2pdf->writeHTML($content, isset($_GET['vuehtml'])); //$html2pdf->Output($file_name.'_'.date("dmY").'.pdf'); $html2pdf->Output($product_id.'_'.$file_name.'_'.date("dmY").'.pdf'); ```

Original source

Related problems