Skip to Content

After Downloading, Error while opening PDF : PDF has no pages

After Downloading, Error while opening PDF : PDF has no pages

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = L_SPOOLNO

NO_DIALOG = SPACE

DST_DEVICE = MSTR_PRINT_PARMS-PDEST

IMPORTING

PDF_BYTECOUNT = MI_BYTECOUNT

TABLES

PDF = MTAB_PDF

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 = 9

Thanks in advance

Monika

ERR_BTCJOB_SUBMIT_FAILED = 10

ERR_BTCJOB_CLOSE_FAILED = 11

OTHERS = 12.

  • Transfer the 132-long strings to 255-long strings

LOOP AT MTAB_PDF.

TRANSLATE MTAB_PDF USING '~'.

CONCATENATE WA_BUFFER MTAB_PDF INTO WA_BUFFER.

ENDLOOP.

TRANSLATE WA_BUFFER USING '~'.

DO.

it_attach = WA_BUFFER.

APPEND it_attach.

SHIFT WA_BUFFER LEFT BY 255 PLACES.

IF WA_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

****GET THE FILE NAME TO STORE....................

v_path = 'C:\PD Form\' .

CONCATENATE v_path p_pernr-low '.pdf' into v_name.

create object v_guiobj.

call method v_guiobj->file_save_dialog

EXPORTING

default_extension = 'pdf'

default_file_name = v_name

file_filter = v_filter

CHANGING

filename = v_name

path = v_path

fullpath = v_fullpath

user_action = v_uact.

if v_uact = v_guiobj->action_cancel.

leave to current transaction.

endif.

..................................DOWNLOAD AS FILE....................

move v_fullpath to v_filename.

call function 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = MI_BYTECOUNT

filename = v_filename

filetype = 'BIN'

TABLES

data_tab = it_ATTACH

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

others = 22.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    May 18, 2011 at 08:16 AM

    Hi Monika,

    after CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    call 'GUI_DOWNLOAD'

    with table MTAB_PDF, not with it_attach

    Regards

    andrea

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 07, 2011 at 06:24 AM

    Resolved by myself

    Add comment
    10|10000 characters needed characters exceeded

    • My Generated Spool request is PDF Spool. It contains Adobe Forms data. To Download Adobe form

      Spool (PDF Spool) into PDF format,

      First,

      A) Read PDF Spool data by using u2018FPCOMP_CREATE_PDF_FROM_SPOOLu2019 Function module.

      B) Assign the Output Data to XSTRING format

      C) Convert that XSTRING data to Binary Format using 'SCMS_XSTRING_TO_BINARY' Function module.

      D) Save File on Application server using OPEN DATASET , TRANSFER , CLOSE DATASET.You can see your

      downloaded file in Transaction AL11 in specified directory.

      You can save your file on Presentation server also using GUI_DOWNLOAD.

      First three steps are necessary if your spool is PDF Spool.

      Basically we need this when we are downloading Adodbe forms ( which is not a SAPScript or smartforms)

      Example :

       DATA :
        e_pdf1 TYPE  fpcontent,
        e_renderpagecount1  TYPE i.
      
      
        CALL FUNCTION 'FPCOMP_CREATE_PDF_FROM_SPOOL'
          EXPORTING
            i_spoolid               = l_spoolno
            i_partnum               = '1'
         IMPORTING
           e_pdf                   = e_pdf1
           e_renderpagecount       = e_renderpagecount1
      *   E_PDF_FILE              = E_PDF_FILE1
      * EXCEPTIONS
      *   ADS_ERROR               = 1
      *   USAGE_ERROR             = 2
      *   SYSTEM_ERROR            = 3
      *   INTERNAL_ERROR          = 4
      *   OTHERS                  = 5
                  .
        IF sy-subrc <> 0.
      * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
      *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
      
      
        DATA : buffer  TYPE  xstring,
        append_to_table  TYPE  c.
      
        DATA : output_length TYPE  i.
        TYPES : BEGIN OF ty_binary,
                  binary_field(1000) TYPE c,
                END OF ty_binary.
      
        DATA : lt_binary TYPE TABLE OF ty_binary WITH HEADER LINE.
        DATA : lv_xstring TYPE xstring.
      
      
        lv_xstring = e_pdf1.
      
      * Convert xstring to binary.
        CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
          EXPORTING
            buffer                = lv_xstring
           append_to_table       = ' '
      * IMPORTING
      *   OUTPUT_LENGTH         =
          TABLES
            binary_tab            = lt_binary.
      
      
      
      
        DATA : wa_binary LIKE lt_binary.
      
        DATA: BEGIN OF itab OCCURS 0,
        field(256),
        END OF itab.
        DATA: dsn(50000) VALUE '/usr/sap/tmp/',
        length LIKE sy-tabix,
        lengthn LIKE sy-tabix.
      
      
        CONCATENATE '/usr/sap/tmp/' lv_pernr '.pdf' INTO dsn.
      
      
      
      ******* Save file on Application server
      
        OPEN DATASET dsn FOR OUTPUT IN BINARY MODE.
      
      
        LOOP AT lt_binary.
      
          TRANSFER lt_binary-binary_field TO dsn.
      
        ENDLOOP.
      
      
      
      
        CLOSE DATASET dsn.
        CLEAR lt_binary.
        REFRESH lt_binary.
      
      

      cheers