You need to sign in to do that
Don't have an account?
Bertrand DB
Lightning component: save a generated PDF as File/Attachment
Hello,
I have a Lightning component on my opportunity page that does the following:
-> My issue is: how to save the PDF generated by the Visualforce page, and attach it to the Opportunity?
Any ideas?
demoModal.cmp:
monpdf.vfp:
demoModalController.js
I have a Lightning component on my opportunity page that does the following:
- When clicking on the button, it opens a Lightning modal box
- This modal box display a Visualforce page, renderas PDF, inside an iframe.
- I have two button bellow: Cancel, Save
-> My issue is: how to save the PDF generated by the Visualforce page, and attach it to the Opportunity?
Any ideas?
demoModal.cmp:
<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global"> <!--use boolean attribute for Store true/false value, make default to "false" so modal box are not display on the load of component. --> <aura:attribute name="recordId" type="Id" /> <aura:attribute name="isOpen" type="boolean" default="false"/> <!--Use "slds-m-around- -xx-large" class to add standard Large padding to the component--> <div class="slds-m-around--xx-large"> <button class="slds-button slds-button--brand" onclick="{!c.openModel}">Create a document</button> <!--Use aura:if tag to display Model Box, on the bese of conditions. [isOpen boolean attribute] --> <aura:if isTrue="{!v.isOpen}"> <!--###### MODAL BOX Start From Here ######--> <div role="dialog" tabindex="-1" aria-labelledby="header99" class="slds-modal slds-fade-in-open "> <div class="slds-modal__container"> <!-- ###### MODAL BOX HEADER Part Start From Here ######--> <div class="slds-modal__header"> <button class="slds-button slds-modal__close slds-button--icon-inverse" title="Close" onclick="{!c.closeModel}"> X <span class="slds-assistive-text">Close</span> </button> <h2 id="header99" class="slds-text-heading--medium">Your document</h2> </div> <!--###### MODAL BOX BODY Part Start From Here ######--> <iframe src="{! '/apex/monpdf?Id='+v.recordId}" width="100%" height="500px;" frameBorder="0"/> <div class="slds-modal__content slds-p-around--medium"> <p><b>Some random text. </b> </p> </div> <!--###### MODAL BOX FOOTER Part Start From Here ######--> <div class="slds-modal__footer"> <button class="slds-button slds-button--neutral" onclick="{!c.closeModel}" >Cancel</button> <button class="slds-button slds-button--brand" onclick="{!c.savenClose}">Save the document</button> </div> </div> </div> <div class="slds-backdrop slds-backdrop--open"></div> <!--###### MODAL BOX Part END Here ######--> </aura:if> </div> </aura:component>
monpdf.vfp:
<apex:page standardController="Opportunity" showHeader="false" renderAs="pdf"> {!Opportunity.Account.Name} </apex:page>
demoModalController.js
({ openModel: function(component, event, helper) { // for Display Model,set the "isOpen" attribute to "true" component.set("v.isOpen", true); }, closeModel: function(component, event, helper) { // for Hide/Close Model,set the "isOpen" attribute to "Fasle" component.set("v.isOpen", false); }, savenClose: function(component, event, helper) { // Display alert message on the click on the button from Model Footer alert('It works'); component.set("v.isOpen", false); }, })
I created one vf page that renders a PDF
I am just showing opportunity name in PDF. Here is the controller for vf page -
Now i created one lightning component which has only one save button , on click of this button , it will create same pdf and attach it to an account
Let me know if this solution makes sense to your problem.
All Answers
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_System_PageReference_getContent.htm
You can get the content of vf page and create an attachment on opportunity with this
I created one vf page that renders a PDF
I am just showing opportunity name in PDF. Here is the controller for vf page -
Now i created one lightning component which has only one save button , on click of this button , it will create same pdf and attach it to an account
Let me know if this solution makes sense to your problem.
How should I replace the hard-coded id here?
The id in these two lines:
And
Should actually be the something like "apexpages.currentpage().getparameters().get('id');" ?
you can receive it in apex controller -
Thanks.
I am trying to create this on a custom object as it is on the Quote object. I have already created vf page which generates the pdf. But I am not able to create those buttons and save it as an attachment to that custom object. Please advise on this.