Reputation:
I have a jpg image for the business card layout with dimensions: 9,8 cm/5,9 cm. I have to put it as background layout and on top of this layout i have to print name/address/telephone number email etc. And print it/save it as pdf for later use.
But problem is i cant make it work with FPDF or TCPDF. Any idea how can i prepare this? with FPDF or TCPDF?
Upvotes: 0
Views: 6290
Reputation: 505
There is a library which implements FPDF called FPDI. To create custom paper sizes, like business cards, which typically use CR80 with dimensions of 54mm x 86mm, you can directly add this size into the class constructor of fpdf.php at stdPageSizes as this: 'cr80'=>array(152.82,243.38). This entry already exists so just add this custom one. Your complete definition will be something like this:
$this->StdPageSizes = array('a3'=>array(841.89,1190.55), 'a4'=>array(595.28,841.89), 'a5'=>array(420.94,595.28), 'letter'=>array(612,792), 'legal'=>array(612,1008), 'cr80'=>array(152.82,243.38));
Your calls, if using FPDI, will now be something like this:
$pdf = new Fpdi();
$pdf->AddPage('L','cr80'); //note our custom name
Note that even though the right size of CR80 is 54x86mm, it seems that the right settings require that these values be multiplied by 2.83 - tested. I hope this helps in code shortenings and quick reuse.
Upvotes: 0
Reputation: 931
To set the background on fpdf you have to call Image() as the first thing when setting up the Header() function in your class.
The way I normally do it is by extending Extend FPDF in my own class, i.e.:
require('path/to/fpdf.php);
class SomeClassName extends FPDF {
// add your instance variables if needed
....
function Header(){
//now call Image()
$this->Image(); //set up your background here
...
}
}
If you look at faqs in the fpdf.org site you will see (vague) instructions on how to do this.
Upvotes: 0
Reputation: 1550
The example n. 51 at http://www.tcpdf.org shows how to create a full page background. Then, for the page format, check the source code documentation of the getPageSizeFromFormat() method (more than 300 page formats are already defined, including business cards).
Upvotes: 0
Reputation: 21
You specifically asked about creating a business card sized document, so you should use:
//Sets document size to a 5.9cm x 9.8cm landscape oriented page
$pdf = new TCPDF('L', 'mm', array(59,98));
The documentation gives a list of pre-defined page sizes here: http://www.tcpdf.org/doc/classTCPDF.html#a087d4df77e60b7054e97804069ed32c5
Upvotes: 2
Reputation: 90
Using TCPDF you can position elements absolutely as it were, so you could do something like
$pdf = new TCPDF('L', 'mm', 'A4'); //Or whatever your required settings are
//Basic setup
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AddPage();
$pdf->Image('src', x, y); //Where x and y are the offset (probably 0, 0)
$pdf->writeHTMLCell(w, h, x, y, 'html') //Again where x and y are offset
$pdf->Output('filename.pdf', 'D'); //To force download
The TCPDF online documentation isn't great, but the examples help a lot http://www.tcpdf.org/examples.php
Upvotes: 3