Skip to Content
Technical Articles
Author's profile photo Aditya Pattnayak

How to Send Password protected PDF file from ECP


Technology evolves in a rapid pace in this modern era.  ECP is a niche skill in the world of Human capital management. In ECP, we need to password protect attachments while sending the sensitive data .Otherwise It will create privacy related non compliance issues. This blog will explain the process to send password protected PDF file ECP to external email id.


The requirement is to send a password protected PDF file from ECP to external email id.


In ERP system, we can send password protected file with or without third party software. But we have to use command line to make it happen. We have to use the below function module to run the command line.


Please check below blogs on how to send password protected PDF fine in ERP system.

But in ECP, we can not execute command line. So we need to follow different approach for that.

We have to use CPI to password protect the PDF file.


  • First we need to convert the data into PDF format. For eg if we are reading the data from spool, then use the below function module to covert the data to PDF.                                  CALL FUNCTION ‘CONVERT_OTFSPOOLJOB_2_PDF’
  • We need to write the data to a temp file in application server and then read the file from application server for proper formatting of PDF data.
  • We have to convert the data to BASE64 format using SCMS_BASE64 _ENCODE_STR function module
  • We need  to send the data to CPI.
  • We need to use the class CL_HTTP_CLIENT=>CREATE_BY_DESTINATION to instantiate the object.
  • Fill the headers and set the URI by CL_HTTP_UTILITY=>SET_REQUES_URI
  • We will send PDF file attachment data in base64 and password information along with the email id.
  • Get the http response and mark it successful if the the response code is 200



Please check the below blog if you want to get detail on how to send file in ECP

There are open source scripts available to password protect the pdf file which can used in CPI.


CPI is the key to integration in ECP. There are also public API available in Adobe to encrypt the PDF file. Do let me know if this was helpful and share if you think it is useful. Please do reach out to me if you need any further clarifications.



Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo AKSHAY RUIA

      Hi Aditya,

      Thanks for the blog.

      Can you please help with password protect script. I have a script to add the password, however, the related libraries are not available to add.

      Can you please some details how to add the script code for adding password to base 64.

      below is the sample code snippet.

      private static String USER_PASSWORD = "password";
      private static String OWNER_PASSWORD = "naveen";
      public static void main(String[] args) throws IOException {
          Document document = new Document();
               PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("E:\\HelloWorld.pdf"));
               writer.setEncryption(USER_PASSWORD.getBytes(),OWNER_PASSWORD.getBytes(), PdfWriter.ALLOW_PRINTING,PdfWriter.ENCRYPTION_AES_128);
               document.add(new Paragraph("This is Password Protected PDF document."));
            } catch (DocumentException e)
            } catch (FileNotFoundException e)
      Thanks & Regards,
      Akshay Ruia