Generating printable content
Salesforce has a built-in PDF generation engine that can take your HTML markup and turn it into a PDF. This is a very useful feature to generate more formal documents such as invoices or purchase orders.
You can access it using the renderAs
attribute of the apex:page
element on a Visualforce page, setting it to pdf
. Note that you would typically dedicate a specific Visualforce page for this purpose rather than attempting to use this attribute on one used for other purposes.
Tip
Make sure that you use as much vanilla HTML and CSS as possible; the Visualforce standard components do not always render well in this mode. For this reason, it is also useful to use the standardStylesheets
attribute to disable Salesforce CSS as well.
You can also programmatically access this capability by using the PageReference.getContentAsPDF
method and attaching the PDF generated to records for future. If you would rather generate PDF content without using a Visualforce page, you can...