1

Below is my controller

public class MyController { 

public   Letter__C letter{get;set;}
public String isPDF { get; set; }
public Boolean bolPrintableView {get;set;}

    public MyController(){
       letter = [SELECT Id,Name__c
                      WHERE Id =  :ApexPages.currentPage().getParameters().get('Id') LIMIT 1];
         IF(letter != null && obj.Status__c == 'Approved'){ 
        isPDF  = 'pdf';
    }else{
        isPDF  = 'html';
    }
    }
public void init() {
    String strPrintableView = 
    ApexPages.currentPage().getParameters().get('print');
    bolPrintableView = (strPrintableView == '1');
}
}

VF Page:

<apex:page controller="MyController" renderAs="{!isPDF}" applyBodyTag="false" >

<head>
    <style> 
    body { font-family: 'Arial Unicode MS'; }

@page{
        size: letter;
        margin:20%;
        @top-center{
            content: "TTD Letter";
            font-family: Helvetica, Arial, sans-serif;
            font-size: 24px;
            font-weight: bolder;
        }
        @bottom-right{
            content: "Yours Sincerely,";
            font-family: Helvetica, Arial, sans-serif;
            font-size: 10px;
        }
   }
body {
        font-family: Helvetica, Arial, sans-serif;
        font-size: 14px;
}
    </style>
</head>
    <div align="right"><strong>Date</strong>: {!DAY(Today())} {!CASE(MONTH(Today()), 1, 'January', 2, 'February', 3, 'March', 4, 'April', 5, 'May', 6, 'June', 7, 'July', 8, 'August', 9, 'September', 10, 'October', 11, 'November', 12, 'December', 'Unknown')} {!YEAR(Today())}</div>
    <div align="left">Dear,</div>
 <p>My Text</p>

    <p>My Text</p>    

</apex:page>

When I have clicked on my PDF button I got the printable view of the current page but not of my PDF.

5
  • How you are calling this page? What are the parameters you are passing? It seems controller code is not properly written Jul 24, 2018 at 18:27
  • What happens if you replace the variable {!isPDF} from the renderAs attribute with just pdf? Jul 24, 2018 at 20:52
  • @RenatoOliveira I have used {!isPDF} as I have put a conditional if clause in my controller to generate the pdf
    – sf123
    Jul 25, 2018 at 3:04
  • Right, but what happens when you use either 'html' or 'pdf' on that attribute? Without using the controller variable? Jul 25, 2018 at 13:15
  • if I remove {!isPDF} then the pdf would be rendered even for the record where the status is not equal to approved
    – sf123
    Jul 25, 2018 at 14:56

0

You must log in to answer this question.