cancel
Showing results for 
Search instead for 
Did you mean: 

Create a PDF as attachment in custom module in mail receiver adapter

0 Kudos

I'm trying to create a PDF attachment to an email using a custom module with the following codes. The attachment was created and sent, but when I tried to open it, I got the following error message: the file cannot be read either because a invalid encoding or the file is damaged.

Anybody knew if I did anything wrong in the way I'm opening and creating the PDF attachment below?

// add a new pdf attachment to the message

FileInputStream fi = new FileInputStream("c:/ftmailxi.pdf");

byte[] attachmentContent = new byte[fi.available()];

Payload attachmentPDF = msg.createPayload();

attachmentPDF.setName("ftmailxi.pdf");

attachmentPDF.setContentType("application/pdf");

attachmentPDF.setContent(attachmentContent);

//adding our this pdf as an attachment

msg.addAttachment(attachmentPDF);

//provide the XI message for returning

inputModuleData.setPrincipalData(msg);

......

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Anyway, I resolved the issue. Special PDF handling is needed. I used iTEXT library to read and write out the PDF stream.

prateek
Active Contributor
0 Kudos

This will surly help u

/people/sravya.talanki2/blog/2006/11/28/e-mail-xml-messages-in-pdf-format-from-sap-xi

Check this out

Regards,

Prateek

0 Kudos

Thanks, all the blogs are for ABAP function modules. What I'm writing is a custom java adapter module.