+ Start a Discussion
NSK000NSK000 

Regarding vf page

I'm trying to create a vf page- its more like a review/feedback form. 

<apex:page standardController="Purchase_Order__C" extensions="PO_VendorPerformanceForm" >
<apex:form>
 <apex:pageBlock > 
                    <apex:outputPanel >
                <apex:pageBlockSection title="Submitted by:" showHeader="true" collapsible="false">
                    <apex:outputText value="Name: {!Purchase_Order__c.Requesitioner_Liaison__r.name}"/>
                    <apex:outputText value="Date: {!today()}"/>                    
                    <apex:outputText value="Division Name: {!Purchase_Order__c.Division_Name__c}"/> 
                    <apex:outputText value="Division No: {!Purchase_Order__c.Requesitioner_Liaison__r.DivisionNum__c}"/> 
                    <apex:outputText value="Title: {!Purchase_Order__c.Requesitioner_Liaison__r.Title}"/>
                </apex:pageBlockSection>
                    </apex:outputPanel> 
            </apex:pageBlock>
            <apex:pageBlock >
                <apex:pageBlockSection title="1. Contract Designation:" collapsible="false">
                    <apex:pageBlockSectionItem > 
                        <apex:selectcheckboxes >
                            <apex:selectOption itemLabel="Commodities" itemValue="f"/>
                            <apex:selectOption itemLabel="Services" itemValue="cpp"/>    
                        </apex:selectcheckboxes>     
                    </apex:pageBlockSectionItem>
                </apex:pageBlockSection>
            </apex:pageBlock>
</apex:form>
</apex:page>

Controller: 
public class PO_VendorPerformanceForm {
 public PO_VendorPerformanceForm(ApexPages.StandardController controller) {
        Purchase_Order__c po = (Purchase_Order__c)controller.getRecord();
        parentId = po.Id;
        pdfName = po.Name + '-VPR';
    }
 public ID parentId {get;set;}
    public String pdfName {get;set;}
    public string contentType {get;set;}
    
    /*    SAVE PDF     */
    public PageReference savePdf() {
        // ATTACH VPR TO PO
        // Get PDF of Vendor Perf. Form
        PageReference pdf = Page.POVendorPerfForm;
        pdf.getParameters().put('id',parentId);
        // Initialize attachment
        Attachment attach = new Attachment();
        // the contents of the attachment from the pdf
        Blob body;
        try {
            body = pdf.getContentAsPDF(); // PDF body
        } catch (VisualforceException e) {
            body = Blob.valueOf('Some Text');
        }
        
        attach.Body = body;
        attach.Name = pdfName + '.pdf';
        attach.IsPrivate = false;
        attach.ParentId = parentId; // PO's Id
       
        insert attach;
        
        // (Future) Send Email
        sendEmail(attach.Id);
        return page.POVPRSuccessPage;
    }
    
    /* SEND EMAIL    */
    @future(callout=true)
    public static void sendEmail(Id vprFormId) {
        // Get VPR
        Attachment vprAttachment = [SELECT Id,Name,ParentId,Body,BodyLength 
                                    FROM Attachment 
                                    WHERE Id = :vprFormId];
        
        // Get Template
        EmailTemplate ev = [select id,name,Subject,Body 
                            from EmailTemplate 
                            where name='VPR_Email_template'];

        // Create Email
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        List<Messaging.EmailFileAttachment> emailAttachments = new List<Messaging.EmailFileAttachment>();
        Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
        efa.setFileName(vprAttachment.Name);
        efa.setBody(vprAttachment.Body);
        emailAttachments.add(efa);
        email.setFileAttachments(emailAttachments);
        // Set "To" address
        List<String> toAddresses = new List<String>();
        toAddresses.add('xyz@gmail.com');
        email.setToAddresses(toAddresses);
        // Set "From" address (not applicable in this case)
        /*(OrgWideEmailAddress[] owea = [select Id 
                                      from OrgWideEmailAddress 
                                      where Address = ''];
        if (owea.size() > 0 ) {
            email.setOrgWideEmailAddressId(owea.get(0).Id);
        }*/
        email.subject = ev.Subject;
        email.setSaveAsActivity(True);
        email.setHtmlBody(ev.Body);
        List<Messaging.SendEmailResult> results = new List<Messaging.SendEmailResult>();
        results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
    }
}

The problem is I'm able to save the vf page as pdf but I'm not able to see the checkboxes in that pdf. Can some one help me with this ? 
I appreciate your help.  Thank you in advance!
RamakantRamakant
Hello,

Please find below sample code to show checkbox:
<apex:page standardController="Account" renderAs="pdf">
    
     <apex:image value="/img/checkbox_unchecked.gif" rendered="{!IF(Account.Checkbox__c==false,true,false)}"/>
     <apex:image value="/img/checkbox_checked.gif" rendered="{!IF(Account.Checkbox__c==false,true,false)}"/>

  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Page: CheckboxPdf
  <!-- End Default Content REMOVE THIS -->
</apex:page>
Screenshot of PDF rendered :
User-added image
Please mark as best answer if helped for others help.

Regards,
Ramakant
 
NSK000NSK000
Hey Ramakant! Thank you for your reply.  
But the user has to input some data- like he has to select some checkboxes. After completing the form when he hit save Then the vf page is saved as pdf in notesandattachmnts.