php-tcpdfHow do I set the margins using PHP TCPDF?
Using the PHP TCPDF library, you can easily set the margins of your document. The following example code block sets the left, top, right, and bottom margins to 20 mm each:
<?php
// Include the library
require_once('tcpdf_include.php');
// Create a new instance of TCPDF
$pdf = new TCPDF();
// Set the margins
$pdf->SetMargins(20, 20, 20, 20);
// Output the document
$pdf->Output('example.pdf', 'I');
?>
This code will create a document with 20 mm margins on all four sides.
Code explanation
require_once('tcpdf_include.php')
- This line includes the TCPDF library.$pdf = new TCPDF()
- This line creates a new instance of TCPDF.$pdf->SetMargins(20, 20, 20, 20)
- This line sets the left, top, right, and bottom margins to 20 mm each.$pdf->Output('example.pdf', 'I')
- This line outputs the document to a file named example.pdf.
For more information about setting margins with TCPDF, see the TCPDF documentation.
More of Php Tcpdf
- How do I install TCPDF using Yum on a PHP server?
- How can I generate a QR code using PHP and TCPDF?
- How can I generate a PDF from XML data using PHP and TCPDF?
- How do I install TCPDF with Composer in a PHP project?
- How do I use the PHP TCPDF WriteHTMLCell function?
- How do I generate a PDF file using TCPDF, PHP and MySQL?
- How do I add a watermark to PDFs using PHP and TCPDF?
- How can I install and use PHP-TCPDF on a Linux system?
- How do I set the page orientation when using PHP TCPDF?
See more codes...