To create an attractive PDF file from a Visualforce page, you can use the "renderAs" attribute in the "<apex:page>" tag along with some additional styling and formatting. Here's an example:
<apex:page controller="PDFController" renderAs="pdf">
<style>
/* Add custom CSS styles for the PDF layout */
body {
font-family: Arial, sans-serif;
font-size: 12px;
color: #333333;
margin: 20px;
}
h1 {
font-size: 24px;
color: #006699;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 10px;
border: 1px solid #cccccc;
}
th {
background-color: #f2f2f2;
font-weight: bold;
text-align: left;
}
</style>
<h1>Sample PDF Report</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<apex:repeat value="{!contacts}" var="contact">
<tr>
<td>{!contact.Name}</td>
<td>{!contact.Email}</td>
<td>{!contact.Phone}</td>
</tr>
</apex:repeat>
</tbody>
</table>
</apex:page>
In this example, we have a Visualforce page that renders as a PDF using the `renderAs="pdf"` attribute in the `<apex:page>` tag. The page includes custom CSS styles defined within the `<style>` tag to control the appearance of the PDF layout.
The page content consists of a heading `<h1>` and a table displaying contact information. The contact data is fetched from the `contacts` list in the Apex controller (PDFController).
To generate the PDF file, you would need to create the corresponding Apex controller (PDFController) with the logic to retrieve the data to be displayed in the PDF.
Ensure that you format and customize the CSS styles according to your specific design preferences. You can add additional HTML elements, such as headers, footers, images, or charts, to make the PDF more visually appealing.
When the Visualforce page is accessed with the `renderAs="pdf"` attribute, it will be rendered as a PDF file, allowing users to download an attractive PDF version of the page content.
Note: Ensure that you comply with Salesforce's governor limits and consider any page size limitations when generating the PDF files.