Skip to Content

Introduction

This Document helps to Browse PDF file from Local system and display in Web dynpro .

UI Elements:

                      File Upload

                      Button

                      IFrame

   

Create a Webdynpro Component

Create a Node ( BROWSE_PDF)

 

Nodes:      BROWSE_PDF      Cardinality: 1:1

Attribute:   URL                       Type: String

Attribute:   DATASOURCE       Type :String

Create a UI Element (File Upload)

Bind the property of file upload : DATA

Select Datasource

Create UI element Button

Create a action UPLOAD

Create  a UI Element IFRAME to display the PDF

Bind the Property  Source 

Select URL

Write the code for Action UPLOAD

   DATA LO_ND_BROWSE_PDF TYPE REF TO IF_WD_CONTEXT_NODE.
   DATA LO_EL_BROWSE_PDF TYPE REF TO IF_WD_CONTEXT_ELEMENT.
   DATA LS_BROWSE_PDF TYPE WD_THIS->ELEMENT_BROWSE_PDF.
   DATA LV_URL LIKE LS_BROWSE_PDF-URL.
   DATA LO_EL_CONTEXT TYPE REF TO IF_WD_CONTEXT_ELEMENT.
   DATA LS_CONTEXT TYPE WD_THIS->ELEMENT_CONTEXT.
   DATA LV_DATASOURCE TYPE WD_THIS->ELEMENT_CONTEXT-DATASOURCE.
   DATA: CACHED_RESPONSE     TYPE REF TO   IF_HTTP_RESPONSE,
         LV_FILE_CONTENT     TYPE          XSTRING,
         LV_GUID             TYPE          GUID_32,
         LV_HOST             TYPE          STRING,
         LV_PORT             TYPE          STRING,
         LV_PROTOCOL         TYPE          STRING.

   LO_EL_CONTEXT = WD_CONTEXT->GET_ELEMENT( ).
   LO_EL_CONTEXT->GET_ATTRIBUTE(
     EXPORTING
       NAME =  `DATASOURCE`
     IMPORTING
       VALUE = LV_DATASOURCE ).

   CREATE OBJECT CACHED_RESPONSE
          TYPE   CL_HTTP_RESPONSE
          EXPORTING ADD_C_MSG = 1.

   LV_FILE_CONTENT = LV_DATASOURCE.
   CACHED_RESPONSE->SET_DATA( LV_FILE_CONTENT ).
   CACHED_RESPONSE->SET_HEADER_FIELD( NAME  = IF_HTTP_HEADER_FIELDS=>CONTENT_TYPE
                                      VALUE = ‘application/pdf’ ).

   CALL FUNCTION ‘GUID_CREATE’
        IMPORTING ev_guid_32 = lv_guid.

     cached_response->set_status( code = 200 reason = ‘OK’ ).
     cached_response->server_cache_expire_rel( expires_rel = 360 ).

       CALL METHOD cl_http_server=>get_location
         EXPORTING
           server       = cl_wdr_task=>server
         IMPORTING
           host         = lv_host
           port         = lv_port
           out_protocol = lv_protocol.

       CONCATENATE
         lv_protocol ‘://’ lv_host ‘:’ lv_port ‘/sap/bc/webdynpro/sap/’
         lv_guid ‘.PDF’
         INTO lv_url.

       cl_http_server=>server_cache_upload( url      = lv_url
                                            response = cached_response ).

   LO_ND_BROWSE_PDF = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_BROWSE_PDF ).
   LO_EL_BROWSE_PDF = LO_ND_BROWSE_PDF->GET_ELEMENT( ).

   LS_BROWSE_PDF-URL = LV_URL.

   lo_el_BROWSE_PDF->set_static_attributeS(
                      static_attributes = ls_BROWSE_PDF ).

Create a Application

Run the Application

Choose file

Click on Upload button

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply