cancel
Showing results for 
Search instead for 
Did you mean: 

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

omakinen
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

kammaje_cis
Active Contributor

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. 🙂

omakinen
Participant
0 Kudos

Thanks Krishna! This sounds very promising. I'd like to understand it a bit better.

- Do we still need two entities, one for data and one for the attachment? And we must link them via Association (1...N)?

- The instance attribute in the CREATE_ENTITY method. How does one store/read the request body there?

- Are there any examples for creating an ajax batch request?

It would be great if you could even write a short blog about this method! 🙂

-Ossi

kammaje_cis
Active Contributor

- Number of Entities depends.

If your attachment entity can handle all the data, then you just require one. I required multiple entities to handle data. It was a deep create with header and items. (For PR). No association required between data entity and attachment entity. This is because you are issuing two separate calls within the batch call.

Sure, I will publish a blog soon. 🙂

omakinen
Participant
0 Kudos

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

0 Kudos

have you done something submitting pdf as well as data with CREATE_DEEP_ENTITY.?

0 Kudos

HI Ossi,

Were you able to arrive at a solution. If you could post an example that would be great.

Thanks

Former Member
0 Kudos

Hi Ossi,

Please check the below link.

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

Regards

Madhu

omakinen
Participant
0 Kudos

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