cancel
Showing results for 
Search instead for 
Did you mean: 

Send/print PDF file to local printer from Web Dynpro Abap

rub_alfonso
Explorer
0 Kudos

Hi experts !!

I would like to know if it is possible to print or to send PDF document from the Web Dynpro to a local printer using any command inserted on a button.

I know that I could display PDF file on the Web Dynpro and push "standard print" button. But what I want to do is to send PDF document "by myself" not depending on ADOBE´s standard functionaity.

All this, is because I want to have under control when the user prints out PDF file (not to let him/her print 2 times). If user uses the standard PRINT button there is no way to check that.

Thanks in advance !!!

Accepted Solutions (0)

Answers (1)

Answers (1)

sahai
Contributor
0 Kudos

hi,

If i understood the reply correctly ... then i guess you want to have a print button on the screen by pressing this button the pdf file should get printed...also after first time pressing the button the button should not be allowed to press again...

you can always do this i.e you can create a button on the screen and den have a smartform created say ZSMARTFORM..

now you can write the below mentioned code on the button. you just created.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME                 = 'ZSMARTFORM' " smartform name
   IMPORTING
     FM_NAME                  = FM_NAME
            .
  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: JOB_OUPUT TYPE SSFCRESCL,
        LT_OTFDATA TYPE TABLE OF ITCOO.

  DATA: LA_CTRL_FORM TYPE SSFCTRLOP,
        LA_OUTPUT_OPT TYPE SSFCOMPOP.

** Spool Parameters
  LA_OUTPUT_OPT-TDIMMED = 'X'.
  LA_OUTPUT_OPT-TDDELETE = 'X'.
  LA_OUTPUT_OPT-TDLIFETIME = 'X'.
  LA_OUTPUT_OPT-TDDEST = 'LOCL'.

*    ****************************************************************************
* Parameters passes to get the output in PDF format
****************************************************************************
  LA_CTRL_FORM-NO_DIALOG = 'X'.
  LA_CTRL_FORM-PREVIEW = 'X'.
  LA_CTRL_FORM-GETOTF = 'X'.
  LA_CTRL_FORM-LANGU = 'EN'.
  LA_CTRL_FORM-DEVICE = 'PRINTER'.

  CALL FUNCTION FM_NAME
    EXPORTING
     CONTROL_PARAMETERS         =  LA_CTRL_FORM
     OUTPUT_OPTIONS             = LA_OUTPUT_OPT
      BILLABLE_LOT               = A "ls_ctx_vn_inp-BILLABLE_LOT
      SECTION                    = B "ls_ctx_vn_inp-SECTION
      PROJECT                    = PROJECT
      MGROUP                     = MGROUP
   IMPORTING
     JOB_OUTPUT_INFO            = JOB_OUPUT
   EXCEPTIONS
     FORMATTING_ERROR           = 1
     INTERNAL_ERROR             = 2
     SEND_ERROR                 = 3
     USER_CANCELED              = 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.
  REFRESH LT_OTFDATA.

  LT_OTFDATA[] = JOB_OUPUT-OTFDATA[].

  CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
    EXPORTING
      I_OTF                    = LT_OTFDATA
    EXCEPTIONS
      CONVERT_OTF_TO_PDF_ERROR = 1
      CNTL_ERROR               = 2
      OTHERS                   = 3.

  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: L_DUMMY TYPE STANDARD TABLE OF TLINE,
  PDF_DATA TYPE XSTRING,
  PDF_SIZE TYPE I.
  CLEAR: PDF_DATA, PDF_SIZE.

* convert otf to pdf
  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      FORMAT                = 'PDF'
      MAX_LINEWIDTH         = 255
    IMPORTING
      BIN_FILESIZE          = PDF_SIZE
      BIN_FILE              = PDF_DATA
    TABLES
      OTF                   = LT_OTFDATA[]
      LINES                 = L_DUMMY
    EXCEPTIONS
      ERR_MAX_LINEWIDTH     = 1
      ERR_FORMAT            = 2
      ERR_CONV_NOT_POSSIBLE = 3
      OTHERS                = 4.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
*    *path to the word file
    I_FILENAME = 'JobCard.pdf'
*     String Variable
    I_CONTENT =  PDF_DATA
*     File Type
    I_MIME_TYPE = 'PDF' ).

now you can create an attibute wdui_visibility...and den pass value 1 or 2 and bind this attribute to the visibility property of the button so that the button will be visible for the first time only and afetr getting preesed it will be invisible preventing any further click...

i think this will solve your problem.

Regards,

Sahai.S

rub_alfonso
Explorer
0 Kudos

Hi sahai.s.

First of all, thank u for your response but is not enought to solve my problem.

The way you do, is to create the PDF document, not to print PDF by my local printer (the one that is near me and the one that is able to print Smartforms ).

I´m looking for a way (if exist) to communicate the Web Dynpro with my local printer wthout using ADOBE´s standard print button (the one which appears when you show the PDF on the WD).

Thank you !!

Former Member
0 Kudos

Hi,

You can always restrict the use of the button which will trigger the smartform output.

Just maintain a flag.

Thanks

Sayan

rub_alfonso
Explorer
0 Kudos

Hi Jana,

that flag should be marked when the user push "print" button on the web dynpro and the document come out by the local printer.

So I'm looking for a way to print PDF documents by the local printer without using ADOBE's standard functionality ...

Thanks !!