Skip to Content
author's profile photo Former Member
Former Member

PDF file gets corrupted when generated from BSP

Hi,

I am generating a PDF file from a BSP page ( see the code below). The problem is that PDF file gets corrupted and I am unable to open it. I also tried to use other functions like GUI_Download and DOwnload as suggested by many and they also do not work either. Has any one generated a PDF from BSP and can some one help?

Data: GG type String.

  • event handler for data retrieval

data : event type ref to cl_htmlb_event.

class cl_htmlb_manager definition load.

class CL_HTTP_RESPONSE DEFINITION LOAD.

DATA : PARAMS TYPE PRI_PARAMS,

VALID TYPE C,

GV_SUCCESS_SPOOL_NO LIKE SY-SPONO.

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING DESTINATION = 'LOCL'

  • COPIES = COUNT

  • LIST_NAME = 'TEST'

  • LIST_TEXT = 'Test NEW-PAGE PRINT ON'

IMMEDIATELY = ''

RELEASE = 'X'

NEW_LIST_ID = 'X'

  • EXPIRATION = DAYS

LINE_SIZE = 140

  • LINE_COUNT = 23

  • LAYOUT = 'X_PAPER'

  • SAP_COVER_PAGE = 'X'

  • RECEIVER = 'SAP*'

  • DEPARTMENT = 'System'

NO_DIALOG = 'X'

IMPORTING OUT_PARAMETERS = PARAMS

VALID = VALID.

IF VALID <> SPACE.

NEW-PAGE PRINT ON PARAMETERS PARAMS NO DIALOG.

write :/ 'Hello Message1'.

write :/ 'Hello Message2 '.

NEW-PAGE PRINT OFF .

ENDIF.

data : spool_no TYPE TSP01-RQIDENT .

spool_no = sy-spono.

DATA: itab TYPE TLINE,

witab TYPE TABLE OF TLINE,

output TYPE STRING,

outputx TYPE XSTRING.

data : l_pdf_len type i.

data: mi_bytecount type i.

DATA : APP_TYPE TYPE STRING VALUE 'APPLICATION/PDF' .

DATA: cached_response TYPE ref to if_HTTP_RESPONSE.

data : l_display_url type string .

data : guid type GUID_32 .

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = spool_no

NO_DIALOG = 'X'

IMPORTING

PDF_BYTECOUNT = mi_bytecount

TABLES

PDF = witab

EXCEPTIONS

ERR_NO_ABAP_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DESTDEVICE = 5

USER_CANCELLED = 6

ERR_SPOOLERROR = 7

ERR_TEMSEERROR = 8

ERR_BTCJOB_OPEN_FAILED = 8

ERR_BTCJOB_SUBMIT_FAILED = 9

ERR_BTCJOB_CLOSE_FAILED = 10

others = 11.

if sy-subrc EQ 0.

LOOP AT witab INTO itab.

CONCATENATE

output

itab-tdline

INTO output in character mode.

ENDLOOP.

endif.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = output

mimetype = 'APPLICATION/PDF'

IMPORTING

buffer = outputx.

concatenate cl_abap_char_utilities=>byte_order_mark_little

outputx

into outputx in byte mode.

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

'APPLICATION/PDF; charset=utf-16le' ).

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 = 'attachment; filename = TEST.PDF'

).

l_PDF_len = xstrlen( OUTPUTX ).

response->set_data( data = OUTPUTx

length = l_PDF_len ).

navigation->response_complete( ).

Regards

Amit Agrawal

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jun 30, 2005 at 12:31 PM

    Have you checked out this weblog?

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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.