Skip to Content
0

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

May 03, 2017 at 06:37 AM

240

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Krishna Kishor Kammaje
May 04, 2017 at 03:53 AM
1

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. :)

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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

0

- 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. :)

1
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

0
Madhusudhan S May 03, 2017 at 04:03 PM
0

Hi Ossi,

Please check the below link.

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

Regards

Madhu

Show 1 Share
10 |10000 characters needed characters left 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

0