Skip to Content
0
Former Member
Nov 09, 2004 at 01:01 PM

PDF Output

1071 Views

So what am I missing?

<b>BSP Programming: Handling Of Non-HTML Documents</b>

/people/mark.finnern/blog/2003/09/23/bsp-programming-handling-of-non-html-documents

<b>Generate file .doc or .pdf as from a text</b>

Generate file .doc or .pdf as from a text

<b>Page Layout</b>

<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2002" >
  <htmlb:page>
    <htmlb:form method       = "post"
                encodingType = "multipart/form-data" >
      <htmlb:radioButtonGroup id="display_type" >
        <htmlb:radioButton id   = "inline"
                           text = "Display Inline" />
        <htmlb:radioButton id   = "html"
                           text = "Display Inside HTML Page" />
        <htmlb:radioButton id   = "window"
                           text = "Display In New Window" />
        <htmlb:radioButton id   = "convert"
                           text = "Convert to PDF Inside HTML Page" />
        <htmlb:radioButton id   = "convertnew"
                           text = "Convert to PDF In New Window" />
      </htmlb:radioButtonGroup>
      <htmlb:fileUpload id          = "myUpload"
                        onUpload    = "HandleUpload"
                        upload_text = "Display"
                        size        = "90" />
      <hr>
      <br>Name = <%= file_name%>
      <br>MIME-Type = <%= file_mime_type%>
      <br>Length = <%= file_length%>
      <%
  IF ( display_type = 'html' OR display_type = 'convert' ) AND  display_url IS NOT INITIAL.
      %>
      <iframe src="<%= display_url%>" width="100%" height="500px">
      </iframe>
      <%
  ENDIF.
  IF ( display_type = 'window' OR display_type = 'convertnew' ) AND display_url IS NOT INITIAL.
      %>
      <script language="Javascript">
        window.open("<%= display_url%>").focus();
      </script>
      <%
  ENDIF.
      %>
    </htmlb:form>
  </htmlb:page>
</htmlb:content>

<b>OnInputProcessing</b>

* event handler for checking and processing user input and
* for defining navigation

DATA: radioButtonGroup TYPE REF TO CL_HTMLB_RADIOBUTTONGROUP.
DATA: fileUpload TYPE REF TO CL_HTMLB_FILEUPLOAD.
DATA: cached_response TYPE REF TO if_http_response.
DATA: response TYPE REF TO if_http_response.
DATA: guid TYPE guid_32.

fileUpload ?= CL_HTMLB_MANAGER=>GET_DATA(
                       request = request
                       id      = 'myUpload'
                       name    = 'fileUpload' ).

file_name      = fileUpload->file_name.
file_mime_type = fileUpload->file_content_type.
file_length    = fileUpload->file_length.
file_content   = fileUpload->file_content.

radioButtonGroup ?= CL_HTMLB_MANAGER=>GET_DATA(
                       request = request
                       id      = 'display_type'
                       name    = 'radioButtonGroup' ).

display_type = radioButtonGroup->selection.

IF display_type = 'inline' AND XSTRLEN( file_content ) > 0.
  response = runtime->server->response.
  response->set_data( file_content ).
  response->set_header_field( name  = if_http_header_fields=>content_type
                              value = file_mime_type ).
  " response->set_header_field( name  = if_http_header_fields=>content_length
  "                             value = file_length ).
  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 ).
* signal that response is complete
  navigation->response_complete( ). 
  RETURN.
ENDIF.

IF ( display_type = 'html' OR display_type = 'window' ) AND XSTRLEN( file_content ) > 0.

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

  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 ).
  RETURN.

ENDIF.

IF ( display_type = 'convert' OR display_type = 'convertnew' ) AND XSTRLEN( file_content  ) > 0.

  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 = '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 display_url.

  cl_http_server=>server_cache_upload( url      = display_url
                                       response = cached_response ).

  RETURN.

ENDIF.

Again so what am I missing? If I select the Convert to PDF with a text file and open in a new window I get my page then I do a save as and I save it as a .PDF but then Adobe can't open it. So I must be missing something easy...