+ Start a Discussion
Bhargav krishna 1Bhargav krishna 1 

How to create a custom PDF page

Hi everyone,
How to create a custom vfpage as PDF page. I have the component reanderedAS="PDF", but i was to see the field values in the genenrated PDF. Can anyone help me over here.

Regards,
Bhargav.
Best Answer chosen by Bhargav krishna 1
Deepak Pandey 13Deepak Pandey 13
<apex:page standardController="Account" extensions="AccountPDFController" renderAs="pdf" applyBodyTag="false">
<head> <style type="text/css"> body { font-family: Arial Unicode MS; } </style> </head> <h1>Account Information</h1> <apex:panelGrid columns="2" border="1" cellspacing="0" cellPadding="5" width="100%">
<apex:outputText value="{!$ObjectType.Account.fields.Name.label}" />
<apex:outputText value="{!Account.Name}" />
<apex:outputText value="{!$ObjectType.Account.fields.AccountNumber.label}" />
<apex:outputText value="{!Account.AccountNumber}" />
<apex:outputText value="{!$ObjectType.Account.fields.WebSite.label}" />
<apex:outputText value="{!Account.WebSite}" /> <apex:outputText value="…" />
<apex:outputText value="…" />
</apex:panelGrid>
</apex:page>

controller--

public class AccountPDFController
{
public AccountPDFController(ApexPages.StandardController controller)
{
Account acc = (Account)controller.getRecord();
String accNum = acc.AccountNumber;
//Assign "Account_[Ac].pdf" as a file name
String fileName = 'Account_' + accNum + '.pdf'; Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=' + fileName);
} }

All Answers

Deepak Pandey 13Deepak Pandey 13
<apex:page standardController="Account" extensions="AccountPDFController" renderAs="pdf" applyBodyTag="false">
<head> <style type="text/css"> body { font-family: Arial Unicode MS; } </style> </head> <h1>Account Information</h1> <apex:panelGrid columns="2" border="1" cellspacing="0" cellPadding="5" width="100%">
<apex:outputText value="{!$ObjectType.Account.fields.Name.label}" />
<apex:outputText value="{!Account.Name}" />
<apex:outputText value="{!$ObjectType.Account.fields.AccountNumber.label}" />
<apex:outputText value="{!Account.AccountNumber}" />
<apex:outputText value="{!$ObjectType.Account.fields.WebSite.label}" />
<apex:outputText value="{!Account.WebSite}" /> <apex:outputText value="…" />
<apex:outputText value="…" />
</apex:panelGrid>
</apex:page>

controller--

public class AccountPDFController
{
public AccountPDFController(ApexPages.StandardController controller)
{
Account acc = (Account)controller.getRecord();
String accNum = acc.AccountNumber;
//Assign "Account_[Ac].pdf" as a file name
String fileName = 'Account_' + accNum + '.pdf'; Apexpages.currentPage().getHeaders().put('content-disposition', 'attachment; filename=' + fileName);
} }
This was selected as the best answer
Deepak Pandey 13Deepak Pandey 13
send your code if your problem is not resolve.
Deepak Pandey 13Deepak Pandey 13
You declare a string and put the current id on it or you hardcoded pass a id...