Jump to content

Display the template of a page before starting to generate a PDF document [PS 1.6]


Joseph Joestar

Recommended Posts

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 by Joseph Joestar (see edit history)
Link to comment
Share on other sites

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

  • 2 weeks later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...