You need to sign in to do that
Don't have an account?
invalid pdf error for email with pdf attachment
Hi,
I have a requirement to generate a pdf and send a email with thsi pdf attachments.
The pdf is generated and attached and email is sent.
when i login as system admin : pdf generated opens in adobe / nitro pdf
for other profiles > email is sent with attachments but pdf attachment doesnt open in pdf , it says invalid pdf file...
whats the problem...
The profile has access to the page which is rendered as pdf.
PageReference pdf = Page.PdfGenerator;
pdf.getParameters().put('id',objectId);
pdf.setRedirect(true);
// The contents of the attachment from the pdf stored as a Blob
Blob body;
try
{
// Get contents of the attachment from the pdf
body = pdf.getContent();
}
catch (VisualforceException e)
{
body = Blob.valueOf('Encountered VF exception');
}
system.debug(' body of pdf content ' + body);
//Generating a Email PDF attachment
Messaging.EmailFileAttachment PDFAttachFile = new Messaging.EmailFileAttachment();
PDFAttachFile.setContentType('application/pdf');
PDFAttachFile.setFileName('test.pdf');
PDFAttachFile.setInline(false);
PDFAttachFile.Body = body;
// Construct the email envelope
OrgWideEmailAddress[] orgemail = [select Id,Address from OrgWideEmailAddress where Address = 'some email' limit 1];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setUseSignature(false);
if ( orgemail.size() > 0 )
{
mail.setOrgWideEmailAddressId(some id);
}
mail.setToAddresses(new String[]{toEmailAddr });
mail.setSubject('hi 123' );
mail.setHtmlBody('Hi ');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { PDFAttachFile });
// Send the mail with Attachment
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail});
why oher profiles other than system admin cant generate a proper pdf?
plz urgent requirement...........................
Hi Anup ,
Try using
Blob body;
try {
body = pdf.getContentAsPDF();
}
catch (VisualforceException e) {
body = Blob.valueOf('No content in PDF');
}
Let me know if it helps you !!!
Thanks