Some time back I posted a solution to generate PDF from Lightning components using in-memory data.
Post url: http://www.vermanshul.com/2017/07/lightning-generate-pdf-from-lightning.html
It was developed for a specific scenario, wherein we need to generate PDF where:
However, I realize that there are still lack of solutions (or maybe my search skills are downgrading) to generate and automatically download PDF document from Lightning Experience, without using any lightning components, wherein data exists within Salesforce. You can use the earlier solution in that case, but it will be an overkill.
There are various solutions available to generate PDF from javascript. But, I still think the plain old method of converting HTML to PDF (via visualforce PDF generation utility provided by Salesforce) is a better solution, due to sheer control over the end result.
So, I ended up creating another quick solution to generate PDF documents from Salesforce.
This simple solution entails adding a custom action to an object and embedding the button within object view.
Steps:
Code:
Steps:
Code:
Post url: http://www.vermanshul.com/2017/07/lightning-generate-pdf-from-lightning.html
It was developed for a specific scenario, wherein we need to generate PDF where:
- User interface is Salesforce classic
- Initiated via Lightning Component
- Data doesn't exist within Salesforce and is completely in-memory
However, I realize that there are still lack of solutions (or maybe my search skills are downgrading) to generate and automatically download PDF document from Lightning Experience, without using any lightning components, wherein data exists within Salesforce. You can use the earlier solution in that case, but it will be an overkill.
There are various solutions available to generate PDF from javascript. But, I still think the plain old method of converting HTML to PDF (via visualforce PDF generation utility provided by Salesforce) is a better solution, due to sheer control over the end result.
So, I ended up creating another quick solution to generate PDF documents from Salesforce.
Generate PDF within Lightning Experience with Salesforce Data
This simple solution entails adding a custom action to an object and embedding the button within object view.
Steps:
- Create a visualforce page with page attribute renderas = "pdf" (sample code below)
- Add a Quick Action "Generate PDF" for required object:
- Action Type: Visualforce
- Visualforce Page: GeneratePDF.page
- Go to Lightning App builder to add the action to detail view of Object
Code:
Automatically download PDF from Lightning Experience
Now, the above solution does allow you to generate PDF. However, it's not a good user experience. Wouldn't it be better, if the PDF is automatically downloaded with a defined name.Steps:
- Create new page to initiate PDF page download (code below)
- Modify quick action "Generate PDF" created in previous step and set Visualforce page to DownloadPDF.page
Code:
I can't see the source code. Can you share it with me please?
ReplyDeleteYou can find code on github (link below)
Deletehttps://gist.github.com/toanshulverma/efda6b9fab1ae900b11da97218a80961
Thank you
ReplyDeleteGracias
ReplyDeleteHi Anshul, great post! Do you have any idea why the default "Save" button is disabled/how to enable it? I see it is in your screenshots as well. We'd prefer for our users to save rather than automatically download. Thanks very much!
ReplyDeleteHi Ro, that will need customization to code. The code sample shared eas designed to automatically open or download the pdf.
Delete