I have a visualforce page embedded in an iframe into another visualforce page (see below), the iframed pages is a PDF. When I click the custom button preview the PDF, The fields in the PDF are empty, but when I save the PDF into "Notes & Attachments", the PDF is populated with the information from the record... I know that I need to pass variable from the parent, but what needs to be done?
Custom Button: /apex/PdfGeneratorTemplate?id={!Monthly_Cloud_Bill__c.Id}
Parent
<apex:page controller="PdfGeneratorController" >
<apex:form >
<apex:pageBlock title="PDF Input">
<apex:pageBlockButtons >
<apex:commandButton action="{!savePdf}" value="Save PDF"/>
</apex:pageBlockButtons>
<apex:pageMessages />
<iframe height="600px" id="Page" name="InvoicePDF" src="/apex/InvoicePDF2" width="100%"></iframe>
</apex:pageBlock>
</apex:form>
</apex:page>
Iframe
<apex:page standardController="Monthly_Cloud_Bill__c" showHeader="false" renderas="pdf">
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
<td>
<img src='{!URLFOR($Resource.Logo)}' title="logo" />
</td>
<td align="right"><font face="Arial" >
<b>Quote for {!Monthly_Cloud_Bill__c.account__r.Name}</b></font><br/>
</td>
</tr>
<hr/>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr> <td><font face="Arial" >
{!$Organization.Name}<br/>
{!$Organization.Street}<br/>
{!$Organization.PostalCode} {!$Organization.City}<br/>
{!$Organization.Country}<br/>
</font></td>
<td width="60%"> </td>
<td ><font face="Arial">Invoice number: {!Monthly_Cloud_Bill__c.Name}
<br/>
Invoice Date:<apex:OutputField value="{!Monthly_Cloud_Bill__c.CreatedDate}"/><br/>
</font>
</td>
</tr>
</table>
<br/>
<hr/>
<p><b><font face="Arial" color="#000080">Address Information</font></b></p>
<table border="0" width="100%" id="table2">
<tr>
<td colspan="3">
<font face="Arial">Account name: {!Monthly_Cloud_Bill__c.Account__r.Name} <br/><br/></font>
</td>
</tr>
<tr>
<td>
<font face="Arial">Bill To:<br/>
{!Monthly_Cloud_Bill__c.Account__r.BillingStreet}<br/>
{!Monthly_Cloud_Bill__c.Account__r.BillingPostalCode} {!Monthly_Cloud_Bill__c.Account__r.BillingCity}
</font>
</td>
<td width="50%"></td>
<td >
<font face="Arial">Ship To:<br/>
{!Monthly_Cloud_Bill__c.Account__r.ShippingStreet}<br/>
{!Monthly_Cloud_Bill__c.Account__r.ShippingPostalCode} {!Monthly_Cloud_Bill__c.Account__r.ShippingCity}
</font>
</td>
</tr>
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Order Description</font></b></p>
<table border="0" width="100%" id="table4">
<tr>
<td bgcolor="#C0C0C0"><font face="Arial">Product</font></td>
<td bgcolor="#C0C0C0"><font face="Arial">Price</font></td>
<td bgcolor="#C0C0C0"><font face="Arial">Amount</font></td>
<!-- <td bgcolor="#C0C0C0"><font face="Arial">Total Price</font></td> -->
</tr>
<tr>
<td>Product1</td>
<td>{!Monthly_Cloud_Bill__c.Billing_Amount__c}</td>
<td>{!Monthly_Cloud_Bill__c.Amount__c}</td>
<!-- <td><apex:OutputField value="{!line.TotalPrice}"/></td> -->
</tr>
<tr>
<td bgcolor="#C0C0C0" align="right" colspan="6">
<font face="Arial"><b>Total Due:</b><apex:OutputField value="{!Monthly_Cloud_Bill__c.Net_Usage_For_Billing__c}"/></font></td>
</tr>
</table>
<br/>
<hr/>
<p><b><font color="#000080" face="Arial">Payment Instructions</font></b></p>
<table border="0" width="100%" id="table3">
<tr>
<td><font face="Arial">
Start date: <!-- <apex:OutputField value="{!Opportunity.QuoteBeginDate__c}"/><br/> -->
</font>
</td>
</tr>
</table>
<br/>
<!--<p><font face="Arial">{!Opportunity.Conditions__c}</font></p> -->
<br/>
<hr/>
<table width="100%" id="table5">
<tr>
<td width="50%"><b>{!$Organization.Name}</b></td>
</tr>
<tr>
<td width="50%"> </td>
<td width="50%"> </td>
</tr>
<tr>
<td width="50%">Signature<hr color="black" size="1"/></td>
<td width="50%">Signature<hr color="black" size="1"/></td>
</tr>
<tr>
<td width="50%">Name<hr color="black" size="1"/></td>
<td width="50%">Name<hr color="black" size="1"/></td>
</tr>
<tr>
<td width="50%">Title<hr color="black" size="1"/></td>
<td width="50%">Title<hr color="black" size="1"/></td>
</tr>
<tr>
<td width="50%">Date<hr color="black" size="1"/></td>
<td width="50%">Date<hr color="black" size="1"/></td>
</tr>
</table>
<p> </p>
<hr/>
<p align="center"><font face="Arial"><i>Copyright {!$Organization.Name}.</i></font></p>
</apex:page>
Class:
public with sharing class PdfGeneratorController {
// public ID parentId {get;set;}
//public String pdfName {get;set;}
String parentId = ApexPages.currentPage().getParameters().get('id');
Monthly_Cloud_Bill__c MCB = [SELECT Account__r.Id, Account__r.Name from Monthly_Cloud_Bill__c WHERE Id = :parentId];
Account acc = MCB.Account__r;
String AccountName = acc.Name;
String AccountId = acc.Id;
public PageReference savePdf() {
//PageReference pdf = Page.PdfGeneratorTemplate;
PageReference pdf = Page.InvoicePDF2;
// add parent id to the parameters for standardcontroller
pdf.getParameters().put('id',parentId);
// create the new attachment
Attachment attach = new Attachment();
// the contents of the attachment from the pdf
Blob body;
try {
// returns the output of the page as a PDF
body = pdf.getContent();
// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}
attach.Body = body;
// add the user entered name
attach.Name = AccountName + '.pdf';
attach.IsPrivate = false;
// attach the pdf to the account
attach.ParentId = parentId;
insert attach;
// send the user to the account to view results
//return new PageReference('/'+parentId);
return new PageReference('/'+'flow/Email_Cloud_Invoice?MBCID='+parentId + '&AccountID='+AccountId + '&AttachmentID='+doc.id+ '&retURL='+parentId);
}
}