You can save the pdf as attachemet not in the folder instead save it on database as follows,
public class attachPDFToAccount {
private final Account a; //Account object
//constructor
public attachPDFToAccount(ApexPages.StandardController standardPageController) {
a = (Account)standardPageController.getRecord(); //instantiate the Account object for the current record
}
//method called from the Visualforce's action attribute
public PageReference attachPDF() {
//generate and attach the PDF document
PageReference pdfPage = Page.pdfDemo; //create a page reference to our pdfDemo Visualforce page, which was created from the post http://www.interactiveties.com/blog/2015/render-visualforce-pdf.php
Blob pdfBlob = pdfPage.getContent(); //get the output of the page, as displayed to a user in a browser
Attachment attach = new Attachment(parentId = a.Id, Name = 'pdfAttachmentDemo.pdf', body = pdfBlob); //create the attachment object
insert attach; //insert the attachment
//redirect the user
PageReference pageWhereWeWantToGo = new ApexPages.StandardController(a).view(); //we want to redirect the User back to the Account detail page
pageWhereWeWantToGo.setRedirect(true); //indicate that the redirect should be performed on the client side
return pageWhereWeWantToGo; //send the User on their way
}
}
<apex:page action="{!attachPDF}" extensions="attachPDFToAccount" standardController="Account">
<!--
Created by: Greg Hacic
Last Update: 7 August 2015 by Greg Hacic
Questions?: greg@interactiveties.com
Notes:
- Visualforce page for creating a PDF file and attaching to Account
-->
<apex:pageMessages></apex:pageMessages><!-- included for display of errors should they occur -->
<apex:detail inlineEdit="true" relatedList="true"></apex:detail> <!-- included so Account detail information is visible when errors occur -->
</apex:page>
This will save the pdf as attachement.
If this helps you please mark it as the best answer so it could help the community in many ways.
This will save the pdf as attachement.
If this helps you please mark it as the best answer so it could help the community in many ways.