Reputation:
I've read about 5 posts about this and tried the code fixes with no joy so am posting my own, hopefully this won't offend.
I'm trying to make a page with 2 columns and am using MultiCell() - I am happy with this and have succeeded in removing the margin at the top / on te right & left.
As you can see from the image there is a space at the bottom of the page which pushes the bottom of the text boxes onto the next page.
Can someone please help me, I've been trying for hours now! Here's my code:
// create new PDF document
$pageLayout = array( 139 , 76 );
$pdf = new TCPDF('l', 'mm', $pageLayout, true, 'UTF-8', false, true);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('Online Ticket Seller Ticket');
$pdf->setPrintFooter(false);
$pdf->setPrintHeader(false);
$pdf->SetMargins(PDF_MARGIN_LEFT-15, PDF_MARGIN_TOP-29, PDF_MARGIN_RIGHT-16);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->SetFont('helvetica', '', 10, '', true);
// add a page
$pdf->AddPage();
$pdf->SetFillColor(255, 255, 255);
$pdf->setCellPaddings(1, 1, 1, 1);
$pdf->setCellMargins(0, 0, 0, 0);
// set some text for example
$txt1 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua.';
$txt2 = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
// Multicell test
$pdf->MultiCell(38, 75, '[LEFT] '.$txt1, 1, 'L', 0, 0, '', '', true);
$pdf->MultiCell(101, 75, '[RIGHT] '.$txt2, 1, 'L', 0, 0, '', '', true);
//Close and output PDF document
$pdf->Output('example_005.pdf', 'I');
Many thanks in advance.
Upvotes: 0
Views: 12694
Reputation: 46
If you don't need Margin or Your want to make Margin zero then write the below code
$pdf->SetMargins(0,0,0);
Then write the below code before the line $pdf->AddPage();
$pdf->SetAutoPageBreak(TRUE, 0);
Example :
$pdf->SetMargins(0,0,0);
$pdf->SetAutoPageBreak(TRUE, 0);
$pdf->AddPage();
Note: The space at the bottom of the page you mention is called 'pageBreak margin'. So, use SetAutoPageBreak(TRUE, 0) to remove 'pageBreak margin'.
Upvotes: 0
Reputation: 22760
NOTE:
This below answer is too big to be a comment but not expansive enough to be a true answer, it is more intended for querying some of the information given in the question.
Also note (from my comment):
Can you show us which questions you've already read and tried and which have not solved your issue, otherwise we will simply be linking/suggesting you to questions you've already tried and failed with. Cheers
Your question states Here's my code
:
$pdf->SetMargins(PDF_MARGIN_LEFT-15, PDF_MARGIN_TOP-29, PDF_MARGIN_RIGHT-16);
This is pretty wrong, you want to set the values so:
$pdf->SetMargins(15, 29, 16);
is more syntactically correct.
What you can also try is using the value $keepmargins
from the documentation.
Parameters
$left (float) Left margin.
$top (float) Top margin.
$right (float) Right margin. Default value is the left one.
$keepmargins (boolean) if true overwrites the default page margins
So:
$pdf->SetMargins(15, 29, 16,true);
Upvotes: 1