• amr_i_m
  • NEWBIE
  • 5 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

I wrote a code  generating an e-mail with a PDF attachment. I checked the code through the IDE (Eclipse) and all works fine.

Running the same code but using a button in a VisualForce page to activate the method  I received "PDF generation failed. Check the page markup is valid. " message.

The IDE code and the CommandButton code call the same method send().

If instead of getContentAsPDF I use only getContent the Command button works OK.


Following is the code 

 

         }  

    public void send() {

        // Define the email

         Messaging.SingleEmailMessage  email = new Messaging.SingleEmailMessage();   

         Messaging.EmailFileAttachment EFA = new Messaging.EmailFileAttachment();

              if (SP.SPEmail__c!= null)

        {

//         toaddresses = new String []{SP.SPEmail__c};

//        String[] CCaddresses ='gustavo@hotmail.com';

       

        }

        PageReference newPage = new PageReference(QuotaLetter);

        Blob blobFormPDF = null;

            system.debug('******LLEGUE******');

       if (!Test.isRunningTest()){//unable to call .getContent() within tests

            blobFormPDF = newPage.getContentAsPDF();

        } 

        //String[] toAddresses = addresses.split(':', 0);

        // Sets the paramaters of the email

        email.setReplyTo(replyto);

        email.setSubject( subject );

        email.setToAddresses( toaddresses );

        email.setCcAddresses (ccaddresses);       

 //       email.setToAddresses(new String[] { EMAIL_ADDRESS });

 //     email.setPlainTextBody( body );

        email.setPlainTextBody( 'This is the message body' );

//      Set the Attachment

        EFA.setFileName(FileName);

        EFA.setBody(blobFormPDF);

        email.setFileAttachments(new Messaging.EmailFileAttachment[]{EFA});

        // Sends the email

        Messaging.SendEmailResult [] r =

        Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});

       if (r[0].isSuccess()==True){

         estado_del_email='Sent';

         system.debug('****SENT*****');

 

Next is the code used in the IDE

 

            Public sendEmail SE=new sendEmail();

  SE.replyto = 'gustavopipman@hotmail.com';

    SE.toaddresses.add( 'gustavopipman@hotmail.com');

    SE.ccaddresses.add('gustavopipman@hotmail.com');

    SE.subject = 'Gustavo Pipman Quota Letter 2012';

    SE.FileName= 'Gustavo Pipman Quota Letter 2012';

    SE.QuotaLetter = 'https://c.na7.visual.force.com/apex/Sale_People_Letter?id=a01A0000008tEJ3';

SE.send();

 

And finnally is the code belonging to the action of the commandbutton

 

   

     Public void sendemail(){

    SalesPeople = [select name from Sale_Manager__c where name = :SMN];

    SE.replyto = 'gustavopipman@hotmail.com';

    SE.toaddresses.add( 'gustavopipman@hotmail.com');

    SE.ccaddresses.add('gustavopipman@hotmail.com');

    SE.subject = 'Gustavo Pipman Quota Letter 2012';

    SE.FileName= 'Gustavo Pipman Quota Letter 2012';

    SE.QuotaLetter = 'https://c.na7.visual.force.com/apex/Sale_People_Letter?id=a01A0000008tEJ3';

    SE.send();

    update SalesPeople ;

 

I also add the Page code with commandButton

 

</apex:page>

<apex:page controller="SalesPeopleMethods"   title="SPsetinfo" action="{!SPsetinfo}" sidebar="False">

    <apex:form >

               <apex:pageBlock >

<table border ='2' width='250' height='100'>

<tr> <th width='70%' height='70'>Food</th>

<th>Drink</th> <th>Sweet</th></tr>

<tr> <td>A</td> <td>B</td> <td>C</td></tr>

</table>

                     <apex:dataTable value="{!SalesPList}" var="b"   columns="2" width="200px"

                     columnsWidth="90px,10px">

                           <apex:column headerValue="Name" width="95%">   

                            <apex:outputField value="{!b.name}"/>

            </apex:column>  

                           <apex:column headerValue="Earning" width="5%" >   

                            <apex:inputField value="{!b.Earning_Commission__c}"/>

            </apex:column>   

                          <apex:column headerValue="send Email" width="5%" >   

                            <apex:commandLink action="{!sendemail}" >

                            <apex:param name="SMN"  value="{!b.name}" assignTo="{!SMN}"/>

                            <apex:commandButton value="email to {!b.name}"/>

                </apex:commandLink>

            </apex:column>   

           </apex:dataTable>

              </apex:pageBlock>

       </apex:form>

 

  

 

 I have a program feature that generates PDF documents via the standard Visual Force 'renderAs="PDF"' mechanism. This feature does not work reliably for 'larger' documents (i.e. 50 pages). By 'reliably' I mean that I can run PDF generation 10 times, and it will work successfully 3-5 times out of these 10. The rest of the time, after a 3+ min delay, I get the following error message:

"PDF generation couldn't complete because the request took too long. You are using components that are not fully supported by PDF generation, please consult the documentation for a list of unsupported components."

I've reviewed the page (it's a long and ugly beast, so am not posting it here), but am not seeing anything unsupported or suspicious.  This test can be run on the exact same object, with the exact same data, 10 times in a row, and the results are non-deterministic.   The fact that it works for some runs, but not others makes me suspect that this doesn't have to do with any specific page markup, but I could be wrong.

When I look at the system log output, I see that the controller code for this page is done after 12-15 sec. After that, there's a long delay--when the PDF is rendered successfully, the delay is about 30-40 sec. When it fails, as above, it is 3+ min.

It appears that something is making the PDF rendering engine go haywire, but I have not been able to figure out what it may be, and therefore, how to work around it.

If you have the system log open, you can see that the last statement from the controller (CODE_UNIT_FINISHED|StaticResourcePick <init>) is usually executed a long time before the CUMULATIVE_LIMIT_USAGE line. 

 

 

Does anyone have any ideas/suggestions?

hi,

 

we have an arabic client and try to generate a document with both english and arabic content. in our browsers, we can see both languages, however the generated PDF only contains the english content, whereas the arabic content is empty.

 

this happens in both cases, when using arabic text directly (copy paste from a text editor) or when converting the arabic text first to html entities.

 

 

 

is arabic not supported or do we have to instruct the renderer in some special way to support arabic?


 






<apex:page renderAs="PDF">

<head>
<style type="text/css">
@page {
size: 21.0cm 29.7cm;
margin-top: 2.0cm;
margin-left: 0cm;
margin-right: 1.5cm;
margin-bottom: 2cm;
}
</style>
</head>

<body>

Copy paste:<br/>
غير ذلك(الرجاء التوضيح)

<br/><br/>
HTML Entities:<br/>
&#1594;&#1610;&#1585;&#1584;&#1604;&#1603;

</body>
</apex:page>



 

  • March 24, 2009
  • Like
  • 0