on 01-21-2013 8:09 AM
Hello Experts,
I am trying to convert XML to PDF using XSLFO. The code works fine in local NWDS. I have uploaded the relevant jar files as well into PI (7.3 Version) and executed end to end scenario. The Scenario is from File to File. I am placing an XML File but the PDF File is is emptyin the target folder. So I have tried to create an attachment in SAP PI with below code.
OutputAttachments outAttach = arg1.getOutputAttachments();
Attachment attOut = outAttach.create("PDF_Output.pdf",outStream.toByteArray());
outAttach.setAttachment(attOut);
I couldnt see any attachments in the moni/channel monitoring. The Mapping seem to work successfully without any failures.
Can you please help me out in creating attachments in SAP PI. I have already referred to below links
http://scn.sap.com/docs/DOC-26528
http://scn.sap.com/thread/1918880
http://scn.sap.com/thread/1953315
Regards,
N. Jayanth Kumar.
Can you attach the java program file? Since it is file to file scenario no need to go for attachments.
Check my other blogs which will collectively help in such situations
Regards,
Praveen Gujjeti
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Praveen,
I have used the below code. I am using XSLFO for XML to PDF conversion. It works well in local system, when run through NWDS, but not working in PI. It doesnt throw any error at all when executed in PI. When I saw the Log viewer, it is throwing error in Parsing. I have uploaded all relevant jar files onto PI (7.3 Version) ESR. Request you to please provide your valuable suggestions.
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.pdf.PDFRenderer;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class xml_to_pdf extends AbstractTransformation {
private Map param;
BufferedReader docInput;
String inputLine = "";
private String finalOutput = "";
StringBuffer inputData = new StringBuffer();
StringBuffer outputData = new StringBuffer();
InputStream fin_xsl = getClass().getResourceAsStream("/xslfo_xslt/XSLT.txt");
InputStream inputStream = null;
OutputStream outputStream = null;
public xml_to_pdf() throws Exception
{
docInput = null;
}
public void setParameter(Map param) {
// TODO Auto-generated method stub
this.param = param;
if (param == null) {
this.param = new HashMap();
}
}
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException
{
//An info message is added to trace. An instance of trace of object is obtained by calling
// the getTrace method of class AbstractTransformation
getTrace().addInfo("JAVA Mapping Called");
try
{
inputStream = arg0.getInputPayload().getInputStream();
outputStream = arg1.getOutputPayload().getOutputStream();
}
catch (Exception e)
{
throw new StreamTransformationException("Unable to parse input document - ".concat(e.getMessage()));
}
//the XSL FO file
// the XML file from which we take the name
StreamSource source = new StreamSource(inputStream);
// creation of transform source
StreamSource transformSource = new StreamSource(fin_xsl);
try
{
// Initializing Trace
docInput = new BufferedReader(new InputStreamReader(inputStream));
}
catch (Exception e)
{
throw new StreamTransformationException("Unable to parse input document - ".concat(e.getMessage()));
}
// create an instance of fop factory
getTrace().addInfo("create an instance of fop factory \n");
FopFactory fopFactory = FopFactory.newInstance();
// a user agent is needed for transformation
getTrace().addInfo("a user agent is needed for transformation \n");
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
//System.out.println("Renderer Override : "+ foUserAgent.getRendererOverride().toString());
// to store output
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
Transformer xslfoTransformer;
//Setup XSLT
getTrace().addInfo("Conversion beginning \n");
try
{
xslfoTransformer = getTransformer(transformSource);
Fop fop;
try
{
PDFRenderer pdfRenderer = new PDFRenderer();
pdfRenderer.setUserAgent(foUserAgent);
foUserAgent.setRendererOverride(pdfRenderer);
getTrace().addInfo("Starting conversion \n");
fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, outStream);
getTrace().addInfo("Before XSLT");
getTrace().addInfo("After XSLT");
//Set the value of a <param> in the stylesheet
//transformer.setParameter("versionParam", "2.0");
// Resulting SAX events (the generated FO)
// must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Setup input for XSLT transformation
//transformer.transform(source, res);
xslfoTransformer.transform(source,res);
//Writing the content to Output Stream
outputStream.write(outStream.toByteArray());
outputStream.close();
}
catch (Exception e) {
//throw e;
System.out.println("Error caught "+e.toString());
getTrace().addInfo("Error caught "+e.toString());
}
}
catch (Exception e)
{
//throw e;
System.out.println("Error here"+e.toString());
getTrace().addInfo("Error caught "+e.toString());
}
System.gc();
}
private Transformer getTransformer(StreamSource streamSource)
{
// setup the xslt transformer
net.sf.saxon.TransformerFactoryImpl impl = new net.sf.saxon.TransformerFactoryImpl();
try {
return impl.newTransformer(streamSource);
} catch (TransformerConfigurationException e) {
System.out.println("Error caught in get transformer "+e.toString());
//e.printStackTrace();
}
return null;
}
}
Regards,
N. Jayanth Kumar.
Hi Praveen,
I tried to execute with above code, but I am getting the below error in PI 7.3 Log Viewer.
org.apache.fop.fo.ElementMappingRegistry findFOMaker
WARNING: Unknown formatting object http://www.w3.org/1999/XSL/Format^root
Can you please let me know what could be the cause of this issue?
Regards,
N. Jayanth Kumar.
Hello,
In your operation mapping, did you check the read attachments option?
Regards,
Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Experts,
Just for an update, I would like to know if a PDF can be accessed as Payload to be placed in a target folder, if that is not possible, can we create as an attachment, use a payload swapbean to convert that into payload?
Regards,
N. Jayanth Kumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.