function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankit Arora 30Ankit Arora 30 

VF page to PDF to Notes & Attachments

I want to convert VF to PDF and then save it to Notes and attachments and below are the VF pages and apex class.

When I run the process, a pdf is created successfully at the right location under the application's notes and attachments but its blank. When I "login to community as a user", again the same vf page is blank but when I create a custom link of vf page in Application object, I can see the entire letter in pdf. Before putting the extension and action tag, I was able to see the same page from the custom link and from "login to community as a user". Can you please tell me what I am doing wrong, why its showing blank page.
Also VF page render the output dynamically, its not a static page. I have added VF pages and Apex classes to the community profile.
Please help me.

1st Visualforce Page:
<apex:page standardcontroller="Application__c" extensions="attachPDFToApplication" action="{!attachPDF}" standardStylesheets="false" showHeader="false" applyHtmlTag="false" applyBodyTag="false" docType="html-5.0" >
<apex:include pageName="DecisionLetter_V2"/>

2nd Visualforce Page:
<apex:page renderAs="pdf"> </apex:page>

Apex Class:
public class attachPDFToApplication {

public attachPDFToApplication(ApexPages.StandardController standardPageController) {
    }
 
public void attachPDF() {
PageReference pdfPage = Page.DecisionLetter_V2;
Attachment attach = new Attachment();
Blob pdfBlob;
      try {
             pdfBlob = pdfPage.getContent();
           }
       catch (VisualforceException e) {
             pdfBlob = Blob.valueOf('Some Text');
           }
                
attach.parentId = ApexPages.currentPage().getParameters().get('id');
attach.Name = 'DecisionLetter - '+ system.Now() + ' .pdf';
attach.body = pdfBlob;
insert attach;
    }
}


Thank you

Regards,
Ankit
Ankit Arora 30Ankit Arora 30
Need Help !!