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
Sudhan KanadeSudhan Kanade 

Can we generate editable visualforce page content into a pdf ?

I have created a editable table grid in visualforce page. Users can update some of the information on that table grid.  Now once its edited. I would like to generate a PDF and send it as an attachment.  

Is there a way that the updated visualforce page can be rendered as PDF so that it can be sent as an attachment ?

Thanks
Ankit AroraAnkit Arora
I think if you create two pages, one to take the input from user (in the grid) and other page which renderAs PDF then your problem will be solved right?

Say you've taken the input from user on first page, as soon as user clicks on send/create etc then you can pass those inputs to your other page's controller and render it as PDF.
Sudhan KanadeSudhan Kanade
Hi Ankit,

Thanks for replying back to my question. I tried to implement your suggestion by creating two VF Pages, second being renderAs="PDF".  But so far I am not able to pass the parameters to second page.  I had tried various options, but because I am not using any standard Table component due to the transposition of the data (row being displayed as column and vice-versa) none of the solutions have worked so far. Do you have any suggestions  ?    So when the users update the table cells, they should get captured and display in the PDF page (VF2).  But it only shows the same page without the updated data in it.  I thought that by doing {!value} the data gets binded to the controller so that it can display them on different viewstate. Here is the code : - 

VF1 :  VF2 only has renderAs="PDF"
<apex:page controller="ProductCrossRefWrapperController" tabstyle="Account" > 
 <apex:includeScript value="{!$Resource.JqueryGit}"/>
 <apex:stylesheet value="{!$Resource.ProductCrossRefCSS}"/>
 <apex:form >
 <apex:commandButton value="Generate PDF" action="{!processButtonClick}">
            <apex:param name="price"
                value="test"
                assignTo="{!price}"/>
        </apex:commandButton>
 <div id="products">
 <apex:pageBlock title="PRODUCT CROSS REFERENCE CHART">
  <table class="list" border="2" cellpadding="1" cellspacing="1">
    <tr>
      <apex:repeat value="{!headWrap.values}" var="heading">
        <th>
           {!heading}
        </th>
      </apex:repeat>
    </tr>
    <apex:repeat value="{!rowWrappers}" var="row">
       <tr class="productRow">        
         <apex:repeat value="{!row.values}" var="value">           
           <td contenteditable='true'>
             <apex:outputText escape="false" value="{!value}"></apex:outputText>
           </td>           
         </apex:repeat>
       </tr>
    </apex:repeat>
   
  </table>

  </apex:pageBlock>

</div>

</apex:form>
</apex:page>

Apex Controller :-
//
// Custom controller for wrapper example
//
public with sharing class ProductCrossRefWrapperController 
{
    // the list of products that will be displayed in the page
    List<Product_Cross_Reference__c> products;
    
    // the list of row wrappers that contain a transposed view of the products
    private List<RowWrapper> rows;
    
    // the headings for the row wrappers table
    private RowWrapper headings;
    
    // retrieves the list of accounts backing the page
    public List<Product_Cross_Reference__c> getProducts()
    {
        if (null==products)
        {
            products=[select Product_Cross_Reference__c.Brand_Name__c, Product_Cross_Reference__c.Product_Name__c, Product_Cross_Reference__c.Product_Number__c,  Product_Cross_Reference__c.Price_1_Gal__c, Product_Cross_Reference__c.Price_5_Gal__c  from Product_Cross_Reference__c];
        }
        
        return products; 
    }
    
    // retrieves the row wrapper containing the wrapped account headings
    public RowWrapper getHeadWrap()
    {
        // set up the headings
        if (null==headings)
        {
            headings=new RowWrapper();
            headings.addValue('');
            for (Integer idx=0; idx<getProducts().size(); idx++)
            {
                headings.addValue(getProducts()[idx].Brand_Name__c);
            }
        }
                                     
        return headings;
    }
    
    // retrieves the list of row wrappers
    public List<RowWrapper> getRowWrappers()
    {
        if (null==rows)
        {
            rows=new List<RowWrapper>();
            
            // create a row for each field - there are 6 of these, Brand Name, Product Name, Product Number, Price_1, Price_5 
            for (Integer idx=0; idx<4; idx++)
            {
                rows.add(new RowWrapper());
            }
            
            String[] myfields = new String[]{'Product Name', 'Product Number', 'Price: 1-Gal', 'Price: 5-Gal'};
            
            Integer count = 0;
            for(String i : myfields){                
               // rows.add(new RowWrapper());
                rows[count].addValue(i);
                count++;
                if(count == 5){
                    break;
                }
            }
            
            // iterate the accounts and populate the rows
            for (Integer idx=0; idx<getProducts().size(); idx++)
            {
                //rows.add(new RowWrapper());
                //rows[0].addValue(getProducts()[idx].Brand_Name__c);
                rows[0].addValue(getProducts()[idx].Product_Name__c);
                rows[1].addValue(getProducts()[idx].Product_Number__c);
                rows[2].addValue(ifnull(getProducts()[idx].Price_1_Gal__c));
                rows[3].addValue(ifnull(getProducts()[idx].Price_5_Gal__c));                
            }
        }
        
        return rows;
    }
    
    public String ifnull(Decimal s1) {
        String result = '';
        if (s1 != null) { result = String.valueOf(s1);}
        return result;
    }
    public String ifnull(String s1) {
        String result = '';
        if (s1 != null) { result = s1;}
        return result;
    }
    
    // nested class that wraps information about a row - in this case simply a list of strings 
    public class RowWrapper
    {
        // the values (cells) making up this row
        public List<Object> values {get; set;}
        
        // constructor
        public RowWrapper()
        {
            values=new List<Object>();
        }
        
        // append a value (cell) to the row
        public void addValue(Object value)
        {
            values.add(value);
        }
        
       
    }
    
    // handle the action of the commandButton
    public PageReference processButtonClick() {
        PageReference reRend = new PageReference('/apex/ProductCrossRefWrapperPDFVF');
        reRend.setRedirect(false);
        return reRend;
    }
    
    public String price {
        get;
        // *** setter is NOT being called ***
        set {
            price= value;
            System.debug('value: '+value);
        }
    }

    
}