Jump to content
CJF077

Edit PDF - Adjust Logo + Add Bank Details

Recommended Posts

Hi Guys,

I have a requirement to make a few minor changes to the PDF.

I need to reduce the size of the logo or move the box with the invoice number down a few lines. It is currently covering the logo.

Also the transactions box at the bottom, i would like to either remove or add another box which has details of our bank account for transfer of payment.

Any help / guidance is appreciated.

 

 

Share this post


Link to post
Share on other sites
10 hours ago, CJF077 said:

I need to reduce the size of the logo or move the box with the invoice number down a few lines. It is currently covering the logo.

$pdf->Image(ROOTDIR . '/assets/img/' . $logoFilename, 15, 25, 75);

in the default example in invoicepdf.tpl, those three numbers after the filename are for X position (left->right), Y position (top->bottom) and width (unless specified, height will be calculated to maintain proportion to the width)... therefore, altering that 3rd number (75) will change the size of the logo...though it's not always straightforward as it can make the logo fuzzy when printed, so a few test prints may be required.

alternatively, if you want to lower the box, you would increase the number in line ~53...

$pdf->Ln(5);
10 hours ago, CJF077 said:

Also the transactions box at the bottom, i would like to either remove or add another box which has details of our bank account for transfer of payment.

one option to cover both eventualities, would be to wrap the Transactions box with an if statement to check if the invoice is currently unpaid - if it is, there will be no transactions to output and so it outputs payment methods (e.g bank transfer).. otherwise, it outputs the transactions... in summary, there is no point in showing transactions if they haven't paid yet - and if they have paid, there's no point in showing them payment methods!

if ($status!="Unpaid") {
# Transactions
$pdf->SetFont($pdfFont, 'B', 12);
$pdf->Cell(0, 4, Lang::trans('invoicestransactions'), 0, 1);

$pdf->Ln(5);

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

$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="25%">' . Lang::trans('invoicestransdate') . '</td>
        <td width="25%">' . Lang::trans('invoicestransgateway') . '</td>
        <td width="30%">' . Lang::trans('invoicestransid') . '</td>
        <td width="20%">' . Lang::trans('invoicestransamount') . '</td>
    </tr>';

if (!count($transactions)) {
    $tblhtml .= '
    <tr bgcolor="#fff">
        <td colspan="4" align="center">' . Lang::trans('invoicestransnonefound') . '</td>
    </tr>';
} else {
    foreach ($transactions AS $trans) {
        $tblhtml .= '
        <tr bgcolor="#fff">
            <td align="center">' . $trans['date'] . '</td>
            <td align="center">' . $trans['gateway'] . '</td>
            <td align="center">' . $trans['transid'] . '</td>
            <td align="center">' . $trans['amount'] . '</td>
        </tr>';
    }
}
$tblhtml .= '
    <tr height="30" bgcolor="#efefef" style="font-weight:bold;">
        <td colspan="3" align="right">' . Lang::trans('invoicesbalance') . '</td>
        <td align="center">' . $balance . '</td>
    </tr>
</table>';

$pdf->writeHTML($tblhtml, true, false, false, false, '');
} else {

#Payment Method

$pdf->SetFont('freesans','B',12);
$pdf->Cell(0,4,"Payment",0,1);

$pdf->Ln(5);

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

$paymethhtml = '<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="33%" bgcolor="#efefef" style="text-align:center;"><strong>Bank Transfer</strong></td>
        <td width="67%" bgcolor="#ffffff" style="text-align:center;">Reference Number: <strong>INV '.$invoicenum.'</strong>    Sort Code: <strong>12-34-56</strong>    Account Number: <strong>12345678</strong></td>
    </tr>
	</table>';

$pdf->writeHTML($paymethhtml, true, false, false, false, '');
	
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Great work. Fixed my issue straight away.

In regards to the logo, is there anyway to have text on the right hand side, eg website / email address.

Currently the invoice has only the logo and no additional contact information.

Share this post


Link to post
Share on other sites
7 hours ago, CJF077 said:

In regards to the logo, is there anyway to have text on the right hand side, eg website / email address.

Currently the invoice has only the logo and no additional contact information.

the usual way to do it would be to enter those details in the Pay To box in General Settings -> General Tab and enter your postal/contact details there...

http://help.whmcs.com/m/system/l/698239-change-the-pay-to-address-on-invoices

07925c01-0872-426c-aad3-4d39505a795c.png

... and the invoice templates are designed to output those details aligned to the right-hand side of the logo.

the other way would be to edit the template directly and add those details in there in the layout of your choice.

Share this post


Link to post
Share on other sites
15 hours ago, brian! said:

the usual way to do it would be to enter those details in the Pay To box in General Settings -> General Tab and enter your postal/contact details there...

http://help.whmcs.com/m/system/l/698239-change-the-pay-to-address-on-invoices

07925c01-0872-426c-aad3-4d39505a795c.png

... and the invoice templates are designed to output those details aligned to the right-hand side of the logo.

the other way would be to edit the template directly and add those details in there in the layout of your choice.

I tried this but the formatting appeared to be out. The top was in bold, and larger font and then the rest was in different sizes.

Share this post


Link to post
Share on other sites
8 hours ago, CJF077 said:

I tried this but the formatting appeared to be out. The top was in bold, and larger font and then the rest was in different sizes.

that's how it's defined by default in the invoicepdf.tpl - it's in a right-aligned cell and the opening line isn't in bold, just a larger font size.

# Company Details
$pdf->SetXY(15, 42);
$pdf->SetFont($pdfFont, '', 13);
foreach ($companyaddress as $addressLine) {
    $pdf->Cell(180, 4, trim($addressLine), 0, 1, 'R');
    $pdf->SetFont($pdfFont, '', 9);
}

so if you were to change that value of 13 to 9, all lines should be the same font size.

Share this post


Link to post
Share on other sites
13 hours ago, brian! said:

that's how it's defined by default in the invoicepdf.tpl - it's in a right-aligned cell and the opening line isn't in bold, just a larger font size.


# Company Details
$pdf->SetXY(15, 42);
$pdf->SetFont($pdfFont, '', 13);
foreach ($companyaddress as $addressLine) {
    $pdf->Cell(180, 4, trim($addressLine), 0, 1, 'R');
    $pdf->SetFont($pdfFont, '', 9);
}

so if you were to change that value of 13 to 9, all lines should be the same font size.

Thank you for this.

 

Is there anyway within this to make bold text?
A good example would be:

Email: email@email.com
Phone: 123 456 789
Web: www.example.com

Share this post


Link to post
Share on other sites
On 13/10/2018 at 01:58, CJF077 said:

Is there anyway within this to make bold text?

once your into the realms of wanting to do that, then it's often easier to use a 100% width table - especially if you're familiar with basic HTML.

a basic example would be...

# Company Details
$pdf->SetXY(15, 42);
$pdf->SetFont($pdfFont, '', 9);
$companyhtml = '<table width="100%" cellspacing="1" cellpadding="0" border="0">
	<tr><td width="70%"></td><td width="10%" align="right"><strong>Email:</strong></td><td width="20%">support@whmcs.com</td></tr>
	<tr><td width="70%"></td><td width="10%" align="right"><strong>Phone:</strong></td><td width="20%">123 456 789</td></tr>
	</table>';
$pdf->writeHTML($companyhtml, true, false, false, false, '');
$pdf->Ln(5);

EB7WwcT.png

when I create custom invoice pdf templates for clients, i'll usually put the logo in the table too and use css styling - this makes it simpler if they want to make minor changes themselves rather than learn the intricacies of TCPDF!

PHD77yG.png

J72nlgY.png

another option is to remove the 45-degree status banner to increase available space for your company/contact details, but hopefully the above simple table tweak should be sufficient for your needs. thanks.png

Share this post


Link to post
Share on other sites
6 hours ago, CJF077 said:

Thanks this seemed to work but the alignment of the text appears to be out.

it looks correct to me according to what the above html code is supposed to do - e.g align the text headings to the right... you could remove the align="right" from each table row and that would auto align each to the left (that could look weird).

I suppose if you wanted to do it as per your example, you would change it to...

$companyhtml = '<table width="100%" cellspacing="1" cellpadding="0" border="0">
	<tr><td width="70%"></td><td width="30%"><strong>Email: </strong>support@whmcs.com</td></tr>
	<tr><td width="70%"></td><td width="30%"><strong>Phone: </strong>123 456 789</td></tr>
	</table>';

 

  • Thanks 1

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines