function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tganikumartganikumar 

How to generate PDF file in salesforce using visualforce page...?

Hello everyone,

 

Actually i created pdf with using following code.... but i want one clarification aboout this...

 

 

<apex:page standardController="Project_Charter__c" renderAs="PDF" extensions="PCReqDocPDF">
<!--<apex:sectionHeader title="Project Charter"/>-->
<style>
body {font-family: Arial Unicode MS;}
.companyName {
display:none;
color:red;
}
</style>
<h2>Project Charter :&nbsp;<apex:outputText style="color:blue"><font color="red">{!Project_Charter__c.name}</font></apex:outputText></h2>

<p><b><font face="Arial" color="red"><apex:outputText styleClass="companyName">Basic Information</apex:outputText></font></b></p>

<table border="0" width="100%" id="table2">
<tr>
<td colspan="3">
<font face="Arial">Project Charter Number <b>:</b> &nbsp;&nbsp;&nbsp;&nbsp;{!Project_Charter__c.Name}<br/><br/></font>
<font face="Arial">Project Charter Name&nbsp;&nbsp;&nbsp;&nbsp;<b>:</b> &nbsp;&nbsp;&nbsp;&nbsp;{!Project_Charter__c.Project_Charter_Name__c} <br/><br/></font>
<font face="Arial">Project Charter Description <b>:</b> <br/>{!Project_Charter__c.Project_Charter_Description__c} <br/><br/></font>
</td>
</tr>
</table>

<br/>

<p><b><font face="Arial" color="#000080">Executive Summary</font></b></p>

<table border="0" width="100%" id="table2">
<td colspan="3">
<font face="Arial">Executive Summary <b>:</b> <br/>{!Project_Charter__c.Executive_Summary__c} <br/></font>
</td>
</table>
<br/>
<hr/>

<p><b><font face="Arial" color="#000080" >Business Overview</font></b></p>

<table border="0" width="100%" id="table2">
<td colspan="3">
<font face="Arial">Business Overview <b>:</b> <br/>{!Project_Charter__c.Business_Overview__c} <br/></font>
</td>
</table>
<br/>


<p><b><font face="Arial" color="#000080">Business Objectives</font></b></p>
<table border="0" width="100%" id="table2">
<td colspan="3">
<font face="Arial">Business Objectives <b>:</b> <br/>{!Project_Charter__c.Business_Objectives__c} <br/></font>
</td>
</table>

</apex:page>

 

Here, i got pdf file using above code. But i am not getting colors for this and whenever i see this i want to save this file into my code... means if i want to save this document then automatically that will attach into my notes and attachments related list... So for this i want some code ... is this possible attach this file into notes and attachments related list?

 

give reply as sson as possible

 

....

thanks 

@taani.ax1426@taani.ax1426

Hi,

 

For getting color in first part relace the code with 

<style>
body {font-family: Arial Unicode MS;}.companyName {color:red;}
</style>

 

Let me know whether you got color in heading or not, or I am getting your query worng. For Notes and attachment part, I am working, get back to you soon.

 

Regards,

Taani

tganikumartganikumar

Hi taani,

 

This is also not working in my code... and the style function also not working in my code. How to do this can u give me some reply as soon as possible....?

tganikumartganikumar
Hi taani, This is also not working in my code... and the style function also not working in my code. How to do this can u give me some reply as soon as possible....? -- Ganesh Kumar T 9246756194
@taani.ax1426@taani.ax1426

Hi,

 

Try to match this code with your code..

 

//Attach the PDF to the Notes & Attachments Area
/* Get the page definition */
PageReference ForecastPdfPage = Page.forecast;
/* set the id on the page definition */
ForecastPdfPage.getParameters().put('Id',q.Id);
/* generate the pdf blob */
Blob ForecastPdfBlob = ForecastPdfPage.getContent();
/* create the attachment against the Opportunity */
Attachment a = new Attachment(parentId = q.id, name=opportunityNo.NAME + '-'+ opportunityNo.Opportunity_No__c+'-'+'Forecast.pdf', body = ForecastPdfBlob);
/* insert the attachment */
insert a;

 

Not sure wether it will help or not..still

 

Regards,

taani