I am using TCPDF to generate a PDF file from HTML content. I want to set the page width and height to the custom values 400px and 300px.
I used the following code
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
Where
PDF_PAGE_ORIENTATION
is p
;PDF_UNIT
is mm
;PDF_PAGE_FORMAT
is A6
.On the newer TCPDF version you can define the page size in multiple ways: All standard page formats are already defined (more than 300 types). You can simply define a page size by defining an array with 2 numbers: width, height (regardless the page orientation).
For a responsive full page height, set the body element min-height to 100vh. If you set a page width, choose 100% over 100vw to avoid surprise horizontal scrollbars. I'll leave you with a tutorial from my YouTube channel demonstrating the CSS height and width settings for an HTML page that is full screen size and grows with the content it contains:
Instead of PDF_PAGE_FORMAT (or A6), you could use an array to specifiy width and height. The 3rd argument of the TCPDF constructor accepts either a string like 'A4', 'A6', etc. or a two-element array containing the width and height (in the units defined in PDF_UNIT).
All standard page formats are already defined (more than 300 types). You can simply define a page size by defining an array with 2 numbers: width, height (regardless the page orientation).
you could do:
$custom_layout = array($your_width, $your_height);
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, $custom_layout, true, 'UTF-8', false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With