Skip to Content
0

Java Mapping to read pdf and convert to xml

May 15, 2017 at 05:35 AM

163

avatar image

Hi All,

I have a java mapping to convert pdf to xml .It works fine when I test in eclipse .But it is not working when I test in SAP PO.

Below is the code ,can anyone check what might be the issue?


package com.sap.pi.customjavamap;

import java.io.*;

import com.lowagie.text.pdf.PdfReader;

import com.lowagie.text.pdf.parser.PdfTextExtractor;

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

public class ReadPDF extends AbstractTransformation {

@Override

public void transform(TransformationInput inTrans, TransformationOutput outTrans)

throws StreamTransformationException {

try {

FileInputStream is = (FileInputStream) inTrans.getInputPayload().getInputStream();

FileOutputStream os = (FileOutputStream) outTrans.getOutputPayload().getOutputStream();

PdfReader reader = new PdfReader(is);

PdfTextExtractor pdf = new PdfTextExtractor(reader);

String finalXML = "";

finalXML += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"+

"<ns0:signedDoc xmlns:ns0=\"http://proximus.com/CA/Basware/sgnDoc/v1\">";

finalXML=finalXML+"\n<signedDocType>";

finalXML=finalXML+pdf.getTextFromPage(1);

finalXML=finalXML+"\n</signedDocType>"+"\n</ns0:signedDoc>";

byte by[] = finalXML.getBytes();

os.write(by);

reader.close();

os.close();

}

catch (Exception e) {

getTrace().addInfo("Exception Occurred" + e.getMessage());

}

}

}

Thanks,

Sahana

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

0 Answers