Skip to content

Instantly share code, notes, and snippets.

@toanshulverma
Created December 1, 2018 23:07
Show Gist options
  • Save toanshulverma/efda6b9fab1ae900b11da97218a80961 to your computer and use it in GitHub Desktop.
Save toanshulverma/efda6b9fab1ae900b11da97218a80961 to your computer and use it in GitHub Desktop.
Generates and Downloads PDF
<apex:page showHeader="false" standardController="Account">
File is being downloaded. If it doesn't download, <a href="/apex/PDFTestPage" id="lnkDownload" target="_blank" download="PDFTest.pdf" onload="auto_download();">click here</a> to download file.
<script>
function auto_download(){
document.getElementById('lnkDownload').click();
};
//trigger auto-download
window.setTimeout(auto_download, 10);
</script>
</apex:page>
@SarahNicewander
Copy link

Hi Anshul, I got this to work (mostly) however I keep getting a PDF error that it can't generate the PDF because it's corrupt. I'm not sure if there is something further I need to edit in the code to pull the current record or if my Adobe is causing problems.

@toanshulverma
Copy link
Author

Hi Anshul, I got this to work (mostly) however I keep getting a PDF error that it can't generate the PDF because it's corrupt. I'm not sure if there is something further I need to edit in the code to pull the current record or if my Adobe is causing problems.

@SarahNicewander I would suggest to first test the PDF generation with dummy data. Technically, PDF generation in this solution just works as a regular VF based PDF generation capability. The key trick is to get the data passed from lightning to Visualforce context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment