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
surasura 

Rendering Page PDF Format

Guys, I am developing an application that shares a controller between multiple pages.

In first page there is a form that contain multiple buttons.

on first page button one is pressed it calls a method and assign value  to Controller attribute and display that contents in the second page in a input field

 

Seond page contain a button to render same content in PDF format .when button is pressed  it redirects to a another page and display content in pdf format that Works fine !!!!!

 

On the first page there is a another button to directly show the content in PDF format by redirecting direcly to third page but that doesnt work  PDF is render as empty document

 

point to note

  • multiple pages share the same controller
  • content rendered as pdf
  • Same instance of the controller is used to access old value with out reinstantiation  (using PageReference.setredirect(false)  )

process works in two steps but same thing doesnt work in one step

step 1

public PageReference ViewMailInEditMode()

    
    {
        Map<String,String> formValues = new Map<String,String>();
        Id selectedEmp=employeeAssignment.Employee__c;
        String emailTemplate = this.emailTemplate;
        formValues.put('effectiveDate',String.valueOf(employeeAssignment.Effective_Date__c));
        formValues.put('id',selectedEmp);
        formValues.put('templateType',emailTemplate);
        if (emailTemplate.equals('Employee Extension'))
        {
            formValues.put('fromDate',String.valueOf(employeeAssignment.FromPeriod__c));
            formValues.put('toDate' ,String.valueOf(employeeAssignment.ToPeriod__c));
            formValues.put('currentDesignation',desgnationName);
            
        }
        EmailTemplates = new Email_Template__c();
        EmailTemplates.Body__c =EmailManager.CallMethod(formValues);
        PageReference pgRef = new PageReference('/apex/EmpAssignmentPrintview');
        pgRef.setRedirect(false);
        return pgRef;
    }

 

page 2

 

(printview)
  

<apex:page standardController="Employee_Assignment__c" extensions="EmployeeAssisgnmentExtension" id="page">
  
  <apex:pageBlock id="pageBlock1" >  
        <apex:form id="form1">
            <apex:inputField value="{!EmailTemplates.Body__c}"/>
            <apex:commandButton action="{!Save}" value="Print View"/>
        </apex:form>
    </apex:pageBlock> 
 </apex:page>

 step 2


  •  public PageReference Save()
        {
    
            PageReference pgRef = new PageReference('/apex/EmpAssignmentPrintview2');
            pgRef.setRedirect(false);
            return pgRef;
        }

     

    page 3 (printview2)
  • <apex:page standardController="Employee_Assignment__c" extensions="EmployeeAssisgnmentExtension" id="page" renderAs="pdf">
      <!-- Begin Default Content REMOVE THIS -->
      <apex:outputField value="{! EmailTemplates.Body__c}" />
      <!-- End Default Content REMOVE THIS -->
    </apex:page

     above code work fine

  • code that sum up above two steps to one

     public PageReference pdfview()
        {
            Map<String,String> formValues = new Map<String,String>();
            Id selectedEmp=employeeAssignment.Employee__c;
            String emailTemplate = this.emailTemplate;
            formValues.put('effectiveDate',String.valueOf(employeeAssignment.Effective_Date__c));
            formValues.put('id',selectedEmp);
            formValues.put('templateType',emailTemplate);
            if (emailTemplate.equals('Employee Extension'))
            {
                formValues.put('fromDate',String.valueOf(employeeAssignment.FromPeriod__c));
                formValues.put('toDate' ,String.valueOf(employeeAssignment.ToPeriod__c));
                formValues.put('currentDesignation',desgnationName);
                
            }
            
           // System.debug('ssssssssssssssssssssssssss');
            EmailTemplates = new Email_Template__c();
            EmailTemplates.Body__c =EmailManager.CallMethod(formValues);
            System.debug('ssssssssssssssssssssssssss'+ EmailTemplates.Body__c );
           
           PageReference pgRef1 = new PageReference('/apex/EmpAssignmentPrintview2');
           
            pgRef1.setRedirect(false);
           
            return pgRef1;
         } 

     the above code doesnt work 

Any help would be great  !!!!!!!!!!!!!!!!!!!!!

AndyPandyAndyPandy

Hi Sura,

 

Could I be incredibly rude and ask you for some help which is related to your issue?  Firstly, I'm afraid I cannot help you with your issue, my apologies.  However, you appear to be attempting something very similar to what I am trying to do, and clearly you're far more successful than me.

 

I have created a custom object called Adverse Incident - and there are a whole host of fields for it.  What I want is when a user is viewing a particular record - for there to be a button at the top called "Create PDF" - which then displays a PDF Form of that record (which would basically be VF Page rendered as a PDF).

 

You appear to have done this exact thing for your object - and you seem to have used relatively little code - would you mind explaining what your method was - and I can then attempt to learn how to do that and mimic your method for my scenario?

 

Again, apologies for making a somewhat unrelated reply to your query - but I really am struggling with this and any help you could provide would be very gratefully received.

 

Many thanks,

 

Andy

surasura

hi Andy ,

I saw your reply  ,  I am also bit new to Salesforce so I am not sure whethet i can be any help , any way lets give it a try 

first thing you need to do to view a page as PDF is set the rendered as attribute in page tag to  PDF. if there any input fields that contain HTML content  setting escape attribute to  fasle will certainly help .

 

Then if you retrive the  related object and set their contents to <apex:outputtext > value attribute it should work , give it a try .

Hope you understand what I am Sayiing , let me know  hot it went 

 

:smileyhappy:

AndyPandyAndyPandy

Hi Sura,

 

Thank you very much for your reply - it has helped.  I've been searching a lot this afternoon, and between you and another helpful contributor, I've manged to get a very crude PDF going:

 

But it IS working...

 

One thing that isn't quite coming out right, is my Account Names - the Custom Object has a Master-Detail lookup between both my Accounts and Person Accounts - when I reference both of those in my VF Page e.g.:

 

<apex:outputText value="{!Adverse_Incident__c.Account__c}"/>

 The output is just the long ID number of the Account, not the user-friendly Account Name.

 

Would you know how to alter that?

 

Thank you again,

 

Andy