Newer Version Available

This content describes an older version of this product. View Latest

Best Practices for Rendering PDFs

Rendering a Visualforce page as a PDF is a great way to easily share information about your Salesforce organization. In addition to the guidelines listed in Rendering a Page as a PDF, you should familiarize yourself with the following concepts.

PDF Rendering Performance

For better performance when rendering Visualforce pages as PDFs, reference static image and stylesheet resources through the $Resource global variable.

Referencing static resources on a remote server increases the time it takes to render a Visualforce page as a PDF. You need to add remote servers to your permitted Remote Sites list under Setup, in Security Controls | Remote Sites Settings. You can’t reference remote resources when using Visualforce to render PDFs in an Apex trigger; doing so results in an exception.

Warning

Component Behavior in PDFs

The following section lists the components that can always be used in a PDF, the components that may not always work, and the components that can never be used. As a general rule, don’t use components that:
  • Rely on JavaScript to perform an action
  • Depend on Salesforce stylesheets
To check if your Visualforce page falls into one of these categories, you can right-click anywhere on the page and view the HTML source. If you see a <script> tag that refers to JavaScript (.js) or a <link> tag that refers to a stylesheet (.css), you should test that the generated PDF displays as expected.

Components That Are Safe to Use in a PDF

  • <apex:composition> (as long as the page contains PDF-safe components)
  • <apex:dataList>
  • <apex:define>
  • <apex:facet>
  • <apex:include> (as long as the page contains PDF-safe components)
  • <apex:insert>
  • <apex:image>
  • <apex:outputLabel>
  • <apex:outputLink>
  • <apex:outputPanel>
  • <apex:outputText>
  • <apex:page>
  • <apex:panelGrid>
  • <apex:panelGroup>
  • <apex:param>
  • <apex:repeat>
  • <apex:stylesheet> (as long as the URL isn’t directly referencing Salesforce stylesheets)
  • <apex:variable>

Components to Use with Caution in a PDF

  • <apex:attribute>
  • <apex:column>
  • <apex:component>
  • <apex:componentBody>
  • <apex:dataTable>

Components That Are Unsafe to Use in a PDF

  • <apex:actionFunction>
  • <apex:actionPoller>
  • <apex:actionRegion>
  • <apex:actionStatus>
  • <apex:actionSupport>
  • <apex:commandButton>
  • <apex:commandLink>
  • <apex:detail>
  • <apex:enhancedList>
  • <apex:flash>
  • <apex:form>
  • <apex:iframe>
  • <apex:includeScript>
  • <apex:inputCheckbox>
  • <apex:inputField>
  • <apex:inputFile>
  • <apex:inputHidden>
  • <apex:inputSecret>
  • <apex:inputText>
  • <apex:inputTextarea>
  • <apex:listViews>
  • <apex:message>
  • <apex:messages>
  • <apex:outputField>
  • <apex:pageBlock>
  • <apex:pageBlockButtons>
  • <apex:pageBlockSection>
  • <apex:pageBlockSectionItem>
  • <apex:pageBlockTable>
  • <apex:pageMessage>
  • <apex:pageMessages>
  • <apex:panelBar>
  • <apex:panelBarItem>
  • <apex:relatedList>
  • <apex:scontrol>
  • <apex:sectionHeader>
  • <apex:selectCheckboxes>
  • <apex:selectList>
  • <apex:selectOption>
  • <apex:selectOptions>
  • <apex:selectRadio>
  • <apex:tab>
  • <apex:tabPanel>
  • <apex:toolbar>
  • <apex:toolbarGroup>