*&---------------------------------------------------------------------* *& Report /GRUBE/PDF_TEST_SPOOL_TO_PDF * *& * *&---------------------------------------------------------------------* *& Convert Spool Request to PDF and encrypt it with RC4 or AES * *& Add an additional single Watermark to the encrypted PDF * *&---------------------------------------------------------------------* * Selection Texts * P_128 RC4 Keylength 128 bit * P_128A AES Keylength 128 bit * P_256A AES Keylength 256 bit * P_40 RC4 Keylength 40 bit * P_80 RC4 Keylength 80 bit * P_ACCESS Enable Accessibility * P_ANNOT Add Annotations * P_ASSEM Assemble the document * P_BMP Watermark - Bitmap File * P_COPY Copy or extract text * P_FIELDS Fill fields * P_HIRES Print in High Resolution * P_MODIFY Modify the document * P_OPA Watermark Opacity 0 - 255 * P_OPASS Owner Password * P_OUTPUT PDF Output File * P_PRINT1 Allow Printing * P_SPOOL Spool ID * P_UPASS User Password report /grube/pdf_test_spool_to_pdf1 . types: begin of t_a , line(60) type x, end of t_a. data: a type table of t_a. data: file type file_table. data: files type filetable. data: rc type i. data: data_lines type /grube/raw256_table. data: o_bitmap type ref to /grube/cl_pdf_bitmap. data: fl type string. data: len type i. data: lt_pdf type table of tline. data: l_pdf type tline. data: l_tsp01 type tsp01. data: l_spool type rspoid. data: result type xstring. parameters : p_spool type rqident obligatory . parameters : p_output type filename obligatory lower case. parameters : p_bmp type filename lower case. parameters : p_opa type int4 default 48. selection-screen skip 1. parameters: p_upass(16) type c lower case. parameters: p_opass(16) type c lower case. selection-screen skip 1. parameters: p_40 radiobutton group kl. parameters: p_80 radiobutton group kl. parameters: p_128 radiobutton group kl. parameters: p_128a radiobutton group kl. parameters: p_256a radiobutton group kl. selection-screen skip 1. parameters : p_print1 as checkbox default 'X'. parameters : p_modify as checkbox default ' '. parameters : p_copy as checkbox default 'X'. parameters : p_annot as checkbox default 'X'. parameters : p_fields as checkbox default ' '. parameters : p_access as checkbox default 'X'. parameters : p_assem as checkbox default ' '. parameters : p_hires as checkbox default 'X'. at selection-screen on value-request for p_output. * determine the name of the output PDF file call method cl_gui_frontend_services=>file_open_dialog changing file_table = files rc = rc. if rc = 1. read table files into file index 1. p_output = file-filename. endif. at selection-screen on value-request for p_bmp. * determine the name of the BMP watermark file * the white parts of the BMP are transparent call method cl_gui_frontend_services=>file_open_dialog changing file_table = files rc = rc. if rc = 1. read table files into file index 1. p_bmp = file-filename. endif. start-of-selection. l_spool = p_spool. if not p_bmp is initial. * create and upload watermark * only if the user specifies a bitmap file fl = p_bmp. call method cl_gui_frontend_services=>gui_upload exporting filename = fl filetype = 'BIN' importing filelength = len changing data_tab = a. data: l_a type t_a. data: x_bmp type xstring. loop at a into l_a. concatenate x_bmp l_a-line into x_bmp in byte mode. endloop. create object o_bitmap exporting opacity = p_opa. * load the bitmap as XString o_bitmap->set_graphic_xstring( x_bmp ). endif. * select the spool request from the mail spool table select single * from tsp01 into l_tsp01 where rqident = p_spool. if sy-subrc <> 0. write: / 'Cannot find Spool Request'. exit. endif. * convert the spool into PDF (standard SAP function) if l_tsp01-rqdoctype = 'SMART' or l_tsp01-rqdoctype = 'OTF'. * SAPScript and Smartforms call function 'CONVERT_OTFSPOOLJOB_2_PDF' exporting src_spoolid = l_spool no_dialog = 'X' tables pdf = lt_pdf exceptions err_no_otf_spooljob = 1 err_no_spooljob = 2 err_no_permission = 3 err_conv_not_possible = 4 err_bad_dstdevice = 5 user_cancelled = 6 err_spoolerror = 7 err_temseerror = 8 err_btcjob_open_failed = 9 err_btcjob_submit_failed = 10 err_btcjob_close_failed = 11 others = 12. if sy-subrc <> 0. write: / 'Error when converting spool to PDF'. exit. * Implement suitable error handling here endif. else. call function 'CONVERT_ABAPSPOOLJOB_2_PDF' exporting src_spoolid = l_spool no_dialog = 'X' tables pdf = lt_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 err_btcjob_submit_failed = 10 err_btcjob_close_failed = 11 others = 12. if sy-subrc <> 0. write: / 'Error when converting spool to PDF'. exit. endif. endif. * convert the PDF table into xstring field-symbols: type x. loop at lt_pdf into l_pdf. assign l_pdf to casting. concatenate result into result in byte mode. endloop. data: o_pdf type ref to /grube/cl_pdf. data: o_encrypt_rc4 type ref to /grube/cl_pdf_encryption_rc4. data: o_encrypt_aes type ref to /grube/cl_pdf_encryption_aes. data: o_encrypt_aes256 type ref to /grube/cl_pdf_encry_aes_256. data: o_encrypt type ref to /grube/cl_pdf_encryption. * create the PDF object create object o_pdf. * load the PDF into the object (XString) o_pdf->set_pdf_file( result ). if not p_bmp is initial. * add the watermark only if the bitmap is specified o_pdf->add_watermark_position( bmp = o_bitmap sizex = 150 sizey = 120 x = 20 y = 60 as_background = ' ' ). endif. data: upass type string. data: opass type string. upass = p_upass. opass = p_opass. * specify the encryption and the keylength if p_128a = 'X'. * AES 128 bit create object o_encrypt_aes exporting keylength = 128 . o_encrypt ?= o_encrypt_aes. endif. if p_256a = 'X'. * AES 256 bit create object o_encrypt_aes256 exporting keylength = 256 . o_encrypt ?= o_encrypt_aes256. endif. if p_128 = 'X'. * RC4 128 bit create object o_encrypt_rc4 exporting keylength = 128 . o_encrypt ?= o_encrypt_rc4. endif. if p_40 = 'X'. * RC4 40 bit create object o_encrypt_rc4 exporting keylength = 40 . o_encrypt ?= o_encrypt_rc4. endif. if p_80 = 'X'. * RC4 80 bit create object o_encrypt_rc4 exporting keylength = 80 . o_encrypt ?= o_encrypt_rc4. endif. * set the user permissions for the PDF file o_encrypt->set_permission_ex( print_allowed = p_print1 modify_allowed = p_modify copy_allowed = p_copy add_annotations_allowed = p_annot fill_fields_allowed = p_fields copy_accessibility_allowed = p_access assemble_allowed = p_assem print_highres_allowed = p_hires ). * set the user and the owner password for the PDF o_encrypt->set_passwords( user_password = upass owner_password = opass ). * generate the passwords o_encrypt->generate_passwords( o_pdf ). * encrypt the PDF o_pdf->do_action( o_encrypt ). * get the encrypted and processed PDF xstring * if requested the watermark and the trailing pages are included result = o_pdf->create_pdf( ). * just download the resulting PDF to the local desktop PC data: len1 type i. len1 = xstrlen( result ). data_lines = /grube/cl_pdf=>convert_xstring_2_table( result ). fl = p_output. call method cl_gui_frontend_services=>gui_download exporting bin_filesize = len1 filename = fl filetype = 'BIN' changing data_tab = data_lines.