cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Convert PDF to string

Former Member
0 Likes
1,791

Hello everybody,

I have a BSP Application which handles PDF Documents. Now I want download a PDF Dokument from the Applikation Server to the Workstation. I have a HTML Link which is linked to the PDF File. If I click on the link I want to get the binary data of the PDF File in a string.

I don't have any Idea to solve this problem. Can anybody help me?

Kind regards

Axel

Accepted Solutions (0)

Answers (1)

Answers (1)

athavanraja
Active Contributor

do you mean when user clicks the link, you have to read the PDF data from application server and save it in the local work station?

<i>If I click on the link I want to get the binary data of the PDF File in a string</i>.

why do you want to do that?

Regards

Raja

Former Member
0 Likes

Hell Raja,

i have a bsp Applikation which handles with PDF Files. I have a bsp-site in which shows a Link to an PDF File, that is on the application server. If I click on the link a standard popup with the bittons Open, Save, Cancel and Display comes up. The PDF File should not be directly opened in the browser if I click on the link. In "normal" Web Applications I have to modify the HTTP response and put the binray data of the PDF File into the HTTP response. I find a link (/people/thomas.jung3/blog/2004/08/09/bsp-download-to-excel-in-unicode-format) in the SDN which describe it with a Excel sheet, but for PDF's it did not work.

Kind regards

Axel

athavanraja
Active Contributor
0 Likes

you got the right link.

just change the APP_TYPE attributes discussed in the weblog to <b>application/pdf</b> and it should work.

if it doesnt, kindly tell us what error you are getting.

also check this weblog , this may be of useful to you.

/people/sap.user72/blog/2004/11/10/bsphowto-generate-pdf-output-from-a-bsp

Regards

Raja

Former Member
0 Likes

sorry that I forgot to tell you what kind of error I get. I get the error (there is an mistake in the PDF File)when I want to open the downloaded PDF file on my local PC. I develop following code to download the PDF:

APP_TYPE = 'APPLICATION/PDF'.

response->set_header_field( name = 'content-type' value = APP_TYPE ).

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 =

'attachment; filename = webforms.pdf' ).

OPEN DATASET pdfLink FOR INPUT IN BINARY MODE.

DO.

READ DATASET pdfLink INTO is_pdf.

IF sy-subrc = 0.

CONCATENATE Lv_STRING is_pdf INTO Lv_STRING.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET pdfLink.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = lv_string

MIMETYPE = 'APPLICATION/PDF;'

IMPORTING

BUFFER = l_xstring

lv_len = xstrlen( l_xstring ).

response->set_data( data = l_xstring length = lv_len ).

navigation->response_complete( ).

The code is the same as in the log /people/thomas.jung3/blog/2004/08/09/bsp-download-to-excel-in-unicode-format

But it did not work.

Kind regards

Axel

athavanraja
Active Contributor
0 Likes

you also need to delete the cache control.

response->set_data( file_content ).
  response->set_header_field( name  = if_http_header_fields=>content_type
                              value = file_mime_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 ).
  navigation->response_complete( ). " signal that response is complete

Regards

Raja

Former Member
0 Likes

Now I have also delete the cache control, but it did not work. If I want to open the pdf, after the download process, I get the message that the acrobat reader could not open the file because it is defect.

Regards

Axel

athavanraja
Active Contributor
0 Likes

looks like there is a problem with the way you build the binary string.

<i>OPEN DATASET pdfLink FOR INPUT IN BINARY MODE.

DO.

READ DATASET pdfLink INTO is_pdf.

IF sy-subrc = 0.

CONCATENATE Lv_STRING is_pdf INTO Lv_STRING.

ELSE.

EXIT.

ENDIF.

ENDDO.

CLOSE DATASET pdfLink.</i>

change the concatenate statement to add BYTE mode.

CONCATENATE Lv_STRING is_pdf INTO Lv_STRING IN BYTE mode.

Regards

Raja

Former Member
0 Likes

Hello Raja,

thank you for your help. Now it works fine.

Kind regards

Axel