You need to sign in to do that
Don't have an account?
Issue when generating PDF as Site Guest User
Page code:
<apex:page renderAs="pdf">
<h1>TestPdfPage</h1>
</apex:page>
Page URL:
http://wsdev-cityoftoronto.cs41.force.com/TestPdfPage
You can open the page without login
Let’s try to attach the page to email and send it
We will try to send as Sys Admin and Site Guest User
Code:
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
PageReference pdf = Page.TestPdfPage;
pdf.setRedirect(true);
Blob b = pdf.getContent();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('TestPage.pdf');
efa.setBody(b);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
List<String> adresses= new List<String>();
adresses.add('vsenko11@gmail.com');
email.setToAddresses(adresses);
String body= 'Test Body';
email.setSubject('Test Subject');
email.setHtmlBody(body);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mails.Add(email);
Messaging.sendEmail(mails);
When sending as Sys Admin, all Ok
If we do the same as Site Guest User got error when opening PDF
If open in NotePad first file is Ok but second is appears as HTML file.
<apex:page renderAs="pdf">
<h1>TestPdfPage</h1>
</apex:page>
Page URL:
http://wsdev-cityoftoronto.cs41.force.com/TestPdfPage
You can open the page without login
Let’s try to attach the page to email and send it
We will try to send as Sys Admin and Site Guest User
Code:
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
PageReference pdf = Page.TestPdfPage;
pdf.setRedirect(true);
Blob b = pdf.getContent();
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('TestPage.pdf');
efa.setBody(b);
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
List<String> adresses= new List<String>();
adresses.add('vsenko11@gmail.com');
email.setToAddresses(adresses);
String body= 'Test Body';
email.setSubject('Test Subject');
email.setHtmlBody(body);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
mails.Add(email);
Messaging.sendEmail(mails);
When sending as Sys Admin, all Ok
If we do the same as Site Guest User got error when opening PDF
If open in NotePad first file is Ok but second is appears as HTML file.