Joseph Joestar Posted April 23, 2018 Share Posted April 23, 2018 (edited) Hi everyone, Here's my question : In fact, I allow customers to generate a custom PDF document (with TCPDF) (PS 1.6.16) in a new tab by clicking a link on our website. This new tab remains blank during generation until the document is ready and start to be downloaded. But some documents are very slow to generate and this blank page is very annoying (possibly lots of my customers will think that it doesn't work). I have been looking for a solution for quite some time now, but nothing very intersting. If you have any idea, any clue, I will be very happy to read it. M. PS : <?php class ukoo_compatcatalogPDFModuleFrontController extends ModuleFrontController{ public $auth = true; public $ssl = true; public function initContent(){ parent::initContent(); $this->setTemplate('catalogPDF.tpl'); $this->renderPDF(); } public function renderPDF(){ require_once _PS_MODULE_DIR_ . 'ukoo_compat/pdf/HTMLTemplateCatalogPdf.php'; $pdf = new PDF("test", 'CatalogPdf', Context::getContext()->smarty); $pdf->render(); } } Edited April 23, 2018 by Joseph Joestar (see edit history) Link to comment Share on other sites More sharing options...
jgamio Posted April 23, 2018 Share Posted April 23, 2018 (edited) I havent try but what about show a tpl with info like wait we are processing the info with some gif and use ajax to fire the pdf when the document is load Edited April 23, 2018 by jgamio fix (see edit history) Link to comment Share on other sites More sharing options...
Joseph Joestar Posted April 24, 2018 Author Share Posted April 24, 2018 Yes, I've tried a similar solution like this : <?php class ukoo_compatcatalogPDFModuleFrontController extends ModuleFrontController{ public $auth = true; public $ssl = true; public function initContent(){ parent::initContent(); $this->setTemplate('catalogPDF.tpl'); //$this->renderPDF(); } public function renderPDF(){ require_once _PS_MODULE_DIR_ . 'ukoo_compat/pdf/HTMLTemplateCatalogPdf.php'; $pdf = new PDF("test", 'CatalogPdf', Context::getContext()->smarty); $pdf->render(); } } Disable the generation of the PDF in the controller $(document).ready(function(){ $.ajax({ type: "POST", url: "{/literal}{$modules_dir}{literal}ukoo_compat/models/ajax.php", data: {ukooCompatAjax: true, ukooCompatTask: 'pdfGenerator'}, success: function(pdf){ alert(pdf); } }); Call the generation in my script <?php if(isset($_POST['ukooCompatAjax']) && $_POST['ukooCompatAjax'] == true){ include(dirname(__FILE__).'/../../../config/config.inc.php'); if(isset($_POST['ukooCompatTask'])){ if( $_POST['ukooCompatTask']=='pdfGenerator') echo pdfGenerator(); } function pdfGenerator(){ require_once _PS_MODULE_DIR_ . 'ukoo_compat/pdf/HTMLTemplateCatalogPdf.php'; $pdf = new PDF("test", 'CatalogPdf', Context::getContext()->smarty); $content = $pdf->render(); return $content; } } And generate my PDF in it. But for some reasons, I've this message of error : "TCPDF ERROR: [Image] Unable to get the size of the image: my-logo-1504862186.jpg". The exact same PDF document generation works when called in my controller. Am I missing something ? Link to comment Share on other sites More sharing options...
jgamio Posted May 2, 2018 Share Posted May 2, 2018 Why dont try make the ajax on the same controller and use your same function Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now