*&---------------------------------------------------------------------* *& Report /GRUBE/PDF_TEST_UPLOAD_TO_PDF * *& * *&---------------------------------------------------------------------* *& Upload PDF file and encrypt it with RC4 or AES * *& Add an additional tiled 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_INPUT PDF Input File * 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_UPASS User Password report /grube/pdf_test_upload_to_pdf . 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: result type xstring. data: l_a type t_a. * parameters : p_spool type rqident obligatory . parameters : p_input type filename obligatory lower case. 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_input. * determine the name of the input 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_input = file-filename. endif. 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. * upload the input PDF files fl = p_input. call method cl_gui_frontend_services=>gui_upload exporting filename = fl filetype = 'BIN' importing filelength = len changing data_tab = a. * convert the PDF table into xstring loop at a into l_a. concatenate result l_a-line into result in byte mode. endloop. if not p_bmp is initial. refresh a. * 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: 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. 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_tiled( bmp = o_bitmap sizex = 100 sizey = 80 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.