4

I am trying to create a table using "apex:OutputPanel" but I get the error message "PDF generation failed. Check the page markup is valid." Any ideas how I can fix it? Here is my code below:

<messaging:emailTemplate subject="Warranty and Support Confirmation" recipientType="Contact" relatedToType="Entitlement">
<messaging:plaintextEmailBody >

Dear {!relatedto.Opportunity_Contact__r.Name},

Thank you for your order (Reference: {!relatedto.Opportunity__r.Client_PO__c}). Since this is a maintenance renewal, no products will be shipped. 

Attached is a copy of your renewal confirmation for your records. 

Please review the attached confirmation and advise us immediately if any of the information is inaccurate or if you require any changes. 

If you have any questions, please contact the renewals team at renewals@company.com. 

We very much appreciate your business. 

Sales Team 

</messaging:plaintextEmailBody>

<messaging:attachment renderAs="pdf" filename="{!relatedTo.End_User__r.Name}">
<html>
<body>

<img align="right" src="{!$Resource.logo}"></img><br></br><br></br><br></br><br></br><br></br><br></br><br></br><br></br>

<apex:outputText value="{0, date, MMMM d, yyyy}">
<apex:Param value="{!Today()}" />
</apex:OutputText><br></br><br></br>

<b>{!relatedto.Account.Name}</b><br></br>
{!relatedto.Account.BillingStreet}<br></br>
{!relatedto.Account.BillingState}, {!relatedto.Account.BillingPostalCode}<br></br>
{!relatedto.Account.BillingCountry}<br></br><br></br>



To Whom It May Concern:<br></br><br></br>

This is to confirm the following hardware and/or software is covered by a support contract:<br></br>
<br></br>


<b> End User Name: {!relatedto.End_User__r.Name}</b><br></br><br></br> 

<table border="1">

    <tr>
            <td align="center"><b> Product Code</b></td>
            <td align="center"><b> Description </b></td>
            <td align="center"><b> Serial Number </b></td>
            <td align="center"><b> Coverage Type </b></td>
            <td align="center"><b> Coverage End Date</b></td>
    </tr>


<apex:repeat value="{!relatedto.Assets__r}" var="o">
<tr>
<apex:OutputPanel rendered="{!o.Retired__c == false}" >
<apex:OutputPanel rendered="{!o.Returned__c == false}">
<apex:OutputPanel rendered="{!o.Asset_Status__c == 'Active'}">

               <td align="center"><apex:outputField value="{!o.Name}"/></td>
               <td align="center"><apex:outputField value="{!o.Product2.Name}"/></td>



                        <apex:OutputPanel rendered="{!o.RMAed__c == false}">
                           <td align="center"><apex:outputField value="{!o.SerialNumber}"/></td>
                         </apex:OutputPanel>

                        <apex:OutputPanel rendered="{!o.RMAed__c == true}">
                            <td align="center"><apex:outputField value="{!o.New_Asset_Serial_Number__c}"/></td>
                         </apex:OutputPanel>



                <td align="center"><apex:outputField value="{!o.Entitlement_Level__c}"/></td>



                <td align="center"><apex:outputField value="{!o.Entitlement_End_Date__c}" /></td>


</apex:OutputPanel>
</apex:OutputPanel>
</apex:OutputPanel>
</tr>
</apex:repeat>

</table>

Details of the Advance Maintenance Program can be found here:<br></br>

<a href="https://www.company.com/download-center">Support Program Overview</a><br></br><br></br>

Details of the Hardware Warranty can be found here:<br></br>

<a href="https://www.company.com/support/warranty-information">Hardware Warranty Information</a><br></br><br></br>


If you have any questions related to your support contract, please contact 
<a href="mailto:sales@Company.com">sales@Company.com</a>.<br></br><br></br>


Thank you.


</body>
</html>
</messaging:attachment>
</messaging:emailTemplate>
  • remove the renderAsPDF from the page and see the real error .Usually when there is an error in page this error pops in pdf – Mohith Shrivastava Dec 10 '13 at 3:09
  • @MohithKumar Thanks for your reply! There is no error when I remove renderAsPDF. Check the updated code above for the correct table generation. As soon as I renderAsPDF I still get that error message. Any other idea? – andy Dec 10 '13 at 3:32
  • Other idea to debug this is try removing components one by one to figure which is the component throwing your error – Mohith Shrivastava Dec 10 '13 at 4:37
  • just a thought .. try replacing <br></br> with self closing styled Br tags ... <br /> – VarunC Dec 10 '13 at 6:09
  • @MohithKumar Thanks for your reply again! After debugging the code, the problem definitely lies in the table portion: <table border="1"> ..... </table> The PDF generates as soon as I remove that portion (including the image). – andy Dec 10 '13 at 19:35
2

It's been a while ago but I think VF email templates that contain PDFs don't like images referenced from static resources.

First try commenting out the <image> tag and see if it generates the PDF correctly. My VF email templates refer to images in Documents on production org:

<img src="https://c.eu1.content.force.com/servlet/servlet.ImageServer?id=[image id here]&oid=[production org id here]"/>

(the important thing is to have the "externally available image" ticked in the Document)

Although (it's really been ages ago when I had to worry about it) I think SF fixed something there and now you can reference a static resource as long as the resource is set to cache=public and you use real <apex:image> instead of <img>.

| improve this answer | |
  • thanks for your answer! The image appears as soon as I remove the table portion of my code: <table border="1"> ..... </table> This means that the problem has to lie somewhere in the above <table> code. When I comment out the <img> tag, the PDF still does not generate. Any other ideas? – andy Dec 10 '13 at 19:39
  • This will sound very stupid but I sometimes got peculiar compilation errors (reflection-related?). Try putting <apex:variable var="ent" value="{!relatedTo}" /> above the table, then refer to this helper in the repeater: <apex:repeat value="{!ent.Assets__r}" var="o"> – eyescream Dec 10 '13 at 20:24
  • thanks for your reply! I tried it but no luck :(...do you think it's because I am using OutputPanel? – andy Dec 10 '13 at 22:05
  • I was thinking about that but outputPanels by default render to layout="none" which should be OK-ish from table point of view. Also you use outputField everywhere = there's little chance of unescaped & or < breaking the XML document... Does it persist when you have only 1 "column" in the table? – eyescream Dec 10 '13 at 22:18
  • Shall we try a chat session? chat.stackexchange.com/rooms/11900/email-template-with-pdf-fun – eyescream Dec 10 '13 at 22:23
0

Figured it out, put tr under all outputPanel but above td

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.