cancel
Showing results for 
Search instead for 
Did you mean: 

PI 7.1 : Taking a input PDF file and mapping it to a hexBinary attribute

former_member191528
Participant
0 Kudos

Hello All,

We have a requirement which involves taking in an input PDF file and mapping it to a message type with binary attribute and sending it to an R3 system.

Can anyone please detail the steps or point us to the correct documents for setting up the scenario.

The scenario is file to Proxy adapter. The part which we need assitance is pulling up the input pdf and mapping it to binary field.

Thanks.

Kiran

Accepted Solutions (1)

Accepted Solutions (1)

former_member204873
Contributor
0 Kudos

hi,

You can create an adapter module for same by using itext libray:

http://api.itextpdf.com/

How to write PDF file:

/people/shabarish.vijayakumar/blog/2009/05/17/trouble-writing-out-a-pdf-in-xipi

Refer to links below for same:

How to create an adapter module:

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c0b39e65-981e-2b10-1c9c-fc3f8e674...

https://wiki.sdn.sap.com/wiki/display/XI/XIlibrariesfor+development

Adjust your PI 7.0 Adapter Modules for PI 7.1 in 15 minutes

/people/stefan.grube/blog/2008/12/11/adjust-your-pi-70-adapter-modules-for-pi-71-in-15-minutes

JavaDoc:

http://help.sap.com/javadocs/pi/SP3/xpi/index.html

Sample for reading an PDF file will look like:

// Create a PdfReader instance

PdfReader r = PdfReader.fileReader("sample_doc1.pdf");

// Create a PdfDocument instance with the reader

PdfDocument d = new PdfDocument(r);

// Get page count and display on console

System.out.println( -- in actual code store it to string/bytestream and add it to message payload.

"Number of pages in sample_doc1.pdf is " +

d.getPageCount());

// Close all I/O streams associated with the PDF reader

r.dispose();

Thanks.

former_member191528
Participant
0 Kudos

Thanks Mayank for all your help. We will follow up on this approach and in case we encounter any issues with it we will again come back with our findings.

Truly appreciate your help.

Thanks.

Kiran

former_member191528
Participant
0 Kudos

Hello All,

The sample example being posted is for the creating a pdf on the receiver side. We want to read a pdf assign it to an attribute on the receiver side and send the file across.

I found the following example which comes close to our requirement but can anyone tell us the sender and receiver message types to be used for the scenario.

https://wiki.sdn.sap.com/wiki/display/XI/HowtoSendBinaryDatatoRFCfromXI%28or%29PI

Thanks.

Kiran

former_member191528
Participant
0 Kudos

Thanks Sarvesh for your response. Can you please explain how can I go about the mapping in the ESR what should be my source message ?

As far as I know my Target message will be 2 elements one base64" and one file name. But how about the source message and which code I can use to read the pdf ?

Thanks.

Kiran

Former Member
0 Kudos

> But how about the source message and which code I can use to read the pdf ?

Go through this blog, which explains how to read the pdf file..

/people/sap.user72/blog/2005/07/31/xi-read-data-from-pdf-file-in-sender-adapter

Update:- I am not realy sure how much above blog will help you, but the basic idea is that we have to convert the PDF into binary (I am not sure how to do that in XI ) may be by using java mapping (if possible) otherwise you can simply use the above blog (which converts the pdf file into xml data) and sent the xml data to inbound proxy where you take this xml data into one string and convert it into Binary (there are function moudules) and then just do rest of the things..

former_member191528
Participant
0 Kudos

Hi Sarvesh,

The PDF is already in binary we have to pick it up and convert it into base64binary and then just assign it to a base64binary variable and send it across. I am working on implementing the steps whcih you have listed. Thanks for the followup.

Thanks.

Kiran

former_member191528
Participant
0 Kudos

Hi Sarvesh,

Can you please explain if the code snippet mentioned should be used as a udf and how what inpus need to be passed to it. ?

Thanks.

Kiran

former_member181985
Active Contributor
0 Kudos

>The scenario is file to Proxy adapter.

Best option is to send this as an attachment and handle it accordingly in the ABAP/Java Proxy on the receiver side..

otherwise if your proxy logic is already developed , then just modify the java mapping snippet (Java Mapping Snippet Code section) @[How to Send Binary Data to RFC from XI(or)PI |https://wiki.sdn.sap.com/wiki/display/XI/HowtoSendBinaryDatatoRFCfromXI%28or%29PI]

Remove dynamic configuration code....in that snippet

>For the mapping to my inbound I will research on Apache Commons (org.apache.commons.codec.binary.Base64) which I can use in my udf.

SAP has provided this com.sap.aii.utilxi.base64.api.*;

aii_utilxi_misc.jar (PATH: /usr/sap/<SID>/DVEBMGS<nr>/j2ee/cluster/server0/bin/ext/com.sap.xi.util.misc)

Edited by: Praveen Gujjeti on Aug 26, 2010 10:07 PM

former_member191528
Participant
0 Kudos

null

Edited by: Kiran Sakhardande on Aug 31, 2010 12:55 AM

Edited by: Kiran Sakhardande on Aug 31, 2010 12:57 AM

former_member191528
Participant
0 Kudos

Thanks Praveen,Mayank,Sarvesh and Andreas for your valuable help with the issue.

I was able to successfully pick up the binary PDF file from a file server , encode it using Base 64 and post it to R3.

I used the following code snippet and added the mentioned jar files to create a new jar file which was used as java mapping in the operation mapping.

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.*;

import com.sap.aii.utilxi.base64.api.*;

import java.io.*;

import java.util.*;

public class Base64EncodingXIStandard implements StreamTransformation{

String fileNameFromFileAdapterASMA;

private Map param;

public void setParameter (Map map)

{

param = map;

if (param == null)

{

param = new HashMap();

}

}

public static void main(String args[])

{

Base64EncodingXIStandard con = new Base64EncodingXIStandard();

try

{

InputStream is = new FileInputStream(args[0]);

OutputStream os = new FileOutputStream(args[1]);

con.execute(is, os);

}

catch (Exception e)

{

e.printStackTrace();

}

}

public void execute(InputStream inputstream, OutputStream outputstream)

{

DynamicConfiguration conf = (DynamicConfiguration) param.get("DynamicConfiguration");

DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

fileNameFromFileAdapterASMA = conf.get(KEY_FILENAME);

if (fileNameFromFileAdapterASMA == null)

{

fileNameFromFileAdapterASMA = "ToBase64.txt";

}

try

{

while ((len = inputstream.read(buffer)) > 0)

baos.write(buffer, 0, len);

str = Base64.encode(baos.toByteArray()); //buffer);

outputstream.write("<?xml version=\"1.0\" encoding=\"utf-8\"?><ROOT>".getBytes());

outputstream.write(("<FILENAME>" + fileNameFromFileAdapterASMA + "</FILENAME>").getBytes());

outputstream.write( ("<BASE64DATA>" + str + "</BASE64DATA></ROOT>" ).getBytes());

}

catch(Exception e)

{

e.printStackTrace();

}

}

byte[] buffer = new byte[1024*5000];

ByteArrayOutputStream baos = new ByteArrayOutputStream();

int len;

String str = null;

}

I had to do the following configuration settings

1) Create a Sender Comm Channel with Adapter Specific message attributes and Filename checkbox checked.

2) Use the Java Mapping in the Operation mapping.

The scenario is working smoothly with out any issues.

Thanks.

Kiran

Answers (1)

Answers (1)

Former Member
0 Kudos

try using a java mapping. In this you can use the Apache Commons (org.apache.commons.codec.binary.Base64) library to convert base64 values from and to binary. This spares you the touble of developing an adapter module.

For the inbound message you can use any datatype.

former_member191528
Participant
0 Kudos

Thanks Andreas !! Can you please explain what should be the data type of my input message and how do I capture the input pdf in my outbound binary input message. For the mapping to my inbound I will research on Apache Commons (org.apache.commons.codec.binary.Base64) which I can use in my udf.

Thanks.

Kiran