Jump to content

How to change Invoice PDF formatting for the U.S.


Recommended Posts

On the new 1.1.0.3—

To change the date formatting:
1. Open: classes >> Tools.php, line 292
2. Change the numbers in the line below within the square brackets with 0=year; 1=month, 2=day

return ($tmpTab[1].'-'.$tmpTab[2].'-'.$tmpTab[0].($full ? $hour : ''));


So, the above will display as: Month, Day, Year. Swap out the numbers to suit your display order if different than above.
-------------------------------------------------------------------------------------------------------------------------------------------
To change the commas to dots in the tax formatting (the other currency amounts show up with periods when language default changed to English--for some reason the tax amount still shows a comma):
1. Open classes>>PDF.php

2. Modify line 608 from this:

$this->Cell($w[1], $lineSize, number_format($tax_rate, 2, ',', ' '), 0, 0, 'R');


to:

$this->Cell($w[1], $lineSize, number_format($tax_rate, 2, '.', ' '), 0, 0, 'R');


(Note: the period in the second line follows the number "2" and replaces the comma in the same spot in line 1.)
-------------------------------------------------------------------------------------------------------------------------------------------

To alter the title, Delivery
1. Open classes>>PDF.php

2. Modify line 310

$pdf->Cell($width, 10, self::l('Delivery'), 0, 'L');

and swap out the word 'Delivery' with either 'Shipping' or 'Ship To' (your preference).

------------------------------------------------------------------------------------------------------------------------------------------
To alter the title, Invoicing to Billing
1. Open classes>>PDF.php

2. Modify line 311

$pdf->Cell($width, 10, self::l('Invoicing'), 0, 'L');

and swap out the word 'Invoicing' with either 'Billing' or 'Bill To' (your preference).

-------------------------------------------------------------------------------------------------------------------------------------------
To alter the shipping address format to reflect the US standard:

Name
Street address
City, State
Zip Country

1. Open classes>>PDF.php

2. Modify line 332, FROM:

 $pdf->Cell($width, 10, $delivery_address->postcode.' '.Tools::iconv('utf-8', self::encoding(), $delivery_address->city), 0, 'L');


TO:

 $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->city).($deliveryState ? ', '.$deliveryState->name : ''), 0, 'L');



3. Modify 335, FROM:

 $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->country.($deliveryState ? ' - '.$deliveryState->name : '')), 0, 'L');


TO:

 $pdf->Cell($width, 10, $delivery_address->postcode.' '.Tools::iconv('utf-8', self::encoding(), $delivery_address->country), 0, 'L');



------------------------------------------------------------------------------------------------------------------------------------------
To alter the billing address format to reflect the US standard,
1. Open classes>>PDF.php

2. Modify line 333 - FROM:

 $pdf->Cell($width, 10, $invoice_address->postcode.' '.Tools::iconv('utf-8', self::encoding(), $invoice_address->city), 0, 'L');



TO:

 $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->city.($invoiceState ? ', '.$invoiceState->name : '')), 0, 'L');



3. Modify line 336, FROM:

 $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->country.($invoiceState ? ' - '.$invoiceState->name : '')), 0, 'L');



TO:

 $pdf->Cell($width, 10, $invoice_address->postcode.' '.Tools::iconv('utf-8', self::encoding(), $invoice_address->country), 0, 'L');

Link to comment
Share on other sites

  • 2 months later...

Hello.
Thank you for post, but i have different problem.
I would like for PDF Invoice to show Slovenian characters: utf-8 or iso-8859-2 . I have tried changing both but can't get correct characters for 'special letters'.

I have changed: iconv('', self::encoding() to
1. iconv('utf-8', self::encoding()
2. iconv('utf-8', self::encoding(utf-8)

and than also utf-8 to iso-8859-2 in both modes 1 and 2.

My site shows up ok, but emails and invoices aren't encoded ok.
If someone is so kind to point me to solution, i'd be really appreciated!

Thank you / Merci !!
WODP

EDIT: i have tried manually to edit MAIL messages and set character instead of iso 8859-1 to iso 8859-2 but when i save such file, iso 8859-1 overrides settings... I've done this throuch Cpanel and edited html code with text editor (not integrated HTML editor).

Link to comment
Share on other sites

  • 1 month later...

THANKS SO MUCH FOR THIS POST.

Can you tell me how to get the postcode onto the same line to display as City, State Zip

Also.... any idea on how to get the store address into the header. I keep trying to move it up from the footer but continue to get errors.

Link to comment
Share on other sites

  • 1 month later...

Here is what I use on my invoice in case anyone wants to port it. It's got the iso code instead of the full state name.

$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->city).($deliveryState ? ', 

'.$deliveryState->iso_code.'. '. ' '.$delivery_address->postcode : ''), 0, 'L'); 

       $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->city).($invoiceState ? ', 

'.$invoiceState->iso_code.'. '. ' '.$invoice_address->postcode : ''), 0, 'L'); 

       $pdf->Ln(5);

       $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->country), 0, 'L'); 

       $pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->country), 0, 'L');

       $pdf->Ln(5);
       $pdf->Cell($width, 10, $delivery_address->phone, 0, 'L');
       if (!empty($delivery_address->phone_mobile))
       {
           $pdf->Ln(5);
           $pdf->Cell($width, 10, $delivery_address->phone_mobile, 0, 'L');

Link to comment
Share on other sites

  • 2 weeks later...

@ishi
For a simpler method, you can change the State names under the Shipping tab. We in the US know all the states, so if you don't mind not having them spelled out, just change them to the two-letter code! Even old orders reflect the two-letter code when you open/save the PDFs. This is especially important when tying your database to a shipping solution, like stamps.com. The USPS will require the two-letter code.

Link to comment
Share on other sites

@ ishi

THANKS SO MUCH FOR THIS POST.

Also.... any idea on how to get the store address into the header. I keep trying to move it up from the footer but continue to get errors.


Regarding putting the store address into the header (instead of footer) download the attached .txt file. See the comments in the code for what was done.
(Ver 1.1.0.5) (This post follows other mods we have done to our site, so the lines quoted are approximate)

PS-pdf-address-header.txt

Link to comment
Share on other sites

@ishi

THANKS SO MUCH FOR THIS POST.

Can you tell me how to get the postcode onto the same line to display as City, State Zip


To do this , use the following code. This is for ver. 1.1.0.5. Lines indicated are for our site, which as previous mods done to it, so the numbers are approximate:

Lines ~ 342-343    
>>> Changed FROM:
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->city.', '.($deliveryState ? $deliveryState->name : '')), 0, 'L');
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->city.', '.($invoiceState ? $invoiceState->name : '')), 0, 'L');

>>> TO:
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $delivery_address->city.', '.($deliveryState ? $deliveryState->name.' '.$delivery_address->postcode.' '.$delivery_address->country : '')), 0, 'L');
$pdf->Cell($width, 10, Tools::iconv('utf-8', self::encoding(), $invoice_address->city.', '.($invoiceState ? $invoiceState->name.' '.$invoice_address->postcode.' '.$invoice_address->country : '')), 0, 'L');



Hope this works for you.

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