Jump to content

how to create pdf in prestashop


Recommended Posts

Hi,

 

I have to print the cart content in a pdf file and download.

 

I have try some code using pdfinvoicecontroller.php

 

1. I have created new controller - controllers/front/CartprintController.php

 

 

 

class CartprintControllerCore extends FrontController
{
protected $display_header = false;
protected $display_footer = false;

   public $content_only = true;

protected $template;
public $filename; 

public function postProcess()
{ 
if (!$this->context->customer->isLogged() && !Tools::getValue('secure_key'))
Tools::redirect('index.php?controller=authentication&back=cartprint'); 
} 

public function display()
{   
     $displayproducts = $this->context->cart->getProducts();   

$pdf = new PDF($displayproducts, PDF::TEMPLATE_INVOICE_CART, $this->context->smarty, $this->context->language->id);

$pdf->render(); 
} 
public function getTemplate()
{ 
$template = _PS_THEME_PDF_DIR_.'/cartprint.tpl'; 

return $template;
} 
}

 

 

2. Added

const TEMPLATE_INVOICE_CART = 'Cartprint';

line in classes/pdf/PDF.php

 

3.then created a HTML template file in pdf/cartprint.tpl

 

 

<table id="cart_summary" class="std">
<thead>
<tr>
<th class="cart_product first_item">{l s='Product'}</th>
<th class="cart_description item">{l s='Description'}</th>

<th class="cart_unit item">{l s='Unit price'}</th>
<th class="cart_quantity item">{l s='Qty'}</th>
<th class="cart_total item">{l s='Total'}</th>

</tr>
</thead>
{foreach  $displayproducts  item=prodpef name=prodpef }
<tr>
<td class="cart_product first_item">{$prodpef.name}</td>
<td class="cart_description item">{$prodpef.description_short}</td>

<td class="cart_unit item">{$prodpef.price}</td>>
<td class="cart_quantity item">{$prodpef.cart_quantity}</td>>
<td class="cart_total item">{$prodpef.total}</td>> 

</tr>
{/foreach}

</table>

 

4. in shopping cart psge i have created a link

 

 

 <a href="{$link->getPageLink('cartprint', true, NULL)}" title="{l s='Invoice'}" class="_blank"><img src="{$img_dir}icon/pdf.gif" alt="{l s='Invoice'}" class="icon" /></a>

 

but still i am not getting pdf output .

 

Any help ?

Link to comment
Share on other sites

Hi,

 

First of all it was necessary to make it as a module.

Also, in PDF class constructor, there are only 3 parameters:

public function __construct($objects, $template, $smarty)

And you transfer 4. What version do you have?

Besides, are you sure that $displayproducts is transfered and not empty?

And we would use $pdf->render(); instead of $pdf->render(false);

 

Best regards.

Link to comment
Share on other sites

  • 1 month later...
  • 4 weeks later...

If you want to create pdf ,you can follow the demo code:

 

using RasterEdge.Imaging.Basic;

using RasterEdge.Imaging.Basic.Core;

using RasterEdge.Imaging.Basic.Codec;

using RasterEdge.Imaging.PDF;

 

 

namespace RE__Test

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

 

public static string FolderName = "c:/";

 

private void button1_Click(object sender, EventArgs e)

{

string fileName = FolderName + "SampleNew.pdf";

 

PDFDocument pdf = new PDFDocument(5);

 

REFile.SaveDocumentFile(pdf, fileName, new PDFEncoder());//save new pdf

 

}

Link to comment
Share on other sites

  • 1 month later...
hi there,

 

  i want to change invoice (pdf) design, i tried background images, font etc, but no result. it accepts only size, color and alignments 

 

how do i do? is it not possible anyway? help/suggestions would be appreciated 

 

thanks in advance :) 

Link to comment
Share on other sites

×
×
  • Create New...