cancel
Showing results for 
Search instead for 
Did you mean: 

PDF not displaying

Former Member
0 Kudos

Hi,

I'm new to BSP's and seem to have a problem. When a form has to be displayed in a separate window the window comes up but with the error:

BSP Exception: Das Objekt 43701DE84054085702000000A3C401DA.pdf in der URL /sap(bD1lbiZjPTIxMCZkPW1pbiZ3PTk4MDM1ODAr)/bc/bsp/sap/zdi_spp_main/43701DE84054085702000000A3C401DA.pdf ist nicht gültig.

Here is the code also:

DATA: cached_response TYPE REF TO if_http_response.

CREATE OBJECT cached_response TYPE cl_http_response EXPORTING add_c_msg

= 1.

confirm->pdf_len = XSTRLEN( confirm->pdf_xstring ).

cached_response->set_data( data = confirm->pdf_xstring

length = confirm->pdf_len ).

cached_response->set_header_field( name =

if_http_header_fields=>content_type

value = 'application/pdf' ).

cached_response->set_status( code = 200 reason = 'OK' ).

cached_response->server_cache_expire_rel( expires_rel = 180 ).

CALL FUNCTION 'GUID_CREATE'

IMPORTING

ev_guid_32 = guid.

CONCATENATE runtime->application_url '/' guid '.pdf'

INTO l_display_url.

cl_http_server=>server_cache_upload( url = l_display_url

response = cached_response ).

Any help would be greatly appreciated.

Thanks

Bradley

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member196065
Participant
0 Kudos

Hi Bradley,

The following code i am using since long time we did not faced any problem till now you can check this code with your code.

This code was return for to download the data inot excel and pdf format

Import parameters for this method are

DATA TYPE XSTRING

OPTION TYPE STRING

RESPONSE TYPE REF TO IF_HTTP_RESPONSE

NAVIGATION TYPE REF TO IF_BSP_NAVIGATION

data: l_app_type type string,

l_filename type string,

l_xstring type xstring, "needed for HTTP response

l_xlen type i.

  • For Downloading into PDF format

if option eq 'PDF'.

  • setting Content Type

move 'application/pdf' to l_app_type.

move 'attachment; filename=webforms.pdf' to l_filename.

elseif option eq 'XLS'.

  • Setting Content Type

move 'application/msexcel' to l_app_type.

move 'attachment; filename=webforms.xls' to l_filename.

endif.

clear l_xstring.

l_xstring = data.

*----


  • Fill HTTP request

*----


response->set_header_field( name = 'content-type'

value = l_app_type ).

response->delete_header_field(

name = if_http_header_fields=>cache_control ).

response->delete_header_field(

name = if_http_header_fields=>expires ).

response->delete_header_field(

name = if_http_header_fields=>pragma ).

response->set_header_field(

name = 'content-disposition'

value = l_filename ).

  • finally display PDF format in Browser

l_xlen = xstrlen( l_xstring ).

response->set_data( data = l_xstring

length = l_xlen ).

navigation->response_complete( ).

Former Member
0 Kudos

Hi,

I've tried return but it just exits the method at that point causing it not to call the page in where the pdf should be displayed. I'm using MVC. Seeing that it always use to work and now it doesn't. Is there a possibility that there is nothing wrong with the code but something that is suppose to be done or set on the server side or anywhere else. Has anybody had the same problem before.

Thanks

Bradley

eddy_declercq
Active Contributor
0 Kudos

Hi,

Pls don't forget to reward points (you need to mark it as a question) and close the question if you find the answers useful.

Eddy

Former Member
0 Kudos

Hi,

The code I use is the same as the one you suggested. The thing is pdf pages are displayed throughout the bsp app using the same code. But the others are working. Previously I had a problem where another page also displaying a pdf doc and with similiar code worked twice out of 10 times. And then eventually without adding or removing any code it worked 100%. I am totally lost about how to fix this problem. And I can't wait for it to fix itself.

Thanks

Bradley

eddy_declercq
Active Contributor
0 Kudos

Hi,

When I want to show pdf, I do the following:

I read the pdf file

read dataset file_path_pdf inTO pdfcontent.

CLOSE DATASET file_path_pdf.

runtime->server->response->set_data( pdfcontent ).

contentsize = xstrlen( pdfcontent ).

runtime->server->response->set_header_field( name = 'Content-Length'

value = contentsize ).

Very important: clear the cache

runtime->server->response->delete_header_field( name = 'Cache-Control' ).

runtime->server->response->delete_header_field( name = 'Expires' ).

runtime->server->response->delete_header_field( name = 'Pragma' ).

runtime->server->response->set_header_field( name = 'Content-Type'

value = 'application/pdf' ).

delete eventually the file

delete dataset file_path_pdf.

close the connection

mnavigation->response_complete( ).

Eddy

athavanraja
Active Contributor
0 Kudos

after the line

cl_http_server=>server_cache_upload( url = display_url

response = cached_response ).

add the following line of code.

<b> return.</b>

Regards

Raja

Former Member
0 Kudos

Hi Bradley,

You can refer to the weblog:BSP Programming: Handling Of Non-HTML ?page=last&x-showcontent=off" [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken]>https [original link is broken] [original link is broken]

Also, to display the file in a Browser you have use code as in the Blog as :


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_data( file_content ).    cached_response->set_header_field( name  = if_http_header_fields=>content_type                                       value = file_mime_type ).    cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 180 ).  
DATA: guid TYPE guid_32. 
CALL FUNCTION 'GUID_CREATE' IMPORTING ev_guid_32 = guid.    
CONCATENATE runtime->application_url '/' guid INTO display_url.    
cl_http_server=>server_cache_upload( url =display_url                                         response = cached_response ).
ENDDIF.

You can get some help from the threads:

[url];/url]

Hope this Helps,

Regards,

Siddhartha

Message was edited by: Siddhartha Jain