cancel
Showing results for 
Search instead for 
Did you mean: 

Creating PDF file in XI using iText

Former Member
0 Kudos

Hi all,

I am trying to create a PDF file in XI using itext. The PDF file is getting created in my target ftp server but I am not able to open the PDF. It is throwing the below error while opening.

"Adobe Reader could not open the sample.pdf because it is either not a supported file or because the file has been damaged(for example,it was sent as an e mail attachment and wasn't correctly decoded)"

I am using the below code in my udf

String filename= "Sample.pdf";

try

{

Document document= new Document();

PdfWriter pdfwriter=PdfWriter.getInstance(document,new FileOutputStream(filename));

document.open();

document.add(new Paragraph("Hi How are you?"));

document.close();

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

conf.put(key,filename);

}

catch(Exception e)

{

}

return "";

Kindly let me know if you have any information on this.

With Regards

jaisu.

Edited by: jaisu118 on Feb 12, 2010 8:04 AM

Accepted Solutions (0)

Answers (2)

Answers (2)

Shabarish_Nair
Active Contributor
0 Kudos

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

can you refer that?

the output should be from a mapping (java) or a module

in your case it is a uDF and i dont think it will work.

rajasekhar_reddy14
Active Contributor
0 Kudos

Hi,

please check in some JAVA forums,the code what you have written is correct or not.

develop one standalone java program test it,if it working fine then you can use the same in UDF.

Regards,

Raj

Former Member
0 Kudos

Hi Raj,

Thanks for your reply.

I have tested the code in Eclipse and it is working fine. I am able to open the PDF file and see the data.

With Regadrs

jaisu.

former_member204873
Contributor
0 Kudos

hi,

Check this thread:

Thanks.

Former Member
0 Kudos

Hi Mayank,

Thanks for your reply.

Did you use javamapping or UDF?

Do we need to updaload any external jars? If yes what are they?

If possible can you please post the entire code with which you were able to generate the pdf file.

Thanks

jaisu

former_member204873
Contributor
0 Kudos

hi,

I had used custom adapter module for creating the PDF file.

you have to use java mapping if you want to create pdf without using adapter module.

You need to import iText library available at http://itextpdf.com/.

code may look like this:

import java.io.BufferedReader;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.Reader;

//1. AbstractTransformation class is imported.

// The associated jar file is: com.sap.xpi.ib.mapping.lib.jar

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

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

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

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

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

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

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

public class xyz extends AbstractTransformation {

public void transform(TransformationInput inp, TransformationOutput out) throws StreamTransformationException {

getTrace().addInfo("JAVA Mapping Called");

InputStream inData = inp.getInputPayload().getInputStream();

// pdf conversion code

out.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));

}}

check http://help.sap.com/javadocs/pi/SP3/xpi/index.html for java mapping api.

Thanks.