2

I have a visual force page which renders correctly as pdf on screen but when I tried to open the attached file as pdf in email I'm getting error 'Adobe Reader could not open test.pdf' because it is either not a supported filoe type or because the file has been damaged(for example, it was sent as email attachment and wasn't correctly decoded). here is the Visual force page that is rendered correctly as pdf on screen butgiving error when attached as pdf file in email.

`

    <!-- took out this from title="{!$ObjectType.PA_Process__c.label} Edit" -->

        <!-- **********   [Record Type : PA Rec Type ]   **********  -->
        <apex:pageBlock >
            <apex:outputPanel id="status">
                <apex:pageblocksection showheader="true" > 

                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="PA#" />
                        <apex:outputfield value="{!PA_Process__c.parentIdForclones__c}"/>
                    </apex:pageBlockSectionItem>

                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Trigger Event" />
                        <apex:outputfield value="{!PA_Process__c.Trigger_Events__c}"/> 
                    </apex:pageBlockSectionItem>

                <apex:outputfield value="{!PA_Process__c.PA_Rev_Reason__c}"  style="width:250px;" />             
            </apex:pageblocksection>
        </apex:outputPanel>

        <apex:outputpanel id="SearchPanelId" rendered="{!OR(ISNULL(PA_Process__c.RecordTypeId),CASESAFEID(PA_Process__c.RecordTypeId)='012e00000008wBvAAI')}">

              <!-- General info rendered for getting input before approval -->
              <apex:pageblocksection title="General Info" showheader="true" columns="2" id="pbs" rendered="{!PA_Process__c.Master_Approval_Status__c !='Approved'}">
              <apex:outputfield value="{!PA_Process__c.JobNo__c}" />

              <apex:pageBlockSectionItem id="pj">
                  <apex:outputLabel value="Company" for="comp" />
                  <apex:panelGrid columns="2" >

                      <apex:outputfield value="{!PA_Process__c.Globecomm_Company__c}"  id="comp"/>
                  </apex:panelGrid>
              </apex:pageBlockSectionItem>

              <apex:pageBlockSectionItem id="pi">

                  <apex:outputLabel value="Proposal Number" for="proposalNumberFieldId" />
                 <apex:panelGrid columns="2" >
                     <apex:outputfield id="proposalNumberFieldId" value="{!PA_Process__c.PNumber__c}" /> 
                 </apex:panelGrid>
             </apex:pageBlockSectionItem>

             <apex:pageBlockSectionItem id="bu">
                 <apex:outputLabel value="Business Unit" for="buid" />
                 <apex:panelGrid columns="2" >
                     <apex:outputfield id="buid" value="{!PA_Process__c.BU__c}"  />
                 </apex:panelGrid>
             </apex:pageBlockSectionItem>


             <apex:outputfield id="customerNameFieldId" value="{!PA_Process__c.Customer_Name__c}" />

             <apex:outputfield id="description" value="{!PA_Process__c.Project_Description__c}"  style="width:300px; height:30px"/>
             <apex:outputfield value="{!PA_Process__c.Account_or_Sales_Manager__c}"/> 
             <apex:outputfield value="{!PA_Process__c.Special_Project_Requirement__c}"  style="width:300px; height:30px"/>
             <apex:outputfield value="{!PA_Process__c.Forecast_Lead__c}" />
             <apex:outputfield value="{!PA_Process__c.Contract_Price__c}"  id="ConPrice" label="Funded Amount"/>
             <apex:outputfield value="{!PA_Process__c.Product_Type__c}"  id="pt"/>
             <apex:outputfield value="{!PA_Process__c.Project_Mgr__c}" id="pmgr" label="Project Manager"/>
             <apex:outputfield value="{!PA_Process__c.Market_Vertical__c}"  id="mktvert"/>
             <apex:outputfield value="{!PA_Process__c.Project_Engineer__c}"   id="pegr" label="Project Engineer"/>
             <apex:inputHidden value="{!PA_Process__c.StandardStat__c}" />
             <apex:inputHidden value="{!PA_Process__c.UsageBBStat__c}" /> 
             <apex:inputHidden value="{!PA_Process__c.SimpleTranStat__c}"/>  
             <apex:inputHidden value="{!PA_Process__c.TerminateStat__c}"/>  
             <apex:inputHidden value="{!PA_Process__c.RenewStat__c}"/> 
             <apex:inputHidden value="{!PA_Process__c.DemoStat__c}"/>
             <apex:inputHidden value="{!PA_Process__c.RiskRelStat__c}"/>
             <apex:inputHidden value="{!PA_Process__c.CAPEXStat__c}"/>       
             <apex:inputHidden value="{!PA_Process__c.RDStat__c}"/>  
             <apex:inputHidden value="{!PA_Process__c.ChangeOrdStat__c}"/> 
             <apex:inputHidden id="proposalNameFieldId" value="{!PA_Process__c.Opportunity_Name__c}"/> 


         </apex:pageblocksection>

         <!--general info -->

         <apex:pageblocksection title="General Info" showheader="true" columns="2" id="pbs1" rendered="{!PA_Process__c.Master_Approval_Status__c =='Approved'}">
             <apex:outputfield value="{!PA_Process__c.JobNo__c}" />


             <apex:pageBlockSectionItem id="pj">
                 <apex:outputLabel value="Company" for="comp" />
                 <apex:panelGrid columns="2" >
                     <apex:outputfield value="{!PA_Process__c.Globecomm_Company__c}"  id="comp" styleClass="Error"/>
                 </apex:panelGrid>
             </apex:pageBlockSectionItem>

             <apex:pageBlockSectionItem id="pi">
                 <apex:outputLabel value="Proposal Number" for="proposalNumberFieldId" />
                 <apex:panelGrid columns="2" >
                     <apex:outputLabel id="proposalNumberFieldId" value="{!PA_Process__c.PNumber__c}"/> 

                 </apex:panelGrid>
             </apex:pageBlockSectionItem>

   <apex:pageBlockSectionItem id="bu">
<apex:outputLabel value="Business Unit" for="buid" />
     <apex:panelGrid columns="2" >
    <apex:outputLabel id="buid" value="{!PA_Process__c.BU__c}"/>
        </apex:panelGrid>
</apex:pageBlockSectionItem>


  <apex:outputfield id="customerNameFieldId" value="{!PA_Process__c.Customer_Name__c}"/>

                <apex:outputfield id="description" value="{!PA_Process__c.Project_Description__c}" style="width:300px; height:30px"/>
               <apex:outputfield value="{!PA_Process__c.Account_or_Sales_Manager__c}"/> 
                <apex:outputfield value="{!PA_Process__c.Special_Project_Requirement__c}" style="width:300px; height:30px"/>

                <apex:outputfield value="{!PA_Process__c.Forecast_Lead__c}" />
                <apex:outputfield value="{!PA_Process__c.Contract_Price__c}"  id="ConPrice" label="Funded Amount"/>
                <apex:outputfield value="{!PA_Process__c.Product_Type__c}" id="pt"/>
                <apex:outputfield value="{!PA_Process__c.Project_Mgr__c}"  id="pmgr" label="Project Manager"/>
                <apex:outputfield value="{!PA_Process__c.Market_Vertical__c}" id="mktvert"/>
                <apex:outputfield value="{!PA_Process__c.Project_Engineer__c}"   id="pegr" label="Project Engineer"/>
                <apex:inputHidden id="proposalNameFieldId" value="{!PA_Process__c.Opportunity_Name__c}"/> 
            </apex:pageblocksection>
           <apex:pageblocksection title="Contract Specific Data" showheader="true" columns="2" id="con">
            <apex:pageblocksectionitem >
            <apex:outputLabel value="Contract Type" for="CType" />

             <apex:panelGrid columns="3">

                <apex:outputField value="{!PA_Process__c.Contract_Type__c}" />

                                  </apex:panelGrid>
            </apex:pageblocksectionitem>

              <apex:outputfield value="{!PA_Process__c.IsContractAttached__c}" />

              <apex:pageBlockSectionItem id="ld">
               <apex:outputLabel value="Liq.Damages" for="liqDmgs">
              </apex:outputLabel>

              <apex:panelGrid columns="9">


             <!-- style="font-size:12;padding-left:130px;font-size:10;padding-right:13px;" -->

              <apex:outputfield id="liqDmgs" value="{!PA_Process__c.Liquidated_Damages__c}"  style="width:55px"/> <!-- ;padding-left:20px-->

               <apex:outputfield value="{!PA_Process__c.liq_dmgs_per__c}" style="width:35px"/>
                                 <apex:outputLabel value="per" for="cap-per"></apex:outputLabel>
                <apex:outputfield value="{!PA_Process__c.perLiquidatedDamages__c}"  id="cap-per"/> 
                 <apex:outputLabel value="upto" for="cap1"></apex:outputLabel>
             <apex:outputfield value="{!PA_Process__c.cap__c}"  style="width:35px;" id="cap1" />
                             </apex:panelGrid>
              </apex:pageBlockSectionItem>

           <apex:outputfield value="{!PA_Process__c.Is_Classified_Contract__c}"  label="Is Contract Classified"/>
           <apex:pageblocksectionitem >
            <apex:outputLabel value="Contract Description" for="condesc">
            </apex:outputLabel>

           <apex:panelGrid columns="3">

           <apex:outputfield id="condesc" value="{!PA_Process__c.Contract_description__c}"   style="width:300px; height:30px"/>

           </apex:panelGrid>
             </apex:pageBlockSectionItem>
            <!--    <apex:outputfield value="{!PA_Process__c.Contract_Review__c}" required="false"/> -->
            </apex:pageblocksection>

            <apex:pageblocksection title="Treasury Data" showheader="true" columns="2">
                <apex:outputfield value="{!PA_Process__c.GSA_Component__c}" />
                  <apex:pageBlockSectionItem id="ab">
     <apex:outputLabel value="Delivery Terms" for="terms"/> 

     <apex:panelGrid columns="3" >
       <apex:outputfield value="{!PA_Process__c.Delivery_Terms_IncoTerms__c}"  id="terms"/>  
                </apex:panelGrid>
</apex:pageBlockSectionItem>


                <apex:PageBlockSectionItem >
                <apex:outputLabel value="Finance Contact" for="fincont"/> 

                <apex:panelGrid columns="2">

                <apex:outputfield id="fincont" value="{!PA_Process__c.Finance_contact_email_address__c}" style="width:105px"/>
                </apex:panelGrid>
                </apex:pageBlockSectionItem>

                <apex:outputfield value="{!PA_Process__c.Payment_Terms__c}" />
                 <apex:pageBlockSectionItem >

                <apex:outputLabel value="Email" for="FinEmail"/>
                <apex:panelGrid columns="2">

                <apex:outputfield value="{!PA_Process__c.Finance_Email__c}"  id="FinEmail"/>

                </apex:panelGrid>
                 </apex:pageBlockSectionItem>
                 <apex:outputfield value="{!PA_Process__c.Lease_vs_Buy__c}"  rendered="false"/>
                <apex:outputfield value="{!PA_Process__c.Validation_of_Credit_Wortiness__c}" />
                          <apex:outputLabel value=""/>
                <apex:outputfield id="Custdep" value="{!PA_Process__c.Is_customer_deposit_required__c}"/>
                 <apex:outputLabel value=""></apex:outputLabel>
                  <apex:outputfield value="{!PA_Process__c.Is_warranty_bond_required__c}" />
                    <apex:outputLabel value=""/>
                <apex:outputfield value="{!PA_Process__c.Is_advance_gauranteed__c}" label="Bank Guarantee" />
            </apex:pageblocksection>
            <apex:pageblocksection id="comp" title="Compliance" showheader="true" columns="2">

                <apex:outputfield value="{!PA_Process__c.Country__c}"  id="Country"/>
               <apex:outputfield value="{!PA_Process__c.Other_Parties_Involved__c}"  style="width:300px;"/>
                <apex:outputfield value="{!PA_Process__c.Ultimate_End_Country__c}"/>
                 <apex:outputfield value="{!PA_Process__c.Is_an_export_license_required_by_Compli__c}"/>

       <apex:pageBlockSectionItem id="ab">
     <apex:outputLabel value="Anti Boycott Screening" for="AntiB"/> 

     <apex:panelGrid columns="3" >

      <apex:outputfield value="{!PA_Process__c.IsAntiBoycottScreening__c}"   id="AntiB" />

    </apex:panelGrid>
</apex:pageBlockSectionItem>


                <apex:pageBlockSectionItem >
                  <apex:outputLabel value="Screening(MK Denial)" for="mk1"/> 

                <apex:panelGrid columns="3">
                   <apex:outputfield value="{!PA_Process__c.Screening_MK_Denial__c}" id="mk1" />

                    </apex:panelGrid>
                  </apex:pageBlockSectionItem>
              <apex:pageBlockSectionItem > 
               <apex:outputLabel value="Will Hardware be shipped?" for="WillHW"/> 
                  <apex:panelGrid columns="3">
                  <apex:outputfield value="{!PA_Process__c.Will_Hardware_be_shipped__c}" id="WillHW" />
                                       </apex:panelGrid>
                  </apex:pageBlockSectionItem>


                   <apex:outputfield value="{!PA_Process__c.Screening_clearing_date__c}" id="mk2"/>

                <apex:pageBlockSectionItem > 
               <apex:outputLabel value="Services Data" for="Services"/> 
               <apex:panelGrid columns="3">
               <apex:outputfield value="{!PA_Process__c.Services_Technical_Data__c}" label="Services Data"  style="width:300px;" id="Services"/>
               </apex:panelGrid>
               </apex:pageBlockSectionItem>



                  <apex:pageBlockSectionItem > 
               <apex:outputLabel value="Equipment List ECCNs" for="ECCN"/> 
                <apex:panelGrid columns="3">

                   <apex:outputfield id="ECCN" value="{!PA_Process__c.Equipment_List_EECNs__c}"  style="width:300px;"/>
                   </apex:panelGrid>
                   </apex:pageBlockSectionItem> 

                    <apex:pageBlockSectionItem > 
               <apex:outputLabel value="Technical Data" for="tech"/> 
                <apex:panelGrid columns="3">



               <apex:outputfield id="tech" value="{!PA_Process__c.Technical_Data__c}"  style="width:300px;"/>
               </apex:panelGrid> 
                 </apex:pageBlockSectionItem>
               <apex:pageBlockSectionItem > 
               <apex:outputLabel value="End Use Details or form" for="enduse"/> 
                <apex:panelGrid columns="3">



            <apex:outputfield value="{!PA_Process__c.End_Use_Details_or_form__c}" id="enduse"  style="width:300px;"/>


                 </apex:panelGrid> 
                 </apex:pageBlockSectionItem>
             <apex:pageBlockSectionItem > 
               <apex:outputLabel value="Is WMD Involved?" for="WMD"/> 
                <apex:panelGrid columns="3">



      <apex:outputfield value="{!PA_Process__c.Is_WMD_Involved__c}" id="WMD" />
                            </apex:panelGrid> 
                 </apex:pageBlockSectionItem>

                              <apex:outputfield value="{!PA_Process__c.Military_End_Use__c}" />
               <apex:outputfield value="{!PA_Process__c.Confirm_against_Product_Matrix__c}" /> 
           <!--      <apex:outputfield value="{!PA_Process__c.Compliance_Review__c}" required="false"/> -->


            </apex:pageblocksection>
            <apex:pageblocksection title="Finance" showheader="true" columns="2" id="finance">
                <apex:outputfield value="{!PA_Process__c.Billing_Address__c}" /> <!-- required="true"/> -->
                <apex:outputfield value="{!PA_Process__c.Title_Transfer__c}" />
                <apex:outputfield value="{!PA_Process__c.Billing_Email__c}" />
                <apex:outputfield value="{!PA_Process__c.Gross_Margin__c}"  id="gm" />
                <apex:outputfield value="{!PA_Process__c.R_D_Component__c}" />
                <apex:outputfield value="{!PA_Process__c.Special_Billing_Rqmts__c}" />
                <apex:outputfield value="{!PA_Process__c.Invoicing_Start_Date__c}" />
                <apex:pageBlockSectionItem id="CAP">
     <apex:outputLabel value="CAPEX Requirement" for="CAPEX"/> 
     <apex:panelGrid columns="3" >
                <apex:outputfield id="CAPEX" value="{!PA_Process__c.CAPEX__c}"  label="CAPEX Requirement"/>
                 <apex:outputfield value="{!PA_Process__c.Capex_Value__c}" />
    </apex:panelGrid>
    </apex:pageBlockSectionItem> 
     <apex:outputfield value="{!PA_Process__c.Invoicing_Stop_date__c}"  />
                 <apex:pageBlockSectionItem id="tax_issue">
                  <apex:outputLabel value="Tax Issues" for="tax"/>
              <apex:panelGrid columns="2">

                 <apex:outputfield value="{!PA_Process__c.Tax_Issues__c}"  id="tax"/>
                                   </apex:panelGrid>
                </apex:pageBlockSectionItem>
                <apex:outputfield value="{!PA_Process__c.Freight_Amount__c}" />
                <apex:outputfield value="{!PA_Process__c.Is_Tax_Exempt__c}"  id="taxE" label="U.S. Sales Tax Exempt"/>
                <apex:outputfield value="{!PA_Process__c.Revenue_Recognition_Type__c}" />
                <apex:outputfield value="{!PA_Process__c.U_S_State__c}" />

                </apex:pageblocksection>
       </apex:outputpanel>

      </apex:pageBlock>     

      </apex:form>
 <center><br/>

</center><br/>

`

  • 2
    my general approach to this type of problem would be selective reduction - start with a minimum VF page that does work, then start adding in bits to see where it fails – cropredy Jul 2 '15 at 21:00
  • 1
    I once had the same problem, and I had to change a bit of my apex code. Can you share the apex code segment where you create the pdf attachment. – navD87 Jul 2 '15 at 21:27
1

The root of your problem could very well be that you're using Components That Are Unsafe to Use When Rendering as PDF such as <apex:outputfield>, <apex:pageBlock>, <apex:pageBlockSection>, <apex:pageBlockSectionItem>and <apex:form>. See Component Behavior When Rendered as PDF for more on components that are "Safe", ones to "Use with Caution", and "Unsafe Components" when rendering PDFs.

  • Thanks for response crmprogdev. Is there any equivalent control for <apex:pageBlock>,<apex:pageBlockSection>, <apex:pageBlockSectionItem>and <apex:form> that are safe for pdf rendering. I can understand that for <apex:outputfield> I can use <apex:outputText>. – user1585871 Jul 6 '15 at 13:50
  • You'd want to use standard HTML rather than apex components. You won't be able to use <apex:pageBlock>. You can redesign your page to break it up using <div> tags or putting the content inside of <table> tags. <apex:outputText> works well with wrapper classes and repeats. If this answer resolves your issue, please help the rest of the community by marking it as having answered your question. – crmprogdev Jul 6 '15 at 14:04
  • For some help refer to developer.salesforce.com/docs/atlas.en-us.salesforce1.meta/… – user1585871 Jul 6 '15 at 14:19
  • The problem is, in the example they cite, they use <apex:form>, a tag not safe for use with PDF's. One has to be very careful composing pages intended for output as PDF's. Wherever possible, it's safest to stick with HTML. – crmprogdev Jul 6 '15 at 14:25

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.