Hi Ravish,
I encountered also this issue. Actually my scenario is this. I have an original file which is a Legal size (8.5mm x 14mmmm). When I an displaying it using the FPDI output as you did, it only display a letter size(8.5mm x 11mm). So the result is: CROPPED PDF file.
I made several googling and found several answers too from different posts. Here is the most relevant solution that I found.
First is this piece of function code below: useTemplate
$this->useTemplate($templateIndex, null, null, 0, 0, true);
Normally, some developers set this as TRUE for the last argument. Yes, it is correct if you dont set the width and lenght. However, I would like to emphasize that the 4th and 5th argument specifies the width and length of an imported PDF. So, if you will adopt or get the actual size of the imported document, set the last argument to FALSE as this will tell that it will take the actual or specific size you set.
Please take this sample codes I did:
$pdf = new FPDI();
$pdf -> setSourceFile('birform2316.pdf');
$tplIdx = $pdf -> importPage(1);
$size = $pdf->getTemplateSize($tplIdx);
$pdf -> AddPage();
$pdf ->useTemplate($tplIdx, null, null, $size['w'], 310, FALSE);
$pdf -> SetFont('Arial');
$pdf -> SetTextColor(0, 0, 0);
$pdf -> SetXY(18, 174);
$pdf -> Write(0, $employer_address);
$pdf -> Output('myOwn.pdf', 'D');
With this code, I have produced a new PDF WITHOUT CROPPING the imported file that I set. Meaning, all details of the template(the original file) has been displayed.
Please take note also that I observed something while setting the size of my PDF:
First, my file has an original width of 215.6mm and its length is 350.9mm. Now when I set the size of my PDF using the functions getTemplateSize and useTemplate such as:
$size = $pdf->getTemplateSize($tplIdx);
$pdf ->useTemplate($tplIdx, null, null, $size['w'], $size['h'],FALSE);
or simply:
$pdf ->useTemplate($tplIdx, null, null, 215.6, 350.9,FALSE);
The result is, my new PDF file is CROPPED at the bottom and I dont know why.
With this observation, I made several tests to find out the reason. And the result that came up is, there is a limit of length in generating a PDF file using FPDI. As you can see in my code above, I did not use the actual length of my file. Instead of using 350.9mm which can be derived from $size[h']
, I did not use it as it will give a cropped file. I just passed a numeric value near to it and the actual width to produce the desired result.
$pdf->useTemplate($tplIdx, null, null, $size['w'], 310, false);
By the way, 310 mm (length) is the largest numeric value I have used to produce a new PDF file which is NOT CROPPED.
I hope I have given some inputs to all developers using FPDI which encounters the problem of CROPPED PDF results.
Thanks to all...
Levi Palmer
$cardDetails
? – Propellantcode
$cardDetails['ORIENTATION'] = 'L'; $cardDetails['SIZE'] = 'STANDARD_CARD';code
size of STANDARD_CARD is Defiled in TCPDF class ascode
case 'STANDARD_CARD' : {$pf = array(360.00,504.00);break;}code
well, I have my problem solved (to some extent, not 100%) I wanted to set the size of pdf to size of PDF imported, say imported pdf is 5.27 X 7.1. then set the size accordingly. but, no luck in that, just some workable solution, not 100%, but, seems to be working for me... – Unfortunate