I am facing very unusual and silly issue. I have a vf page with render as pdf based on a condition. The page contains two tables. I am hiding first table conditionally so that second table can generate with proper pdf format. Here is what should happen: On button click of first table a new tab should open and first table should be hidden and second table should be visible in pdf format. What happens is a new tab opens but first table does not get hidden as the condition (isRender remains false) remains true. Here is the code for more understanding.

VF Page:

<apex:page id="pg" sidebar="false" showHeader="false" standardStylesheets="false" applyHtmlTag="false" 
controller="MultipleSalarySlips" renderAs="{!if(isRender == true, "PDF", '')}">
<apex:form id="frm">
    <table style = "margin-left: 560px;border: 2px solid;padding: 19px;border-radius:5px;background-color:#f1d1bf;display:{!if(isRender == true, 'None','')}" id = "firstTable">
        <!--Table 1 code-->

    <table style="width:100%;margin-top: 50px;border-collapse: collapse;page-break-after:always;">
              <!--Table 2 code with repeate-->

Apex Class:

public with sharing class MultipleSalarySlips {
public String selectedToMonth{get;set;}
public String selectedFromMonth{get;set;}
public String selectedToYear{get;set;}
public String selectedFromYear{get;set;}
public List<Monthly_Salary_Details__c> monthlySalaryDetails{get;set;}
public List<WrpSalaryDetail> wrpSalaryDetails{get;set;}
public Monthly_Salary_Details__c msd{get;set;}
public Boolean isRender{get;set;}
public static Integer iq = 1;

public MultipleSalarySlips(){
    wrpSalaryDetails = new List<WrpSalaryDetail>();
    msd = new Monthly_Salary_Details__c();
    isRender = false;

3 Answers 3


I think for that you need to use rerender attribute and action function.

  1. On button click, call an action function that set the value of isRender to true.
  2. rerender the apex:page, this time you get the value as true and your page displayed as in pdf format.

<apex:actionFunction name="resetRendering" action="{!resetValue}" rerender="pg" />.

Hope it helps you :)

  • Hi Anurag. Thanks for replying. It still does not render as PDF. I think on new tab, constructor gets called and isRender is set to false again. Jun 24, 2016 at 8:08
  • Yes, whenever page loads, constructor called everytime. For this you need to create multiple pages. On first page you have button and on click open second page that have renderAs attribute. It will fix this issue. Jun 24, 2016 at 8:48

Maybe this will help: Document , If you do not want it be re-initialised use a boolean variable to check if it already has been initialised.

  • Thanks @sfdcfox for editing document link. Thanks d_k for your helping hand. Jun 27, 2016 at 11:15

This is how I did it. I used <apex:actionFunction> to call the method. This way it directly called the method.

VF Page

<apex:actionFunction id="downloadSlips" name="downloadSlips" action="{!downloadSlip}"/>
<apex:commandButton title="Download" value="Download" onclick="downloadFunc(); return false;"/>
function downloadFunc() {

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .