cancel
Showing results for 
Search instead for 
Did you mean: 

How can I open a new window for a (calculated) PDF?

Former Member
0 Kudos

Hi,

I have a BSP application with MVC. The start page is a HTML/HTMLB page with some buttons. If you click on the buttons, you get a PDF document in the same browser window. I generated the PDF over smart forms from table/Cluster data.

I call the controller in the OnInputProcessing event handler of the page and give it the parameters.

The problem: if you are on the PDF you cannot come back to the start page. I think, it is better, if the PDF gets a new window. The user can open on this way many PDF docs.

I tryed with navigation->next_page(...) or call_view etc. but all this dosn't work. Only the PDF will be show and in the same window!

Do I have to separe the application in two applications and use the CALL_APPLICATION method?

Or does anyone know a better way?

Thank you!

Regards

Patrizia

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Thomas,

thank you for your mail. I tryed it, but it doesn' t work well because I use a binary PDF file: I convert the data in OTF and then in PDF. But I'll use your way for another application

I solved my problem on a easy way: the first page calls another HTM page and sends the parameters for the controller call. The second one calls the controller and generates and shows the PDF. After this, the user can go back to the start page with the back button and chooses another document and so on. It is very easy.

I have a new question: where can I find the list of parameter for IF_HTTP_RESPONSE (f.e. method set_header_field parameter 'Content-Disposition' or 'cache_control', etc.)? I seek in the SAP library but I found only method names, not parameters.

Thank you and have a nice time.

Regards

Patrizia

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

> but it doesn' t work well because I use a binary PDF file

I'm not sure why that wouldn't work. My PDF data stream is also binary. I'm curious - exactly what was the problem you ran into?

>where can I find the list of parameter for IF_HTTP_RESPONSE f.e. method set_header_field ?

These header field parameters aren't SAP specific. You can find good document on the web.

http://www.faqs.org/rfcs/rfc1806.html

http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

For general documentation on many of the undocument SAP classes like IF_HTTP_RESPONSE check out the following weblog:

/people/thomas.jung3/blog/2005/01/13/bsp-utility-classes

Former Member
0 Kudos

HI Thomas,

I send you a fragment of the code. It does work well.

Thank you for the links!

The data are read, convert into a otf, then in pdf

CALL METHOD me->print_otf_2_pdf

EXPORTING

otfdata = model->otf

response = response

navigation = navigation.

METHOD print_otf_2_pdf .

  • generated result: PDF format

DATA: l_pdf_xstring TYPE xstring,

linetab TYPE tlinetab,

l_pdf_len TYPE i.

  • Conversion of output format OTF into PDF format

  • now convert the final document (OTF format) into PDF format

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

  • MAX_LINEWIDTH = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

IMPORTING

bin_filesize = l_pdf_len

bin_file = l_pdf_xstring " binary file

TABLES

otf = otfdata

lines = linetab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

OTHERS = 5

.

IF sy-subrc <> 0.

......

ENDIF.

CALL METHOD me->open_pdf

EXPORTING

pdf_xstring = l_pdf_xstring

pdf_len = l_pdf_len.

ENDMETHOD.

METHOD open_pdf .

DATA: l_pdf_len TYPE i,

runtime type ref to if_bsp_runtime,

filename type string,

guid type guid_32.

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

value = 'application/pdf' ).

response->set_header_field(

name = 'cache-control'

value = 'max-age=0' ).

l_pdf_len = XSTRLEN( pdf_xstring ).

response->set_data( data = pdf_xstring

length = l_pdf_len ).

navigation->response_complete( ).

ENDMETHOD.

Regards

Patrizia

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

You can just place your PDF document into the ICM cache. Then in when you rebuild your view in your start page, you include a link to this cached object in a 1 pixel X 1 pixel Iframe. In essesence this causes the PDF to open in another window.

The following weblog has the code to acomplish this. It does it for XML, Excel, and HTML downloads, but the process would be the same for PDF.

/people/thomas.jung3/blog/2004/09/02/creating-a-bsp-extension-for-downloading-a-table

In fact here is the code from another application that does this exact same thing for PDF. It is contained in a model class that is called from my controller:


method pdf_out.
*@78QImporting@	RUNTIME	TYPE REF TO IF_BSP_RUNTIME	Business Server Page (BSP) Runtime
 clear me->error.
  clear me->pdf_url.
  data: output type fpformoutput.

  call function 'Z_E_RFC_ADOBE_PUBLIC_DOM_OUT'
    exporting
      model      = me
      pdf_output = abap_true
    importing
      output     = output
      error      = me->error.

****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.

****set the data and the headers
  cached_response->set_data( output-pdf ).
  cached_response->set_header_field( name  = if_http_header_fields=>content_type
                                     value = 'APPLICATION/PDF' ).

  data: filename type string.
  concatenate me->dir_details-dokar
              me->dir_details-doknr
              me->dir_details-dokvr
              me->dir_details-doktl
              into filename separated by '_'.
  concatenate `attachment; filename=` filename into filename.
  concatenate filename
              '.PDF'
              into filename.
****Set the filename into the response header
  cached_response->set_header_field( name  = 'Content-Disposition'
                              value = filename ).

****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 = 60 ).

****Create a unique URL for the object
  data: guid type guid_32.
  call function 'GUID_CREATE'
    importing
      ev_guid_32 = guid.
  concatenate runtime->application_url '/' guid into pdf_url.

****Cache the URL
  cl_http_server=>server_cache_upload( url      = pdf_url
                                       response = cached_response ).
  return.

endmethod.

View Coding

if model->pdf_url is not initial.
              %>
              <iframe src="<%= model->pdf_url %>" width="1px" height="1px">
              </iframe>
              <%
  clear model->pdf_url.
  endif.
              %>