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');
nixxx
  • 423
  • 1
  • 9
  • 23

1 Answers1

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');
Community
  • 1
  • 1
Marty McVry
  • 2,838
  • 1
  • 17
  • 23
  • 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. – nixxx Apr 05 '13 at 11:21
  • Thanks @Marty McVry. The option 'F' s what i was looking for. Rgds. – nixxx Apr 10 '13 at 11:45
  • 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 (^-^) – RajnishCoder Feb 05 '18 at 12:29