+ Start a Discussion
RMS@NCRMS@NC 

Input Text values to PDF

I have a Visualforce Page, with some input text fields. (There is NO standard or custom object associated with this Page). There is a button 'Generate PDF'. On click of this button, PDF needs to be generated having all the input text values.
How do we send the input text values to the PDF? (PDF is getting generated having only labels, no values) Please let me know!
Best Answer chosen by RMS@NC
Abdul KhatriAbdul Khatri
Hi RMS@NC

Visualforce Page
<apex:page renderAs="{!if($CurrentPage.parameters.isPdf == $CurrentPage.parameters.vcity, '', 'pdf')}" controller="Vendor_Registraion">
    <script >
        function CheckAmount(){
            var vendorsName = document.getElementById('{!$Component.vendorreg.vendor.pbsId.vName}');
           
            if(document.getElementById('{!$Component.vendorreg.vendor.pbsId.vName}').value == ''){
                   alert("Vendor Name is mandatory");
            }
                      
            var inputAmount = document.getElementById('{!$Component.vendorreg.vendor.pbsId.amount}');
                  if(document.getElementById('{!$Component.vendorreg.vendor.pbsId.amount}').value ==''){
                            alert('Amount is mandatory to Send email');
                }
           }
    
        function CheckCity(){
           if((document.getElementById('{!$Component.vendorreg.vendor.pbsId.vcity}').value =='') || (document.getElementById('{!$Component.vendorreg.vendor.pbsId.vcountry}').value =='')){
                alert("Both City and Country are required to Generate PDF!");                   
           };
            
           }
    </script>
    
    <apex:form id="vendorreg">
    <apex:pageBlock id="vendor" title="Vendor Registration Form">
        <apex:pageblockSection id="pbsId" columns="2" > 
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vName" value="{!vName}" label="Vendor Company Name" required="true"/> 
       <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vName}" label="Vendor Company Name"/> 
         
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vpereson" value="{!vpereson}" label="Vendor Contact Person"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vpereson}" label="Vendor Contact Person" /> 
        
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vcity" value="{!vcity}" label="City"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vcity}" label="City"/> 
        
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vcountry" value="{!vcountry}" label="Country"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vcountry}" label="Country"/> 
        
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="amount" value="{!amount}" label="Amount per event"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!amount}" label="Amount per event"/> 
        </apex:pageblockSection> 
                  
        <apex:pageBlockButtons >
            <apex:commandButton value="Send Email"  onclick="CheckAmount();" />
            <apex:commandButton value="Reset" />
            <apex:commandButton value="Generate PDF" onclick="CheckCity();" action="/apex/Vendor_Registraion?isPdf=true"/>
        </apex:pageBlockButtons>
        
        <apex:pageMessages id="showmsg"></apex:pageMessages>
    </apex:pageBlock>
    </apex:form> 
</apex:page>

Controller
public class Vendor_Registraion {

    public string vName {get; set;}
    public string vpereson {get; set;}
    public string vcity {get; set;}
    public string vcountry {get; set;}
    public string amount {get; set;}
}

Let me know if this helps

All Answers

Abdul KhatriAbdul Khatri
Hi RMS@NC

Can you please share you Visualforce Page with those input text fields?
RMS@NCRMS@NC
Hi Abdul,
Here is the Visualforce Page:

<apex:page renderAs="{!if($CurrentPage.parameters.isPdf == $CurrentPage.parameters.vcity, '', 'pdf')}" >
    <script >
        function CheckAmount(){
            var vendorsName = document.getElementById('{!$Component.vendorreg.vendor.pbsId.vName}');
           
            if(document.getElementById('{!$Component.vendorreg.vendor.pbsId.vName}').value == ''){
                   alert("Vendor Name is mandatory");
            }
                      
            var inputAmount = document.getElementById('{!$Component.vendorreg.vendor.pbsId.amount}');
                  if(document.getElementById('{!$Component.vendorreg.vendor.pbsId.amount}').value ==''){
                            alert('Amount is mandatory to Send email');
                }
           }
    
        function CheckCity(){
           if((document.getElementById('{!$Component.vendorreg.vendor.pbsId.vcity}').value =='') || (document.getElementById('{!$Component.vendorreg.vendor.pbsId.vcountry}').value =='')){
                alert("Both City and Country are required to Generate PDF!");                   
           };
            
           }
    </script>
    
    <apex:form id="vendorreg">
    <apex:pageBlock id="vendor" title="Vendor Registration Form">
        <apex:pageblockSection id="pbsId" columns="2" > 
        <apex:inputText id="vName" label="Vendor Company Name" required="true"/> 
        <apex:inputText id="vpereson" label="Vendor Contact Person"/>
        <apex:inputText id="vcity" label="City"/>
        <apex:inputText id="vcountry" label="Country"/>
        <apex:inputText id="amount" label="Amount per event"/>
        </apex:pageblockSection> 
                  
        <apex:pageBlockButtons >
            <apex:commandButton value="Send Email"  onclick="CheckAmount();" />
            <apex:commandButton value="Reset" />
            <apex:commandButton value="Generate PDF" onclick="CheckCity();" action="/apex/Vendor_Registraion?isPdf=true"/>
        </apex:pageBlockButtons>
        
        <apex:pageMessages id="showmsg"></apex:pageMessages>
    </apex:pageBlock>
    </apex:form> 
</apex:page>


When I click the 'Generate PDF' button, a PDF should be generated having all the Input values.

Thank You!
Abdul KhatriAbdul Khatri
Hi RMS@NC

Visualforce Page
<apex:page renderAs="{!if($CurrentPage.parameters.isPdf == $CurrentPage.parameters.vcity, '', 'pdf')}" controller="Vendor_Registraion">
    <script >
        function CheckAmount(){
            var vendorsName = document.getElementById('{!$Component.vendorreg.vendor.pbsId.vName}');
           
            if(document.getElementById('{!$Component.vendorreg.vendor.pbsId.vName}').value == ''){
                   alert("Vendor Name is mandatory");
            }
                      
            var inputAmount = document.getElementById('{!$Component.vendorreg.vendor.pbsId.amount}');
                  if(document.getElementById('{!$Component.vendorreg.vendor.pbsId.amount}').value ==''){
                            alert('Amount is mandatory to Send email');
                }
           }
    
        function CheckCity(){
           if((document.getElementById('{!$Component.vendorreg.vendor.pbsId.vcity}').value =='') || (document.getElementById('{!$Component.vendorreg.vendor.pbsId.vcountry}').value =='')){
                alert("Both City and Country are required to Generate PDF!");                   
           };
            
           }
    </script>
    
    <apex:form id="vendorreg">
    <apex:pageBlock id="vendor" title="Vendor Registration Form">
        <apex:pageblockSection id="pbsId" columns="2" > 
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vName" value="{!vName}" label="Vendor Company Name" required="true"/> 
       <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vName}" label="Vendor Company Name"/> 
         
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vpereson" value="{!vpereson}" label="Vendor Contact Person"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vpereson}" label="Vendor Contact Person" /> 
        
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vcity" value="{!vcity}" label="City"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vcity}" label="City"/> 
        
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="vcountry" value="{!vcountry}" label="Country"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!vcountry}" label="Country"/> 
        
        <apex:inputText rendered="{!OR($CurrentPage.parameters.isPdf=='',$CurrentPage.parameters.isPdf=='false')}" id="amount" value="{!amount}" label="Amount per event"/>
        <apex:outputText rendered="{!$CurrentPage.parameters.isPdf=='true'}" value="{!amount}" label="Amount per event"/> 
        </apex:pageblockSection> 
                  
        <apex:pageBlockButtons >
            <apex:commandButton value="Send Email"  onclick="CheckAmount();" />
            <apex:commandButton value="Reset" />
            <apex:commandButton value="Generate PDF" onclick="CheckCity();" action="/apex/Vendor_Registraion?isPdf=true"/>
        </apex:pageBlockButtons>
        
        <apex:pageMessages id="showmsg"></apex:pageMessages>
    </apex:pageBlock>
    </apex:form> 
</apex:page>

Controller
public class Vendor_Registraion {

    public string vName {get; set;}
    public string vpereson {get; set;}
    public string vcity {get; set;}
    public string vcountry {get; set;}
    public string amount {get; set;}
}

Let me know if this helps
This was selected as the best answer
RMS@NCRMS@NC
Thank you for helping me. But sorry, even now, only the labels are getting printed in the PDF. Not the input values.
Any further help?
Abdul KhatriAbdul Khatri
RMS@NC

It is working for me.

Input Visualforce Page:
User-added image

pdf
User-added image
RMS@NCRMS@NC
Oh! Is there some setting that I am missing? Should I keep something checked?
I tried with the same code. It is not coming!

User-added image
Abdul KhatriAbdul Khatri
RMS@NC

Sorry I doubt you the same code as I see * in your pdf which is not coming in mine. I also have a controller class.
RMS@NCRMS@NC
Sorry. I have just copied the same code. In fact, I cleared the cookies and tried in 2 different browsers too. No PDF with values. I understand about the * thing, but dont know how/why !! 
Abdul KhatriAbdul Khatri
Will you like to connect and see what is happening with you.
RMS@NCRMS@NC
Sorry for the very late response. I tried the code given by you in a new org, and it worked perfectly! Thank you so much!! 
Abdul KhatriAbdul Khatri
RMS@NC

I am glad it worked.

Would you be kind to mark it a best answer? That would really be appreciated.

Regards.