Form submission and generate pdf in AEM as cloud service | Community
Skip to main content
Level 4
November 27, 2024
Solved

Form submission and generate pdf in AEM as cloud service

  • November 27, 2024
  • 3 replies
  • 1295 views



HI Team,
We have a requirement to update an HTML form, and upon submission, a PDF needs to be generated based on the form values. I have tried uploading the PDF to AEM DAM and was able to read the field values, but I am unable to update the PDF in AEM.

Which is the best approach to develop this feature ,


AEM as CS version 

Thanks in advance

Best answer by georhe6

I was able to achieve this using itextpdf api, by passing the rendition of the pdf. 

3 replies

narendiran_ravi
Level 6
November 27, 2024

Leveraging AEM Forms Add-On for PDF Generation

The AEM Forms Add-On provides built-in services and workflows to convert form data into PDFs effectively. If you plan to implement a custom solution, here are key considerations and steps:

Key Considerations for Custom Implementation in AEM

  •  Identify where the submitted form data is currently stored. CRX or external DB.
  • Handling Anonymous and Logged-In Users if the data is stored in CRX
    • For anonymous users:
      • Store the data under:
        /content/formname-data/anonymous/{submissionID}
    • For logged-in users:
      • Store the data under:
        /content/formname-data/{userID}/{submissionID}
  • You can create a component to configure the template for the PDF(e.g., headers, footers, body sections). This way we can reuse this for any other forms.
  • Create a service to generate PDFs dynamically from stored form data.
georhe6Author
Level 4
November 27, 2024

Customer is not planning to purchase AEM forms 

A_H_M_Imrul
Community Advisor
Community Advisor
November 27, 2024

Hello @georhe6 ,

Instead of updating the pdf can't we generate the pdf using some library like (itextpdf) based on the submitted data? 

Thanks

georhe6Author
Level 4
November 27, 2024

Thanks @a_h_m_imrul ,
Currently, the PDF  form contains certain predefined values, such as images and generic text. We have decided to use the PDF as a template and populate it with dynamic values using the iTextPDF API.

anupampat
Community Advisor
Community Advisor
November 28, 2024

Hi @georhe6 ,

 

Updating a pdf programmatically means you will have to rely on Java libraries which can do them, refer - https://www.nutrient.io/blog/programmatically-editing-a-pdf-using-java . But they may be limited to some actions and may not fulfill what you are trying to achieve. 

I would recommend on creatin a new PDF every time a form is edited and delete the existing one, this of-course depends on how you create the naming of the pdf file. E.g. if its a customer form, I will create the pdf file based on firstName_lastname_randomId and then replace it when the values are updated .

 

Regards,

Anupam Patra

georhe6AuthorAccepted solution
Level 4
November 29, 2024

I was able to achieve this using itextpdf api, by passing the rendition of the pdf.