Setting paper size in FPDF

Setting paper size in FPDF

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Setting Paper Size in FPDF

When initializing a new PDF document with the standard FPDF library, you immediately face a decision regarding physical dimensions. The constructor signature expects three arguments: orientation, measurement units, and paper format. If you are trying to achieve a specific custom size—such as half of a standard letter sheet, which translates roughly to 8.5 x 5.5 inches—you cannot simply assume that a predefined constant exists for this dimension.

The standard FPDF library provides a fixed set of page sizes in its FPDF class constants. These include P4A, LETTER, LEGAL, A4, and others. However, the list does not cover every possible dimension you might encounter in a print job. When your requirements fall outside these standard presets, you must explicitly define the page size by passing a custom array to the constructor.

To set up a document with dimensions of 8.5 inches by 5.5 inches using millimeters as the unit (which is common for high-precision layouts), you first need to convert those imperial measurements into metric units. Since there are exactly 25.4 millimeters in one inch, the calculation is straightforward but requires precision:

  • Width: $8.5 \times 25.4 = 215.9$ mm
  • Height: $5.5 \times 25.4 = 139.7$ mm

You can then pass this custom array directly into the FPDF constructor. Here is how you would instantiate a new PDF object with these exact dimensions:

$pdf = new FPDF('P', 'mm', array(215.9, 139.7));

It is critical to pass this array as the third argument during instantiation. The library does not offer a method like setPageSize() or SetPageFormat() to alter the dimensions after the object has been created. Once the PDF instance is initialized with a specific page size, that geometry is locked for the life of that document instance. If you attempt to change the size later by creating a new page, FPDF will default back to the standard paper format (usually P4A or Letter) unless you explicitly set the custom array again.

// This does NOT work:
$pdf->AddPage(); 
// The page size remains whatever was set in the constructor.

// This is required if you want a different size on subsequent pages:
$pdf->SetPageSize(array(215.9, 139.7)); 
$pdf->AddPage();

Wait, there is a nuance here. While older versions of FPDF relied strictly on the constructor argument, later versions introduced SetPageSize(). However, if you are working with a version that requires strict adherence to the constructor for custom sizes, or if you want to ensure consistency across different environments, relying on the initial definition is safer. If you need to switch back and forth between standard Letter and this custom half-letter size within the same document, you must call SetPageSize() before adding each new page where that change applies.

Be mindful of how these dimensions interact with your content. A standard letter sheet is 8.5 x 11 inches. Halving it vertically results in the requested 8.5 x 5.5 inches. However, if you are generating documents for commercial printing or specific mailers, verify that the receiving printer supports non-standard page sizes. Many modern laser printers and inkjet devices have a "manual feed" tray specifically designed for half-letter or legal envelopes, but standard duplex printing might fail if the machine does not recognize the custom format as a standard tray size.

If you are building this for a larger application stack, such as Laravel, ensure your PDF generation logic is decoupled from the controller. It is often better to define these constants at the top of your utility file rather than hardcoding them inline:

class PdfUtilities {
    const HALF_LETTER_MM = array(215.9, 139.7);
    
    public static function getHalfLetterPdf() {
        return new FPDF('P', 'mm', self::HALF_LETTER_MM);
    }
}

This approach prevents accidental mixing of page sizes and makes your codebase easier to audit. Always double-check your calculations against the specific printer requirements before deploying a production document that relies on these custom dimensions.

Our network