Jump to content

[Please preview] generate custom PDF in module


Recommended Posts

Hi to all.
I need to add my own html template to the module and generate a PDF.

I made HTMLTemplateCustomPdf.php

<?php

class HTMLTemplateCustomPdf extends HTMLTemplate
{
	public $custom_model;

	public function __construct($custom_object, $smarty)
	{
		$this->custom_model = $custom_object;
		$this->smarty = $smarty;

		$id_lang = Context::getContext()->language->id;
		$this->title = HTMLTemplateCustomPdf::l('Custom Title');
		$this->shop = new Shop(Context::getContext()->shop->id);
	}

	public function getContent()
	{
		$this->smarty->assign(array(
			'custom_model' => $this->custom_model,
		));

		return $this->smarty->fetch(_PS_MODULE_DIR_.'my_module/pdf/template.tpl');
	}

	
	public function getFilename()
	{
		return 'custom_pdf.pdf';
	}


	public function getBulkFilename()
	{
		return 'custom_pdf.pdf';
	}
}

 

In the module I call the function for generating PDF:

$custom_object = array('data' => 'test data');
require_once (_PS_MODULE_DIR_ . 'my_module/pdf/HTMLTemplateCustomPdf.php');
$pdf = new PDF($custom_object, 'CustomPdf', Context::getContext()->smarty);
$pdf->render();

 

I get an error:

obrazek.png.faec92473d27f1463cecdc6d77c5ddf1.png

obrazek.png.6928c7d72f5eb3ee838cea432557a89a.png

Can anyone help me with this?

Thank you

Edited by WebSoft (see edit history)
Link to comment
Share on other sites

  • ps8modules changed the title to [Please preview] generate custom PDF in module
  • 1 month 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...