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
Suman Macha 8Suman Macha 8 

Generate PDF from the data collected with in LWC without saving data to database

Hi,
We have business requirement where we have a community, using lightning web components we have developed few forms where we are collecting data from users, at the end of this process on submitting the form, we would need to generate a pdf using the data collected on LWC without storing it database. I'm looking for possible ways to acheive this. Any help is greatly appreciated. Thank you!
ANUTEJANUTEJ (Salesforce Developers) 
Hi Suman,

>> http://santanuboral.blogspot.com/2020/10/lwc-generate-pdf.html

The above link has an implementation that accepts data and generated pdf. Can you please have a look.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Gabriel LinusGabriel Linus
Hello Suman,

Generating a PDF in Lightning Web Components (LWC) without storing the data in a database can be achieved using various methods. Here's one approach to consider, especially when you have developed forms in your LWC to collect user data:
  • Create a Visualforce Page: Create a Visualforce page with the renderAs "pdf" attribute. This attribute tells Salesforce to render the page as a PDF.
  • Develop an Apex Controller: Create an Apex controller for your Visualforce page. This controller will be responsible for receiving and processing the user input data from your LWC.
  • Collect User Input Data in JavaScript: In your Lightning Web Component, use JavaScript to collect and store the user input data as needed. You can gather this data from the forms you've developed in your LWC.
  • Send Data to Apex on Form Submission: Upon user submission of the form within your LWC, transmit the collected data to your Apex controller through an Apex callout.
  • Integrate Visualforce and LWC: Inside your LWC, invoke the Visualforce page and transmit user data as parameters. You can accomplish this by calling the Visualforce page from your LWC controller.
  • Create an Attachment: Within your LWC's Apex controller, employ page referencing of the Visualforce page. Retrieve the PDF content from the Visualforce page and subsequently set this content as the body of an attachment.
  • Render and Download the PDF: When the Visualforce page is accessed, it will render the PDF content utilizing the user data. This PDF document can be attached to the "Notes & Attachments" object, making it available for download.
This process enables you to dynamically generate PDFs in response to user interactions within your LWC.

In addition to this approach, if you're seeking alternative methods to generate PDFs in Salesforce, I recommend visiting the article at https://arrify.com/generate-pdf-in-salesforce/. This resource provides a variety of techniques for generating PDFs in Salesforce, which include utilizing Visualforce pages, harnessing Lightning Web Components (LWC) with Apex, and integrating third-party applications.