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 for generating 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 to this purpose rather than attempting to use this attribute on one that’s used for other purposes.
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 the future. If you would rather generate PDF...