3

Background

I am generating a PDF using this visualforce page:

<apex:page controller="ExampleController" renderAs="pdf" applyBodyTag="false">
    <head>
        <style>
            @page { margin: 0.25in; }
        </style>
    </head>
    <apex:outputText value="{!body}" escape="false" />
</apex:page>

And this apex controller:

public without sharing class ExampleController {

    private final String body;

    public ExampleController() {
        body = '<i>html content goes here</i>';
    }

    public String getBody() {
        return body;
    }
}

The PDF file it generates is the usual A4-ish page size.

I would like the PDF to be a small square, let's say:

  • Height: 400px
  • Width: 400px

Question

  1. Is there any way to control the page size of the PDF generated by Salesforce visualforce pages?

1 Answer 1

5

Specify the page size using the CSS size attribute.

<style>
    @page { margin: 0.25in; size: 4in 4in; }
</style>

You won't find this in the standard Salesforce documentation, but the Flying Saucer guide I linked to should provide a lot of useful information.

2
  • Annoyingly, I had tried size: 4cm 4cm; and it didn't seem to work... but inches did. thanks
    – Robs
    Commented Apr 15, 2019 at 20:46
  • @Robs Odd. Might be because VF uses an older version of Flying Saucer? At the very least, you can convert it pretty easily.
    – sfdcfox
    Commented Apr 15, 2019 at 20:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .