Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member182040
Active Contributor

1: convert otf to pdf file

2: download pdf file into application server

3:encrypt pdf file with password protect

4:upload pdf file from application server

5:send mail

      OTR TO PDF

FORM pdf .
CLEAR gt_otf.
REFRESH gt_otf .
gt_otf[]
= it_otfdata[].
*• Convert the OTF DATA to SAP Script Text lines
CLEAR gt_pdf_tab.

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format                      = 'PDF'
max_linewidth              
= 132

IMPORTING
bin_filesize               
= gv_bin_filesize
*   BIN_FILE                    =
TABLES
otf                        
= gt_otf
lines                       = gt_pdf_tab
EXCEPTIONS
err_max_linewidth          
= 1
err_format                 
= 2
err_conv_not_possible      
= 3
err_bad_otf                
= 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.


PERFORM download.
PERFORM pssword_prot_encryptpdf .
PERFORM send_mail.
ENDFORM.                   

     Then download pdf file into application server using following code

FORM download .
*
DATA: l_file TYPE string  .
CONCATENATE  'd:\pdf/' main_dtl-vbeln '.PDF' INTO l_file.

OPEN DATASET l_file FOR OUTPUT IN BINARY MODE  .
IF  sy-subrc = 0 .
LOOP AT gt_pdf_tab.
TRANSFER gt_pdf_tab TO l_file .
ENDLOOP.
CLOSE DATASET l_file  .
ELSE.
WRITE : / 'operating system could not open file' .
ENDIF.

ENDFORM.     

  

  • Then  use command line mode Encryptpdf, from verypdf.com,
  • so successfuly file encrypted and password protected.
  • Also you have to create external operating system command (SM69)

       ZTEST is external command

FORM pssword_prot .

DATA: BEGIN OF command_list OCCURS 0.
INCLUDE STRUCTURE sxpgcolist.
DATA: END OF command_list .


DATA: BEGIN OF exec_protocol OCCURS 0.
INCLUDE STRUCTURE btcxpm.
DATA: END OF exec_protocol.
DATA: status LIKE btcxp3-exitstat,
commandname
LIKE sxpgcolist-name VALUE 'ZTEST',

  sel_no LIKE sy-tabix.

* GET LIST OF EXTERNAL COMMANDS

CALL FUNCTION 'SXPG_COMMAND_LIST_GET'
EXPORTING
commandname    
= commandname
operatingsystem
= sy-opsys
TABLES
command_list   
= command_list
EXCEPTIONS
OTHERS          = 1.

CALL FUNCTION 'SXPG_COMMAND_CHECK'
EXPORTING
commandname               
= command_list-name
operatingsystem           
= sy-opsys
EXCEPTIONS
no_permission             
= 1
command_not_found         
= 2
parameters_too_long       
= 3
security_risk             
= 4
wrong_check_call_interface
= 5
x_error                   
= 6
too_many_parameters       
= 7
parameter_expected        
= 8
illegal_command           
= 9
communication_failure     
= 10
system_failure            
= 11
OTHERS                     = 12.

CLEAR command_list.
REFRESH command_list.
DATA: v_dir_input      TYPE sxpgcolist-parameters.
DATA: v_dir_input1      TYPE sxpgcolist-parameters.

command_list-name = 'ZTEST'.
command_list
-opsystem = 'Windows NT'.

DATA : doc  TYPE string.

data : pass type string .

  Doc = ‘invoice’.

  Pass ‘123456’.


CONCATENATE   'd:\pdf\' doc'.PDF' INTO name.
CONCATENATE 'cmd /c d:\pdf\encryptpdf.exe' '-i'  name  '-o ' name  '-u'  pass INTO v_dir_input SEPARATED BY space .

READ TABLE command_list INDEX sel_no.

CONCATENATE command_list-opcommand v_dir_input INTO command_list-opcommand SEPARATED BY space.

* CHECK AUTHORIZATION
command_list
-addpar = 'X'.
APPEND command_list.
.
CONSTANTS: c_extcom    TYPE sxpgcolist-name VALUE 'ZTEST',
c_oper     
TYPE syopsys VALUE 'Windows NT'.

DATA: t_result         TYPE STANDARD TABLE OF btcxpm.
v_dir_input 
command_list-opcommand.

CALL FUNCTION 'SXPG_COMMAND_EXECUTE'

   
EXPORTING

      commandname                  
= c_extcom

      additional_parameters        
= v_dir_input

      operatingsystem              
= c_oper

   
TABLES

      exec_protocol                
= t_result

   
EXCEPTIONS

      no_permission                
= 1

      command_not_found            
= 2

      parameters_too_long          
= 3

      security_risk                
= 4

      wrong_check_call_interface   
= 5

      program_start_error          
= 6

      program_termination_error    
= 7

      x_error                      
= 8

      parameter_expected           
= 9

      too_many_parameters          
= 10

      illegal_command              
= 11

      wrong_asynchronous_parameters
= 12

      cant_enq_tbtco_entry         
= 13

      jobcount_generation_error    
= 14

     
OTHERS                        = 15.


*
ENDFORM.                   

FORM send_mail

.

You can open file using following logic

DATA : doc  TYPE string

.

DATA: pdf TYPE REF TO cl_hrasr00_pdf_generation.

DATA : lt_data            TYPE solix_tab

DATA : doc  TYPE string.

Doc = ‘invoice’.

filename = name.

 

IF NAME IS INITIAL.


CONCATENATE   'd:\pdf\' doc '.PDF' INTO name.


filename
= name.


ENDIF

.


OPEN DATASET filename FOR INPUT IN BINARY MODE.
IF sy-subrc EQ 0.
READ DATASET filename INTO filex.
*      CLOSE DATASET filename.
ENDIF.


After that using following Functional module you can send file

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

ENDFORM.                    " SEND_MAIL









15 Comments