Jump to content

[SOLVED] Modify the paper size of generated PDF invoice


blueinferno2001

Recommended Posts

Hi,

 

modifying paper size would mean to modify the complete files in case you won't risk wordwraps or line breaks where they shouldn't be.

Or do you just speak of margins? Margins may be modified in function writePage() of /classes/pdf/PDFgenerator.php (lines153-155) :

 

public function writePage()
{
	$this->SetHeaderMargin(5);
	$this->SetFooterMargin(18);
	$this->setMargins(10, 40, 10);
	$this->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
	$this->AddPage();
	$this->writeHTML($this->content, true, false, true, false, '');
}

 

Paper size can be modified in the same file. Look for function __construct. There must be a line like this:

 

parent::__construct('P', 'mm', 'A4', true, 'UTF-8', $use_cache, false);

 

You may modify size here.

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

no, not just the margins but the entire paper size.. i want it to be 21 something left-right and 10 something from top-bottom. i tried changing the 'A4' to 'A5' and set to L (landscape) but it didn't come out as I wanted.

 

as far as i know prestashop only provides templates for A4, A5, A6 (perhaps), letter, legal and a few more. My desired paper size doesn't included in the list. if i need to create my own paper size template, i'd like to know how and where i can put the codes.

Link to comment
Share on other sites

I tried adding my own custom size in tcpdf.php line 2486:

case 'A42': {$pf = array(  595.276,  431.890); break;}

 

and changed line 47 in classes\pdf\PDFGenerator.php into:

parent::__construct('P', 'mm', 'A42', true, 'UTF-8', $use_cache, false);

 

and also line 120 in tool\fpdf\fpdf.php into:

$this->PageFormats=array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a42'=>array(595.28,430.89), 'a5'=>array(420.94,595.28), 'letter'=>array(612,792), 'legal'=>array(612,1008));

 

but the result was again not as I expected. The content still occupied the whole A4 paper while it supposed to fill only the top half.

Link to comment
Share on other sites

  • 3 years later...

Hi,

 

it works. I changed

parent::__construct('L', 'mm', 'A5', true, 'UTF-8', $use_cache, false);
into

parent::__construct('L', 'mm', 'A5', true, 'UTF-8', $use_cache, false);
looks like it was just a printer issue I had earlier.

 

 

I dont see the difference. What was changed specifically?

Link to comment
Share on other sites

It seems he changed line 82 (in PrestaShop v1.6.1.8) of classes/PDFGenerator.php:

        parent::__construct($orientation, 'mm', 'A4', true, 'UTF-8', $use_cache, false);

He must have changed it from 'A4' to 'A5'. Try changing it to 'usletter' to see if that gives you the US letter format you want.

Link to comment
Share on other sites

  • 5 years later...

But... this change will affect all PDFs in Prestashop, isn't it? 

What if I want keep default size (A4) for all documents (invoice, order...) and I only want to change the size of a new pdf document of my custom module (shipment label = A5)? 

Can I override some class (PDF Generator?) in my module? 

 

Thanks 

Link to comment
Share on other sites

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...