cancel
Showing results for 
Search instead for 
Did you mean: 

File does not begin with %PDF

Former Member
0 Kudos

Hi,

I have I developed a application WDA to display the employee photo. I have used the component InteractiveForm in layout to do this.

I got the photo from archivelink (BINARY) and convert it to XSTRING. See the source below:

call function 'SCMS_AO_TABLE_GET'

exporting

arc_id = archivelink-archiv_id

doc_id = archivelink-arc_doc_id

comp_id = 'data'

importing

length = lv_length

tables

data = lt_data

exceptions

error_http = 1

error_archiv = 2

error_kernel = 3

error_config = 4

others = 5.

if sy-subrc ne 0.

exit.

endif.

call function 'SCMS_BINARY_TO_XSTRING'

exporting

input_length = lv_length

importing

buffer = foto

tables

binary_tab = lt_data.

The problem is: Some machines are showing the adobe error "File does not begin with %PDF", therefore others have no problem.

What I can do to solve it ?

Can anybody help me?

Thanks a lot,

Accepted Solutions (1)

Accepted Solutions (1)

TomVanDoo
Active Contributor
0 Kudos

could be a setting in the folder options->file types of your windows explorer

But, to display an image, I personally would use an image UI element.

or maybe a file download to make it a clickable link (will open a new window containing the photo)

Former Member
0 Kudos

Hi Tom,

I got the photo from archivelink (BINARY) and convert it to XSTRING. I use the Interactive Form to show the photo similar to the standar WD JAVA ess~cod. If I use the others elements my aplication is not similiar to the standar.

Thanks for your help.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

This is a photo right - like a JPG or GIF? I have no idea why the standard would use the interactiveForm UI element. It seems completely inappropriate. So much overhead of initializing the PDF Reader just to display something that can be done in the native browser. I agree with the previous poster; it is much better if you are dealing strictly with an image to use the Image UI element.

Former Member
0 Kudos

Hi Thomas,

I am using an interactiveForm UI element because I have to use a xstring to treat the photo.

I can't to use an Image UI element because this element only shows an image with url (string) and not with xstring.

If I use the photo's url I have problems because my portal uses the protocolo https and the photo doesn't show, but if i use xstring the photo shows fine.

Thanks.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>I can't to use an Image UI element because this element only shows an image with url (string) and not with xstring.

Yes, but you can take your XSTRING content and place it in the ICM cache and generate a temporary URL for it. The ICM Cache URL will be relative so HTTPS shouldn't be a problem. Perhaps in Web Dynpro Java such a solution as the InteractiveForm was necessarily, but in Web Dynpro ABAP we have the ICM Cache and this will defintely avoid the file does not begin with %PDF - as the PDF Reader was not designed to display images alone - but PDF documents.

Here is a sample:

METHOD push_content_into_icm_cache.
*@78\QImporting@  I_PATH  TYPE STRING  DEFAULT '/sap/public'
*@78\QImporting@  I_FORMAT  TYPE STRING  DEFAULT 'BMP'  Supports JPG/GIF/TIFF/PNG
*@78\QImporting@  I_CACHE_TIMEOUT TYPE I  DEFAULT 60  Cache Timeout in Seconds
*@7B\QReturning@  VALUE( R_URL )  TYPE STRING URL To the Cached Resource
*@03\QException@  ZCX_ABAP_BITMAP   Bitmap Processing Exceptions


****Create the cached response object that we will insert our content into
  DATA: cached_response TYPE REF TO if_http_response.
  CREATE OBJECT cached_response
    TYPE
      cl_http_response
    EXPORTING
      add_c_msg        = 1.
*  cached_response->set_compression( options = cached_response->IF_HTTP_ENTITY~CO_COMPRESS_IN_ALL_CASES ).
  TRY. " ignore, if compression can not be switched on
      CALL METHOD cached_response->set_compression
        EXPORTING
          OPTIONS = cached_response->co_compress_based_on_mime_type
        EXCEPTIONS
          OTHERS  = 1.
    CATCH cx_root.
  ENDTRY.
****set the data and the headers
  DATA: l_app_type TYPE string.
  DATA: l_xstring TYPE xstring.
  CASE i_format.
    WHEN 'BMP'.
      cached_response->set_data( me->gx_content ).
      l_app_type = 'image/x-ms-bmp'.
    WHEN 'GIF'.
      me->get_content_ext_format(
        EXPORTING
          i_format  = i_format
        IMPORTING
          e_xstream = l_xstring ).
      cached_response->set_data( l_xstring ).
      l_app_type = 'image/gif'.
    WHEN 'JPG'.
      me->get_content_ext_format(
        EXPORTING
          i_format  = i_format
        IMPORTING
          e_xstream = l_xstring ).
      cached_response->set_data( l_xstring ).
      l_app_type = 'image/jpeg'.
    WHEN 'TIF'.
      me->get_content_ext_format(
        EXPORTING
          i_format  = i_format
        IMPORTING
          e_xstream = l_xstring ).
      cached_response->set_data( l_xstring ).
      l_app_type = 'image/tiff'.
    WHEN 'PNG'.
      me->get_content_ext_format(
        EXPORTING
          i_format  = i_format
        IMPORTING
          e_xstream = l_xstring ).
      cached_response->set_data( l_xstring ).
      l_app_type = 'image/png'.
    WHEN OTHERS.
      RAISE EXCEPTION TYPE zcx_abap_bitmap.
  ENDCASE.
*
  cached_response->set_header_field( name  = if_http_header_fields=>content_type
                                     value = l_app_type ).

****Set the Response Status
  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 and allow the IFrame on the Client to request it.
  cached_response->server_cache_expire_rel( expires_rel = i_cache_timeout ).

****Create a unique URL for the object
  DATA: guid TYPE guid_32.
  CALL FUNCTION 'GUID_CREATE'
    IMPORTING
      ev_guid_32 = guid.
  CONCATENATE i_path '/' guid '.' i_format INTO r_url.

****Cache the URL
  cl_http_server=>server_cache_upload( url      = r_url
                                       response = cached_response ).
ENDMETHOD.

TomVanDoo
Active Contributor
0 Kudos

Thomas,

I would buy you a beer you if I could.

This actually solved an older problem of mine. I used a filedownload to get the pictures on my webpage. ofcourse people had to click the link. they actually liked the solution because it kept the screen tidy, but the thruth is that I had no idea how to show an image from an xstring.

now I got it running thanks to your input.

I'm pretty certain Kata will get it running as well now.

the only remark i have is:

- I had to use /sap/bc/webdynpro/sap/ as my path

but I guess that has to do with configuration.

Former Member
0 Kudos

Thomas you are the best.

You have resolved my problem.

Can I changed the action when I click the right botton of my mouse for display the properties "Save picture as", "Email picture", etc...?

Now I press the right botton the application displays "User options", etc.... because is a Image UI element in WDA.

Thanks a lot for your help.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I'm afraid that Web Dynpro overrides the browser context menu and replaces it with its own context menu. If you want to offer a download image option, you will have to add that yourself. Just add a menu or button to trigger the action. In the server event you can use the method cl_wd_runtime_services=>attach_file_to_response to push the binary content back to the desktop.

Answers (0)