Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to read a PDF directly from aplication server

Former Member
0 Likes
4,724

I want to make a program that is able to see a PDF from the application server.

I've seen the example program SAP_PDF_VIEWER_DEMO that uses cl_gui_pdfviewer but it seems this class only reads PDF files from the client or from an URL, how can I make a similar program to read directly from de application server?

1 ACCEPTED SOLUTION
Read only

brad_bohn
Active Contributor
0 Likes
4,281

You can certainly build a url to the app server file or access the app server file via a mapped drive and use that functionality. Otherwise, you just need to use OPEN DATASET (binary mode) / READ DATASET to get the data and place it where you need it (to use a custom control or the Adobe Reader app itself).

I want to make a program that is able to see a PDF from the application server.

I've seen the example program SAP_PDF_VIEWER_DEMO that uses cl_gui_pdfviewer but it seems this class only reads PDF files from the client or from an URL, how can I make a similar program to read directly from de application server?

13 REPLIES 13
Read only

brad_bohn
Active Contributor
0 Likes
4,282

You can certainly build a url to the app server file or access the app server file via a mapped drive and use that functionality. Otherwise, you just need to use OPEN DATASET (binary mode) / READ DATASET to get the data and place it where you need it (to use a custom control or the Adobe Reader app itself).

Read only

Former Member
0 Likes
4,281

Hmmm in that case how can I build an url to the aplication server?

I thought it couldnt be accessed via web.. doesnt it need some kind of html server to be able to do that?

Read only

Former Member
0 Likes
4,281

...

Edited by: RagnaRock on Jun 24, 2010 5:06 PM

Read only

Former Member
0 Likes
4,281

after getting the file in BIN format internal table, use FMs like HR_EFI_SHOW_PDF_FORM to display the PDF form,

there are many mroe FMs.. just run though the forum.. you will find some.

Read only

Former Member
0 Likes
4,281

hmmm i'll try this one.

thanks!

Read only

Former Member
0 Likes
4,281

one question,

I have the pdf in binary mode in a table with this structure:

TYPES: BEGIN OF s_file,
         data(64),
       END OF s_file.

but to use this function it needs to be in a table like TSFOTF

how can I convert it?

Read only

Former Member
0 Likes
4,281

can you sugest more FM's of this kind? I dont know what to look for...

Read only

brad_bohn
Active Contributor
0 Likes
4,281

Use the methods of cl_gui_frontend_services: get_upload_download_path and environment_get_variable (if something like %TEMP% is used) to get the download path (or just build it directly) , gui_download to store it locally, then gui_execute to open the file with Adobe Reader. As for the url option, it all depends on your landscape and the security settings. The url is merely a pointer to the file, but of course, that viewer class is tagged 'Do not use!' by SAP.

Read only

Former Member
0 Likes
4,281

Today I've been able to do some new things with the sap web repository,

I am wondering if its possible to give the url generated by the FM DP_PUBLISH_WWW_URL to access it with cl_gui_pdfviewer method html_viewer.

DATA url  TYPE cndp_url.
    DATA str_url TYPE char255.

    CALL FUNCTION 'DP_PUBLISH_WWW_URL'
      EXPORTING
        objid    = 'Z_PDF'
        lifetime = cndp_lifetime_transaction
      IMPORTING
        url      = url
      EXCEPTIONS
        OTHERS   = 1.

    str_url = url.

    IF NOT my_pdf_viewer->html_viewer IS INITIAL.
      CALL METHOD my_pdf_viewer->open_document
        EXPORTING
            url = str_url.
    ENDIF.

I've tried this, and it gives me an error

"SAPHTML_E_CALL_METHOD_FAILED: 桓睯牕l桓睯剕L灏湥潄畣敭瑮湉敎坷湩潤w獭浸㍬搮汬("SAPR3://WebRepository/0123456789/Z_PDF?Version=00001")"

But i'm wondering if there is a way to tweak this and make it work...

Any idea?

Is there any FM that give us an actual http link to the file?

Edited by: RagnaRock on Jun 30, 2010 6:57 PM

Read only

brad_bohn
Active Contributor
0 Likes
4,281

That's going to be a strange way to attack it - the web repository is for logos and other MIME objects for web apps and dynpro-based apps. I wouldn't recommend it for PDF docs. Internal documents are stored in the BDS and can be accessed via the CL_BDS_DOCUMENT_SET class though you don't need that either.

My guess on the error would be that the url you get from the provider isn't a recognizable format. It starts with 'SAPR3://WebRepository...' or something like that if I remeber correctly. If you're set on using the PDF viewer class and a url, then like I said before, you just need to format your url accordingly for the SAP app server and make sure the access is there. Your url would look something like this: 'file://
mysapappserver\...\myfile.pdf'. If I were on the Basis team though, I would force the PDF's to be stored/accessed elsewhere on a file server, depending on your hardware. It's a simple task to provide the access to the folder on the app server.

Read only

0 Likes
4,281

CL_GUI_PDFVIEWER is marked "DO NOT USE" by SAP. Instead use CL_GUI_HTML_VIEWER control, this way:

get the PDF binary

call CL_GUI_HTML_VIEWER->LOAD_DATA method to get an URL to the PDF

exporting mime type (application) and subtype (pdf), and itab1024 contains the PDF binary

importing url

call CL_GUI_HTML_VIEWER->SHOW_URL

exporting url

You may have a look at demo program rsdemo_html_viewer.

Read only

Former Member
0 Likes
4,281

ok, so based on sandra information I've made this:

*&---------------------------------------------------------------------*
*& Report  ZSL_TESTE8
*&---------------------------------------------------------------------*

REPORT  zsl_teste8.

DATA: ok_code LIKE sy-ucomm,
      save_ok LIKE sy-ucomm.

TYPES: BEGIN OF struc_data ,
          line(72)  TYPE c,
       END OF struc_data.

DATA: init,
      container TYPE REF TO cl_gui_custom_container,
      html_viewer TYPE REF TO cl_gui_html_viewer,
      bi_xstring TYPE xstring,
      data_tab TYPE STANDARD TABLE OF struc_data,

      lt_mime TYPE TABLE OF w3mime,
      url(255),
      l_size TYPE i.

PARAMETERS: p_fserv   LIKE rlgrap-filename DEFAULT '.\factura_1.pdf'.

PERFORM get_pdf_binary.

CALL SCREEN 100.



*&---------------------------------------------------------------------*
*&      Form  get_pdf_binary
*&---------------------------------------------------------------------*
FORM get_pdf_binary .

  OPEN DATASET p_fserv FOR INPUT IN BINARY MODE.
  IF sy-subrc = 0.
    READ DATASET p_fserv INTO bi_xstring.
    CLOSE DATASET p_fserv.
  ENDIF.

ENDFORM.                    " get_pdf_binary
*&---------------------------------------------------------------------*
*&      Form  load_data
*&---------------------------------------------------------------------*
FORM load_data .

  CALL METHOD html_viewer->load_data
    EXPORTING
*    URL                  =
      type                 = 'application'
      subtype              = 'pdf'
      size                 = l_size
*    ENCODING             =
*    CHARSET              =
    IMPORTING
      assigned_url         = url
    CHANGING
      data_table           = data_tab"or lt_mime ?
*  EXCEPTIONS
*    DP_INVALID_PARAMETER = 1
*    DP_ERROR_GENERAL     = 2
*    CNTL_ERROR           = 3
*    others               = 4
          .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


ENDFORM.                    " load_data
*&---------------------------------------------------------------------*
*&      Form  show_url
*&---------------------------------------------------------------------*
FORM show_url .

CALL METHOD html_viewer->show_url
  EXPORTING
    url                    = url
*    FRAME                  =
*    IN_PLACE               = ' X'
*  EXCEPTIONS
*    CNTL_ERROR             = 1
*    CNHT_ERROR_NOT_ALLOWED = 2
*    CNHT_ERROR_PARAMETER   = 3
*    DP_ERROR_GENERAL       = 4
*    others                 = 5
        .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


ENDFORM.                    " show_url
*&---------------------------------------------------------------------*
*&      Module  pbo_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE pbo_0100 OUTPUT.

  l_size = XSTRLEN( bi_xstring ).

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer     = bi_xstring
    TABLES
      binary_tab = lt_mime.

  SET PF-STATUS 'STATUS'.
  IF init IS INITIAL.
    CREATE OBJECT container
            EXPORTING container_name = 'CONT'.
    CREATE OBJECT html_viewer
            EXPORTING  parent              = container
            EXCEPTIONS cntl_error         = 1
                       cntl_install_error = 2
                       dp_install_error   = 3
                       dp_error           = 4.
    IF sy-subrc NE 0.
* Fehlerbehandlung
    ENDIF.
    CALL METHOD cl_gui_cfw=>flush
      EXCEPTIONS
        cntl_system_error = 1
        cntl_error        = 2.
    IF sy-subrc NE 0.
* Fehlerbehandlung
    ENDIF.
    init = 'X'.
  ENDIF.

  PERFORM load_data.
  PERFORM show_url.

ENDMODULE.                 " pbo_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  save_ok = ok_code.
  CLEAR ok_code.

  CASE save_ok.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE PROGRAM.
  ENDCASE.

ENDMODULE.                 " USER_COMMAND_0100  INPU

Aparently, doesnt do anything....

Where did I go wrong?

P.S.: screen 100 has a container named "CONT"

Read only

0 Likes
4,281

does your dynpro contains this?


PROCESS BEFORE OUTPUT.
  MODULE pbo_0100.

Use LT_MIME instead of DATA_TAB here:


  CALL METHOD html_viewer->load_data
...
    CHANGING
      data_table           = lt_mime

Last thing, you don't need to flush explicitly in PBO as it is done by SAP automatically at the end of the PBO, as explained in [sap library - control framework - Synchronizing the Automation Queue|http://help.sap.com/saphelp_nw2004s/helpdata/en/37/63bdc2e80211d2bdcb080009b4534c/frameset.htm]