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
- Is there any way to control the page size of the PDF generated by Salesforce visualforce pages?
Best Answer
Specify the page size using the CSS size attribute.
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.