Saving pdf in the background using html2pdf
Asked Answered
P

1

6

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');
Petal answered 5/4, 2013 at 9:39 Comment(0)
A
18

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');
Aphorism answered 5/4, 2013 at 9:46 Comment(3)
I noted the linked example but is it possible i run the script (not really in the background) without it showing popup to save the pdf? I want it to save the pdf without the user realising it. I dont have access to shell scripts and would prefer another option (preferably via php code) if that option exists. Rgds.Petal
Thanks @Marty McVry. The option 'F' s what i was looking for. Rgds.Petal
you saved me by writing this line "Be aware that you cannot save the file on the user's computer unnoticed!" A big thanks buddy (^-^)Preoccupied

© 2022 - 2024 — McMap. All rights reserved.