In this scenario we are going to change normal pdf file into password protected file using SAP CPI.
Step 1: Create the Iflow with the desired name. In this blog I am giving the Iflow name as Dummy(As shown in the below picture).
Step 2: Connect the sender and integration process with the HTTP Sender Adapter and give the preferred HTTP address.
Step 3: Now add the itextpdf JAR file which will be used in the groovy script in the Iflow by going to references tab - archive.
Here is the link to download the JAR (https://jar-download.com/artifacts/com.itextpdf/itextpdf/5.5.13/source-code).
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.itextpdf.text.Document
import com.itextpdf.text.Paragraph
import com.itextpdf.text.pdf.PdfWriter
import com.itextpdf.text.pdf.PdfReader
import com.itextpdf.text.pdf.PdfStamper
def Message processData(Message message) {
def inputPayload = message.getBody();
def name1 = "username";
def pass1 = name1.substring(0,4);
def name2 = "password"
def pass2 = name2.substring(0,4);
def userPassword = pass1+pass2;
def reader = new PdfReader(inputPayload.getBytes());
def outputStreamProtected = new ByteArrayOutputStream();
def stamper = new PdfStamper(reader, outputStreamProtected);
stamper.setEncryption(userPassword.getBytes(), null, PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128);
stamper.close();
message.setBody(outputStreamProtected.toByteArray());
return message;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
12 | |
7 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |