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 can I use PHP and TCPDF to read a PDF?
- How do I install TCPDF using Yum on a PHP server?
- How can I generate a PDF from data stored in a MySQL database using TCPDF and PHP?
- How do I use the PHP TCPDF WriteHTMLCell function?
- How can I use PHP and TCPDF to merge multiple PDFs into one?
- How can I use the TCPDF Multicell function in PHP?
- How do I use the PHP TCPDF namespace?
- How can I install and use PHP-TCPDF on a Linux system?
- How do I use the setfont function in PHP TCPDF?
- How do I generate a PDF file using TCPDF, PHP and MySQL?
See more codes...