function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Austin JRBAustin JRB 

VisualForce page that renderes as a PDF in A4 format

How do you control the format for a VisualForce page that renderes as a PDF in A4 format
etoeto

use the @page element in CSS:

 

 

@page {
size: 21.0cm 29.7cm;
margin-top: 2.0cm;
margin-left: 0cm;
margin-right: 1.5cm;
margin-bottom: 2cm;
}
Austin JRBAustin JRB
Thanks for the help.  I'll try it out!
bunrothabunrotha

I've been playing with this, and thought I should share a gotcha for anyone else using A4 size PDFs.

 

Some elements, specifically it seems like anything in the Salesforce UI style, like an apex pageblocktable, have a tendency to break the @page directive.

 

I've taken to building an HTML page with direct references to merge fields, rather than use apex components, to preserve the page size.

 

The only time this has caused significant pain is when I had to use an apex:repeat component in an HTML table, and write a list controller just to avoid using the apex table components.

 

So if an A4 PDF keeps coming out in Letter size, there's something to check.

 

Cheers,

Nick