PDI · Question #224
Which code displays the contents of a Visualforce page as a PDF?
The correct answer is C. <apexipage renderAs="pdf">. To display the contents of a Visualforce page as a PDF document, the renderAs="pdf" attribute must be set on the <apex:page> tag.
Question
Which code displays the contents of a Visualforce page as a PDF?
Options
- A<apenipage contentType="pdf">
- B<apex:page contentType="application/pd ">
- C<apexipage renderAs="pdf">
- D<apex:page renderAs="application/pdf">
How the community answered
(35 responses)- A6% (2)
- B3% (1)
- C89% (31)
- D3% (1)
Why each option
To display the contents of a Visualforce page as a PDF document, the `renderAs="pdf"` attribute must be set on the `<apex:page>` tag.
The `contentType` attribute is used to specify the MIME type of the page's response, not to trigger PDF rendering, and 'pdf' is not a valid MIME type for this attribute.
While `application/pdf` is the correct MIME type for PDF, the `contentType` attribute alone does not convert the Visualforce page content into a PDF; it merely sets the HTTP header.
The `renderAs` attribute on the `<apex:page>` component is specifically designed to control the output format of the Visualforce page, and setting `renderAs='pdf'` instructs Salesforce to render the page content as a PDF document.
The `renderAs` attribute expects a keyword like 'pdf', not a full MIME type; using `renderAs="application/pdf"` is incorrect syntax for this attribute.
Concept tested: Visualforce page rendering as PDF
Source: https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm#pages_compref_page_attributes
Topics
Community Discussion
No community discussion yet for this question.