+ Start a Discussion
EyalEyal 

Sending PDF files to clients

Hello,

 

We are currently sending our invoices on email based format only with a custom HTML template which is merged with the relevant opportunity. This invoices are sent automatically once the client pays.

 

Many times our clients ask for a PDF attachment for their records.

 

Unfortunately, I haven't found any way to setup a PDF in apex and attach it to the invoice.

 

Is there any way to do so with apex ?

 

I would appreciate any leads or ideas on how to proceed with this issue

 

Thanks a lot,

 

Eyal

 

 

venkatyadavvenkatyadav
<apex:page renderas="pdf">
<html>
  <head> 
    <style> body { font-family: Arial Unicode MS; } </style> 
  </head>
  This page is rendered as a PDF
</html>
</apex:page>
 
 
try this code may its help to u
Navatar_DbSupNavatar_DbSup

Hi,


You can set the attachment type in your send email code
Use the below Cade as reference:
----------- Vf page---------------
<apex:page controller="PdfEmailController">
<apex:sectionHeader title="PDF Example" subtitle="Email a PDF"
description="Example of how to email a dynamically generated PDF."/>

<apex:form >
<apex:pageMessages />
<apex:pageBlock title="PDF Input">

<apex:pageBlockButtons >
<apex:commandButton action="{!sendPdf}" value="Send PDF"/>
</apex:pageBlockButtons>

<apex:pageBlockSection >

<apex:pageBlockSectionItem >
<apex:outputLabel value="Email to send to" for="email"/>
<apex:inputText value="{!email}" id="email"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="Account" for="account"/>
<apex:selectList value="{!accountId}" id="account" size="1">
<apex:selectOptions value="{!accounts}"/>
</apex:selectList>
</apex:pageBlockSectionItem>

</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>

</apex:page>


----------------Apex Class ------------------

public with sharing class PdfEmailController {

public ID accountId {get;set;}
public String email {get;set;}

public List<SelectOption> accounts {
get {
if (accounts == null) {
accounts = new List<SelectOption>();
accounts.add(new SelectOption('0017000000LgRMb','United Oil & Gas Corp.'));
accounts.add(new SelectOption('0017000000LgRMV','Burlington Textiles Corp of America'));
}
return accounts;
}
set;
}

public PageReference sendPdf() {

PageReference pdf = Page.PdfGeneratorTemplate;
// add parent id to the parameters for standardcontroller
pdf.getParameters().put('id',accountId);

// 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');
}

Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('testPdf.pdf');
attach.setInline(false);
attach.Body = body;

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setUseSignature(false);
mail.setToAddresses(new String[] { email });
mail.setSubject('PDF Email Demo');
mail.setHtmlBody('Here is the email you requested! Check the attachment!');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });

// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+email));

return null;

}

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

venkatyadavvenkatyadav

its follw some governer limits

 The maximum response size when creating a PDF must be below 15 MB, before being rendered as a PDF. This is the standard limit for all Visualforce requests.

The maximum file size for a generated PDF is 60 MB.

The total size of all images included in a generated PDF is 30 MB.

venkatyadavvenkatyadav

its follw some governer limits

 The maximum response size when creating a PDF must be below 15 MB, before being rendered as a PDF. This is the standard limit for all Visualforce requests.

The maximum file size for a generated PDF is 60 MB.

The total size of all images included in a generated PDF is 30 MB.

EyalEyal

Thanks,

 

I am nut sure I understand.

 

I am not using  a VF page.

 

I want to send via my apex trigger an email that contains a PDF attachment of the invoice that  is sent  to the client ( i.e the email content but in PDF )

 

How do I do that ?

 

Eyal