Методы отображения содержимого страницы Visualforce в формате PDF в Salesforce

Чтобы отобразить содержимое страницы Visualforce в формате PDF, вы можете использовать следующий код в Salesforce Apex:

Метод 1. Использование атрибута renderAs в теге

<apex:page renderAs="pdf">
    <!-- Content of the Visualforce page -->
</apex:page>

Метод 2. Использование метода getContentAsPDF() в Apex

// Create an instance of the PageReference class with the URL of the Visualforce page
PageReference pageRef = new PageReference('/apex/YourVisualforcePage');
// Set the rendering options to PDF
pageRef.getParameters().put('renderAs', 'pdf');
// Get the PDF content as a Blob
Blob pdfContent = pageRef.getContentAsPDF();

Метод 3. Использование параметра URL

/apex/YourVisualforcePage?renderAs=pdf

Метод 4. Использование атрибута действия в теге или

<apex:commandButton action="{!URLFOR('/apex/YourVisualforcePage', null, [renderAs = 'pdf'])}" value="Generate PDF" />

Метод 5. Использование тега apex:outputLink

<apex:outputLink value="{!URLFOR('/apex/YourVisualforcePage', null, [renderAs = 'pdf'])}">Download PDF</apex:outputLink>