Skip to Content

Send data to Backend, Generate PDF and return it to UI?

Hi guys!

Is this scenario possible? First fill UI5 form, make a call to backend using the data from UI, generate a PDF file and then return it to the UI right away and display it inline?

The examples that I have seen are uploading or saving data to backend first using CREATE/CREATE_STREAM methods and then make another call to read it back again using READ/GET_STREAM methods. Some minimal key is passed along using slug and it's used to read the file from some table or so.

However, I would like to skip the saving part completely if possible. Just pass the data, generate a PDF and return it to UI in one go. Can this be done?

thanks!
Ossi

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • May 04, 2017 at 03:53 AM

    Yes, I have achieved it. This is how.

    1. Use a batch request from UI to send a POST (PDF data) request as well as GET ($value - actual PDF)

    2. In the CREATE_ENTITY method or CREATE_DEEP_ENTITY method (based on your PDF request body), store the request body (PDF data) as an instance attribute (custom) of your DPC_EXT class.

    3. In the GET_STREAM method, you will have access to above instance attribute. With this data create a PDF (using Smartform) and return.

    Note: You have to use a $ajax call for the batch call. This is because regular batch call will fail to parse the response (pdf data).

    Let me know how it went. :)

    Add comment
    10|10000 characters needed characters exceeded

    • Ossi Makinen Krishna Kishor Kammaje

      Thanks Krishna!

      Ok, I think we better have two entities because we have some 20 fields which are needed in order to generate the PDF.

      However, if we would use only one entity for everything, would the Entity's Media-flag be set (because we have binary data within the entity too)?

      It would be really awesome if you can publish an example blog! :)

      br, Ossi

  • avatar image
    Former Member
    May 03, 2017 at 04:03 PM

    Hi Ossi,

    Please check the below link.

    http://www.inkyourcode.com/how-to-generate-pdf-file-in-sapui5/

    Regards

    Madhu

    Add comment
    10|10000 characters needed characters exceeded

    • Thank you for the tip! I have stumbled on the jsPDF before. However, it won't serve us perfectly because we have to do some more data checking and retrieval in the backend before the PDF generation. That's why the PDF should be created in the backend.

      -Ossi