Non-standard page size’s in TCPDF

By David Pratt / Tags: , / 17 Comments / Published: 23-06-10

If you need to create a PDF using TCPDF that isn’t a standard size (A4, A5, B1, LETTER etc.) then it is possible to specify a custom size even though it isn’t that well documented. To do this you need to pass an array containing the desired width and the height of the PDF instead a formatted parameter such as ‘A4′. For example:

// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
 
// add a page
$resolution= array(100, 100);
$pdf->AddPage('P', $resolution);

Make sure you express the height and width in the unit of measurement (pt, px, mm, cm etc.) that you are using as well.

Category: Tech

Tags: ,

Posted: on June 23rd, 2010 at 8:11 pm.

Feeds: RSS 2.0

17 Responses to “Non-standard page size’s in TCPDF”

Erika June 27th, 2010 at 7:44 pm

Thanks for your info. I also notice that the latest TCPDF release (www.tcpdf.org) contains about 281 standard page formats available through getPageSizeFromFormat() function.

David Pratt June 27th, 2010 at 8:17 pm

Yep, a list of standard page formats can be found here: getPageSizeFromFormat()

Jaizon July 2nd, 2010 at 9:54 am

Hi! Can you please send me a detailed example of this. I’m using the CodeIgniter framework and I’m having a hard time integrating this with it.

Thanks in advance.

Myles February 25th, 2011 at 5:03 pm

“Non-standard page size’s in TCPDF”

no ‘ in sizes. it’s a plural.

Salman May 23rd, 2011 at 8:56 am

Changing the parameter “page format” does’nt change anything

Ramya July 6th, 2011 at 12:56 pm

This was exactly what i was looking for. Worked for me. Thanks!

Lance October 14th, 2011 at 10:15 am

Perfect, I’m printing customized labels for stock – this worked like a charm. Thank you!

Stimart November 28th, 2011 at 12:37 pm

Hi :-) I’ve a little problem.
How can I setup array values with “mm” or “cm” unit of measurement?

toM March 29th, 2012 at 3:08 pm

you saved my day :-))

Anon1 July 11th, 2012 at 4:06 am

I’m having a problem here. When I run this code, it just loads incessantly and eats 90% of my server’s memory upon loading. I wonder what’s the problem.

Fayzan July 25th, 2012 at 10:24 pm

I worked thanks a lot!!

Grammar Crusader November 5th, 2012 at 7:07 pm

@Myles, who is concerned about the formatting of the title of this page: Your dumb.

@David Pratt: thanks for the heads-up!

boyan.sharic January 4th, 2013 at 6:02 pm

I love you :)

bhupender November 28th, 2013 at 5:09 pm

I wanna reduce height of pdf, but not width.
*210 is required width*
When i tried array(150,210);
and array(210, 150);

at both time width got effected, while height was still same, with lots of blank space in bottom :'(

Please help, thanks in advance

shyam February 21st, 2014 at 8:28 pm

You can set the page size and orientation to to any user defined format (units is configurable, mm, cm or pt).. Jus a little tweak needed in the tcpdf source without hampering the existing flow.

Parth Thakkar September 18th, 2014 at 4:53 pm

It Worked!!Thanks

Leave a reply