Reputation: 1411
I have just finished work on a PHP script that generates an invoice in PDF format. I've used FPDF for this. Each page of the PDF has an image as a background. This is a single image 793x1113 pixels in size, which after some trial and error I found pixel-perfectly filled the entire page. In the loop that lists the products, I check the value of the Y position. If too high, I add another page, draw the background image again, and set the Y position at the right point to continue the list. Everything works just fine, except for one little issue: On each page except for the very last, about 10 pixels of whitespace is added below the background image, making the layout look off.
This problem does not seem to be related to any of the text content I have added throughout my script, because when I simply add a few blank pages, exactly the same happens. I suppose this is standard whitespace that gets inserted whenever a new page is added. Is there anything I can do to get rid of that, to make everything seamless?
Below the simple code I'm using to generate a three page PDF with backgrounds. When testing, pages 1 and 2 have 10 pixels of whitespace at the bottom, whereas the final 3rd page does not. The 10 pixels subtracted from GetX and GetY when setting the image positions the image directly in the upper left corner. I have var_dumped the Y position after each page add, but this is always the exact same value, so that's not the problem either.
$pdf = new FPDF();
$background = '../data/images/pdf/fullbackground.png';
$pdf->AddPage();
$pdf->Cell( 0, 0, $pdf->Image($background, $pdf->GetX() - 10, $pdf->GetY() - 10, 0), 0, 0, 'L', false );
$pdf->AddPage();
$pdf->Cell( 0, 0, $pdf->Image($background, $pdf->GetX() - 10, $pdf->GetY() - 10, 0), 0, 0, 'L', false );
$pdf->AddPage();
$pdf->Cell( 0, 0, $pdf->Image($background, $pdf->GetX() - 10, $pdf->GetY() - 10, 0), 0, 0, 'L', false );
$pdf->Output();
die();
Any ideas?
Upvotes: 2
Views: 5138
Reputation: 9
You don't have to add page manually. Set auto page break true with 0 margin:
$pdf->SetAutoPageBreak(true,0);
Upvotes: 0
Reputation: 3765
Try setting your margins to 0 and disabling the auto page breaking with a bottom margin of 0.
For example:
$pdf->SetMargins(0,0,0);
$pdf->SetAutoPageBreak(false,0);
SetMargins defaults the left/top/right margins to 1 cm and SetAutoPageBreak defaults to true with a bottom margin of 2 cm.
Upvotes: 1