Jump to content

PDF invoice small change


sitesme

Recommended Posts

Hi,

 

Sometimes PDF invoices go over 1 page and a second page is created sometimes with just 1 line of text.

I am trying to maximize the space on my PDF invoices, therefore I was looking to have the invoice like this: http://d.pr/i/5RIo/48JglSxF

 

Basically, the "Invoiced to" box should move to the right side of the "Invoice number" box.

 

Any idea on how to achieve this?

 

I had a look at the invoicepdf.tpl but I have no clue how to do it.

 

Many thanks

Link to comment
Share on other sites

I've had a play with the invoice templates.

 

I believe you'll need to move this code from line 64 onwards

 

$addressypos = $pdf->GetY();

$pdf->SetFont('freesans','B',10);

$pdf->Cell(0,4,$_LANG["invoicesinvoicedto"],0,1);

$pdf->SetFont('freesans','',9);

if ($clientsdetails["companyname"]) {

$pdf->Cell(0,4,$clientsdetails["companyname"],0,1,'L');

$pdf->Cell(0,4,$_LANG["invoicesattn"].": ".$clientsdetails["firstname"]." ".$clientsdetails["lastname"],0,1,'L');

} else {

$pdf->Cell(0,4,$clientsdetails["firstname"]." ".$clientsdetails["lastname"],0,1,'L');

}

$pdf->Cell(0,4,$clientsdetails["address1"],0,1,'L');

if ($clientsdetails["address2"]) {

$pdf->Cell(0,4,$clientsdetails["address2"],0,1,'L');

}

$pdf->Cell(0,4,$clientsdetails["city"].", ".$clientsdetails["state"].", ".$clientsdetails["postcode"],0,1,'L');

$pdf->Cell(0,4,$clientsdetails["country"],0,1,'L');

if ($customfields) {

$pdf->Ln();

foreach ($customfields AS $customfield) {

$pdf->Cell(0,4,$customfield['fieldname'].': '.$customfield['value'],0,1,'L');

}

}

 

to the section commented off as # Header Bar which is on line 45

 

 

You'll probably need to make additional changes to get it aligned to the right hand side, but this should get you set in the right direction!

Link to comment
Share on other sites

Hi,

 

Thank you for the suggestions, but the idea from IgnitionHosting just moved the client details ABOVE the company details. The point was to get the client details aligned to the right inside the grey box where invoice number / dates are (on the left).

 

I was just able to move a few fields such as city, and country to the same line as the address and remove state as we don't use it, and decreasing a few spacing lines between the different sections. It looks better and I can fit the PDF into one page only for almost all invoices now.

 

Thank you for the alternative brian! but I'm not sure if the HTML code will mess up the PDF generator as I don't see much of HTML in the whole page. I guess there are better ways to create the PDF without HTML code.

I just wish I had a little bit of more knowledge on this: http://www.tcpdf.org/doc/code/classTCPDF.html

 

If anyone comes up with an "easy" fix for this, please let me know. I would still prefer to have the customer on the right side of the grey box to maximize the invoice's spacing around the page.

 

Thank you

Joel

Link to comment
Share on other sites

Hi Joel,

Thank you for the alternative brian! but I'm not sure if the HTML code will mess up the PDF generator as I don't see much of HTML in the whole page. I guess there are better ways to create the PDF without HTML code.

I just wish I had a little bit of more knowledge on this: http://www.tcpdf.org/doc/code/classTCPDF.html

take a look at the code that shows the invoice items in the pdf invoice - it's already using a 100% width html table! :)

it's tweaked into a way tcpdf can handle it, but definitely html.

 

# Invoice Items
$tblhtml = '<table width="100%" bgcolor="#ccc" cellspacing="1" cellpadding="2" border="0">
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;text-align:center;">
       <td width="80%">'.$_LANG['invoicesdescription'].'</td>
       <td width="20%">'.$_LANG['quotelinetotal'].'</td>
   </tr>';
foreach ($invoiceitems AS $item) {
   $tblhtml .= '
   <tr bgcolor="#fff">
       <td align="left">'.nl2br($item['description']).'<br /></td>
       <td align="center">'.$item['amount'].'</td>
   </tr>';
}
$tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$_LANG['invoicessubtotal'].'</td>
       <td align="center">'.$subtotal.'</td>
   </tr>';
if ($taxname) $tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$taxrate.'% '.$taxname.'</td>
       <td align="center">'.$tax.'</td>
   </tr>';
if ($taxname2) $tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$taxrate2.'% '.$taxname2.'</td>
       <td align="center">'.$tax2.'</td>
   </tr>';
$tblhtml .= '
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$_LANG['invoicescredit'].'</td>
       <td align="center">'.$credit.'</td>
   </tr>
   <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
       <td align="right">'.$_LANG['invoicestotal'].'</td>
       <td align="center">'.$total.'</td>
   </tr>
</table>';
$pdf->writeHTML($tblhtml, true, false, false, false, '');

it should be pretty straightforward to do what you want by using a table.

Link to comment
Share on other sites

  • 1 month later...
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated