Password Protecting PDF in ABAP

0% found this document useful (0 votes)
277 views7 pages
The document discusses encrypting a PDF file with a password in SAP. It involves: 1. Converting OTF data to a PDF file 2. Downloading the PDF file to the application server 3. Encryptin…

Uploaded by

Ricky Das
  • FORM Download Procedure
  • PDF with Password Protection
  • Command External Execution
  • Command Check Function
  • Authorization and Execution
  • Mail Sending Form

PDF with Password protection

inShare

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 max_linewidth IMPORTING bin_filesize * BIN_FILE TABLES otf lines EXCEPTIONS = gv_bin_filesize = = gt_otf = gt_pdf_tab =1 =2 = 'PDF' = 132

err_max_linewidth err_format

err_conv_not_possible =3 err_bad_otf =4 OTHERS IF sy-subrc <> 0. = 5.

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 [Link], 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\[Link]' '-i' name '-o ' name 'u' pass INTOv_dir_input SEPARATED BY space . READ TABLE command_list INDEX sel_no. CONCATENATE command_list-opcommand v_dir_input INTO command_listopcommand 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 additional_parameters operatingsystem TABLES exec_protocol EXCEPTIONS no_permission command_not_found parameters_too_long security_risk =4 =5 =1 =2 =3 = t_result = c_extcom = v_dir_input = c_oper

wrong_check_call_interface program_start_error

=6 =7

program_termination_error x_error parameter_expected too_many_parameters =8 =9

= 10

illegal_command

= 11

wrong_asynchronous_parameters = 12 cant_enq_tbtco_entry jobcount_generation_error OTHERS = 15. = 13 = 14

* 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

PDF with Password protection 
inShare  (javascript:void(0);)
1: convert otf to pdf file 
2: download pdf file into applicatio
FORM download .  
* 
DATA: l_file TYPE string  . 
CONCATENATE  'd:pdf/' main_dtl-vbeln '.PDF' INTO l_file. 
 
OPEN DATASET l
(http://scn.sap.com/servlet/JiveServlet/showImage/102-29209-1-112363/external.jpg)
FORM pssword_prot . 
  
DATA: BEGIN OF c
OTHERS          = 1. 
 
 
CALL FUNCTION 'SXPG_COMMAND_CHECK' 
EXPORTING 
commandname                = command_list-name 
oper
* CHECK AUTHORIZATION 
command_list-addpar = 'X'. 
APPEND command_list. 
. 
CONSTANTS: c_extcom    TYPE sxpgcolist-name VALUE
illegal_command               = 11 
 
      wrong_asynchronous_parameters = 12 
 
      cant_enq_tbtco_entry          =

You might also like