Smarty, PHP and FPDF trouble in dreamland

so i am trying to output a pdf file created with post data from a form. if I remove smarty from the equation then it works fine but since I need smarty how can I do this? FPDF will not output as long as anything before or after it has been output. but I need to generate the pdf on the fly and put it in the design but not save it anywhere on the server.

any help would be appreciated.

Well, you can either return a template to a user or a PDF file, not both.

What you can do, is create a link to a PHP file that will generate a PDF file on the smarty output. You can then pass the data that was posted to the URL. For example:

<a href="generate-pdf.php?name=Jack&product=Keyboard&....etc" download>Download PDF</a>

and then in generate-pdf.php generate the PHP and send it to the browser.

1 Like

You can’t use smarty to make a template for fpdf. It’s only for use in tpl files. Nor can you assign smarty vars to a file that generates a pdf with fpdf. The template for the pdf file is loaded in the same file as the generation.

This is where I am having difficulties.

Also I can not use Get to generate the pdf. As that could be exploited.

You would use the smarty ->fetch() method to get the ‘html’ result of the template parsing into a php variable. You would then use the ‘html’ method (load_html(), writeHTML()) of one of the pdf generators (dompdf, tcpdf) to convert that into a pdf ‘document’ that you can then either output directly with the appropriate headers or save with a unique filename.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.