Jump to content

Customizing PDF temp


sisgroup

Recommended Posts

The problem with that is that Smarty is for the HTML 'language', and PDF's are built around Postscript. You'd need a convert, and, although they do exist, most are not particularly good.

 

It took me about 2-3 hours, but it's quite simple so long as you know a little PHP and you draw out what you want first.

 

The measurements (X, Y or Width/Height) are in millimeters and the fpdf documentation contains all you need to know.

Link to comment
Share on other sites

I can't, as I've never used any of them (although the one that comes with Kayako is particularly bad).

 

However, without re-coding, they won't work with WHMCS as WHMCS relies works with the FPDF class - WHMCS creates the class, sets up the basics and then runs pdfconfig.php, within which you put on the contents on the page before the running returns to WHMCS and it handles the rest (finalizing and retuning the PDF to the client, or adding it to the e-mail).

Link to comment
Share on other sites

It depends on how you want to do it.

 

If you're looked to just add some text to the end, you could use Ln() and Write() to put in some gaps and then 'Write' the text.

 

If you're looking to fix it at the bottom of the page (e.g. Terms of Payment), then you may want to use SetXY() and MultiCell(), where SetXY() will position the top-left of the box, and MultiCell() to set the width and write the text:

 

$pdf->SetXY(80,255); # Set Location
$pdf->SetFont('', '', 6.5); # Use 6.5pt Text
$pdf->MultiCell(110, 3, "Your text can go here\n\nand be split over lines", 0, 'J');
 # Add Text

Link to comment
Share on other sites

This is what i have done but its not displaying the text on the PDF invoice i have added the above code to the very bottom of my pdfconfig.php file labled "# My Addition"

 

<?php

# Logo
$pdf->Image(dirname(__FILE__).'/../images/logo.jpg',15,10,50);

# Company Details
$pdf->SetFont('Arial','',13);
$pdf->Cell(0,6,$companyname,0,1,'R'); 
$pdf->SetFont('Arial','',;
for ( $i = 0; $i <= 4; $i += 1) {
$pdf->Cell(0,4,trim($companyaddress[$i]),0,1,'R');
}
$pdf->Ln(5);

# Header Bar
$invoiceprefix = $_LANG["invoicenumber"];
/*
** This code should be uncommented for EU companies using the sequential invoice numbering so that when unpaid it is shown as a proforma invoice **
if ($status!="Paid") {
$invoiceprefix = $_LANG["proformainvoicenumber"];
}
*/
$pdf->SetFont('Arial','B',15);
$pdf->SetFillColor(239);
$pdf->Cell(0,8,$invoiceprefix.$invoicenum,0,1,'L','1');
$pdf->SetFont('Arial','',10);
$pdf->Cell(0,6,$_LANG["invoicesdatecreated"].': '.$datecreated.'',0,1,'L','1');
$pdf->Cell(0,6,$_LANG["invoicesdatedue"].': '.$duedate.'',0,1,'L','1');
$pdf->Ln(10);

# Clients Details
$pdf->Cell(0,4,$_LANG["invoicesinvoicedto"],0,1);
$pdf->SetFont('Arial','',;
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->SetFont('Arial','',;
$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'); 
$pdf->Ln(10);

$pdf->SetDrawColor(200);

$pdf->SetFont('Arial','B',10);
$pdf->SetFillColor(239);
$pdf->Cell(148,7,$_LANG["invoicesdescription"],1,0,'C','1');
$pdf->Cell(40,7,$_LANG["invoicesamount"],1,0,'C','1');
$pdf->Ln();

$pdf->SetFont('Arial','',10);

foreach ($invoiceitems AS $item) {
if (strlen($item["description"])>85) {
	$pdf->Cell(148,6,substr($item["description"],0,85),1);
	$pdf->Cell(40,6,$currencysymbol.$item["amount"],1,0,'C');
	$pdf->Ln();
	$pdf->Cell(148,6,substr($item["description"],85),1);
	$pdf->Cell(40,6,"",1,0,'C');
} else {
	$pdf->Cell(148,6,$item["description"],1);
	$pdf->Cell(40,6,$currencysymbol.$item["amount"],1,0,'C');
}
$pdf->Ln();
}

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

$pdf->Cell(148,7,$_LANG["invoicessubtotal"].":",1,0,'R','1');
$pdf->Cell(40,7,$currencysymbol.$subtotal,1,0,'C','1');
$pdf->Ln();

if ($CONFIG["TaxEnabled"]) {
$pdf->Cell(148,7,$taxrate."% ".$_LANG["invoicestax"].":",1,0,'R','1');
$pdf->Cell(40,7,$currencysymbol.$tax,1,0,'C','1');
$pdf->Ln();
}

$pdf->Cell(148,7,$_LANG["invoicescredit"].":",1,0,'R','1');
$pdf->Cell(40,7,$currencysymbol.$credit,1,0,'C','1');
$pdf->Ln();

$pdf->Cell(148,7,$_LANG["invoicestotal"].":",1,0,'R','1');
$pdf->Cell(40,7,$currencysymbol.$total,1,0,'C','1');
$pdf->Ln();

$pdf->Ln();

if ($notes) {
$pdf->SetFont('Arial','',;
$pdf->MultiCell(188,5,$_LANG["invoicesnotes"].": $notes");
}

if ($status=="Cancelled") {
$pdf->SetXY(80,80);
$statustext = $_LANG["invoicescancelled"];
} elseif ($status=="Unpaid") {
$pdf->SetXY(120,80);
$statustext = $_LANG["invoicesunpaid"];
} elseif ($status=="Paid") {
$pdf->SetXY(120,80);
$statustext = $_LANG["invoicespaid"];
}
$pdf->SetFont('Arial','B',40);
$pdf->SetTextColor(245);
$pdf->Write(5,strtoupper($statustext));

# Footer
$pdf->SetMargins(15, 27, 15); // left, top, right
$pdf->SetAutoPageBreak(TRUE, 25); // TRUE, margin down
$pdf->SetFooterMargin(10);
$pdf->SetFooterFont(array('arial', '', ); // @array font, type (B, I, BI), size
$pdf->SetFooterData($CONFIG["Domain"] . " - ".$_LANG["page"]." {pg} / {nb}");
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(true);

# My addition
$pdf->SetXY(80,255); # Set Location
$pdf->SetFont('', '', 6.5); # Use 6.5pt Text
$pdf->MultiCell(110, 3, "Your text can go here\n\nand be split over lines", 0, 'J'); 

?>

Link to comment
Share on other sites

I can understand some peoples concerns - having to work with PHP to manipulate the content isn't easy for some people, but I like the raw control available by directly working with FPDF as we've managed to create a PDF invoice that's an exact copy of our paper version, including letterhead.

Link to comment
Share on other sites

I can't, as I've never used any of them (although the one that comes with Kayako is particularly bad).

 

However, without re-coding, they won't work with WHMCS as WHMCS relies works with the FPDF class - WHMCS creates the class, sets up the basics and then runs pdfconfig.php, within which you put on the contents on the page before the running returns to WHMCS and it handles the rest (finalizing and retuning the PDF to the client, or adding it to the e-mail).

Not true; there are fpdf libraries around on the net - I think in the fpdf site itself - that convert from HTML to PDF. I'm not sure how fine grained the control is, and I know it will never be as good a control as writing in FPDF itself.

 

One converter is here: http://html2fpdf.sourceforge.net/

Link to comment
Share on other sites

However, like I said, WHMCS relies of FPDF, and HTML2PDF in an extension of FPDF, and requires custom coding in order to support HTML. You can't just drop it in.

 

However, it may be possible to create your own copy of the FPDF class, apply the HTML2PDF extension, create a new $pdf instance, and then directly create the HTML in the pdfconfig.php class, which you can pass to your new class.

 

In theory, when $pdf is returned to WHMCS it'll work with the functions from the parent class, unbeknown that it's working on a derivate, and may make it easer.

 

I've done something similar by creating my own copy of the FPDF class (with a number of extensions), called it JPDF and then set

 

$pdf = new JPDF();

 

WHMCS hasn't had a problem with it and it works fine.

Link to comment
Share on other sites

  • 2 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