cancel
Showing results for 
Search instead for 
Did you mean: 

SAP UI5 export to PDF ( Fetch data dynamically )

Former Member
0 Kudos

Hello Everyone,

I am creating a utility wherein the data ( table ) would be fetched from the back end and then it would be displayed on the front end. I have follewed the approach of Chandrashekhar (    ) but I want to print the internal table content dynamically.

Your help would be appreciated.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I have used jsPDF open source library and that was really very helpful. It has simple functions and easy to use API to show PDF with text and images. Please try that and I was able to integrate it in SAPUI5 app very easily.

thanks

Ashish

AlexDong
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Ashish,

Thank you for your reply and I am already trying to use this tool inside of my APP. I am wondering, why the SAP UI5 library doesn't have such kind of tool?

best regards,

Alex

Former Member
0 Kudos


Code to be written in Gateway service to get the PDF url.


DATA: lt_keys     TYPE /iwbep/t_mgw_tech_pairs,
ls_key     
TYPE /iwbep/s_mgw_tech_pair,
lv_mblnr   
TYPE mkpf-mblnr,
lv_mjahr   
TYPE mkpf-mjahr,
lv_xstring 
TYPE xstring,
ls_stream  
TYPE ty_s_media_resource.

lt_keys
= io_tech_request_context->get_keys( ).
READ TABLE lt_keys WITH KEY name = 'MBLNR' INTO ls_key.
IF sy-subrc = 0.
lv_mblnr
= ls_key-value.
ENDIF.
READ TABLE lt_keys WITH KEY name = 'MJAHR' INTO ls_key.
IF sy-subrc = 0.
lv_mjahr
= ls_key-value.
ENDIF.

PERFORM pdf_call_gw IN PROGRAM zmms_grn_print
USING lv_mblnr lv_mjahr CHANGING lv_xstring.

er_entity
-mblnr = lv_mblnr.
er_entity
-mjahr = lv_mjahr.

DATA: lv_app_type TYPE string,
lo_cached_response
TYPE REF TO if_http_response,
lv_guid
TYPE guid_32.

CREATE OBJECT lo_cached_response
TYPE cl_http_response
EXPORTING add_c_msg = 1.
****set the data and the headers
lo_cached_response
->set_data( lv_xstring ).
lv_app_type
= '.PDF'.

lo_cached_response
->set_header_field(
name
= if_http_header_fields=>content_type
value = lv_app_type ).

****Set the Response Status
lo_cached_response
->set_status( code = 200 reason = 'OK' ).

****Set the Cache Timeout - 60 seconds - we only need this in the cache
****long enough to build the page
lo_cached_response
->server_cache_expire_rel( expires_rel = 60 ).

****Create a unique URL for the object and export URL
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_32
= lv_guid.

CONCATENATE '/sap/public' '/' lv_guid '.' 'PDF' INTO er_entity-url.

****Cache the URL
cl_http_server
=>server_cache_upload(
url
= er_entity-url
response
= lo_cached_response ).


Controller


   console.log('Success');

        selfView.getView().byId('idPDF').setContent("<iframe src=" + data.Url

            + " width='700' height='700'></iframe>");

View

<HTML xmlns="sap.ui.core" id="idPDF" visible="true" content="">

          </HTML>

It will generate the adobe form in SAP UI5 on click of execute button and will diplay in frame. There will print option present in Adobe form to print the pdf.

EkanshCapgemini
Active Contributor
0 Kudos

Hi Alex & Ashish,

Have you guys tested jsPDF with UI5 table component?

It would be helpful if you can share the jsbin or fiddle.

Regards,

Ekansh

Qualiture
Active Contributor
0 Kudos

Reason being, generating PDF's is not something you want to happen in a client browser... Leave that to a backend

AlexDong
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Laxmi,

Sorry to apply so late. The backend functionality is already in use for many years but have some problmes. Now I am responsible for SAP Notes display in UI5 and have to use frontend technology to generate pdf. Thank you anyway.

Best regards,

Alex

AlexDong
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Ashish,

I am confused about jspdf.js API i.e. from_html() functionality. They doesn't support css well e.g. text-align. What's worse, the images in front-end cannot be rendered because of "cross-origin" issue. Now my app is on HANA Cloud Platform. Did you encounter this before?

Best regards,

Alex

Qualiture
Active Contributor
0 Kudos

Seriously, if you have your app running on HANA Cloud Platform, why on earth do you want to generate the PDF on the client? Use the power of HCP and Java to generate PDF's. You can even store your PDF's in HCP's document service (which is CMIS based) for easy retrieval etc)

There are many Java API's for creating PDF's