Hi Rabbi
I also ran into this problem. In fact, my scenario is as follows. I have an original file, Legal size (8.5mm x 14mmmm) . When I show it using the FPDI output, as you did, it only displays the letter size (8.5 mm x 11 mm) . Thus, the result: CROPPED PDF file.
I did some search queries and found several answers from different posts too. Here is the most suitable solution I have found.
First, this is part of the function code below: useTemplate
$this->useTemplate($templateIndex, null, null, 0, 0, true);
Typically, some developers set the value to TRUE for the last argument. Yes, this is correct if you do not specify the width and length. However, I would like to emphasize that the 4th and 5th arguments specify the width and length of the imported PDF file. So, if you accept or get the actual size of the imported document, set the last argument to FALSE , as this will say that it will take the actual or specific size that you set.
Please take this code code that I made:
$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 released a new PDF WIRELESS imported file that I installed. Meaning, all the details of the template (source file) were displayed.
Note also that I noticed something when setting the size of my PDF:
Firstly, my file has an original width of 215.6 mm and its length is 350.9 mm. Now, when I set the size of my PDF using the getTemplateSize and useTemplate functions , for example:
$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);
As a result, my new CROPPED PDF is at the bottom, and I don't know why.
With this observation, I did some tests to find out the reason. And the result that arose is the length limit when creating 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.9 mm, which can be obtained from $size[h'] , I did not use it because it will give a cropped file. I just passed the numerical value next to it and the actual width to get the desired result.
$pdf->useTemplate($tplIdx, null, null, $size['w'], 310, false);
By the way, 310 mm (length) is the largest numerical value that I used to create a new PDF file that DOES NOT .
I hope that I have provided some materials for all developers using FPDI who are facing the issue of CROPPED PDF results.
Thanks everyone ...
Levy Palmer