base64 corrupting bytes


I am currently working on the following process :
pooling a directory containing pdf, then encapsulate each pdf into an xml file .

To encapsulate the pdf into the xml document , I encode its bytes content into a base 64 string.
Unfortunately, this base64 encoding cause the corruption of the pdf .

Description of my process :

pub.file:getFile (load as bytes, encoding=UTF-8 )

For the tests, I have used pub.string:base64Decode in order to compare bytes before/after. And the bytes after process are not equals to the original ones.

Did you already encounter such issue ?

Can you share your bytes data from the step pub.file:getFile (load as bytes, encoding=UTF-8 )

And also the bytes before/after for comparison. I assume we can code a java service.

Hi Julien,

You better go with java service for this requirement which is easy i believe.


Or you can give a try for PSUtilities-Package, which should be available in the community software downloads.

This Package also contains base64 coding services.



Thanks for your answers. I don’t know how to share the bytes( ?? )

Anyway : I progressed since this morning :

My pdf contain an image and after processing (I send the xml capsule and a distant service extract the pdf)
The extract pdf can be opened but generate an error in ACreader. The image is no more visible.

After opening the pdf editor, it appear that there is a stream included in the pdf file (pretty sure it is the image)
This is the part which is corrupted by the base64encode.

I tried a javaservice using org.apache.commons.codec.binary.Base64 : Base64.encodeBase64(bytes)

Same result. I am not sure that is is possible to do what I want as the pdf is a combination of bytes and stream.

What I don’t understand anyway, is that I can send me properly the pdf using the pub.client.SMTP service passing the bytes into attachments and specifying encoding = “base64”

Really strange…


The remaining problem was due to a wrong decode.

The original problem was due to the use of pub.string:base64Encode .

So, for such things, use a java service :

byte[] bytesToWrite = null;
String base64Encoded="";
// pipeline
IDataHashCursor pipelineCursor = pipeline.getHashCursor();
if ( pipelineCursor.first( "bytesToWrite" ) ){
	bytesToWrite = (byte[]) pipelineCursor.getValue();
	throw new ServiceException("bytesToWrite not specified");

try { 
base64Encoded= new String(Base64.encodeBase64(bytesToWrite));
} catch (Exception ioe) { 
	throw new ServiceException("IOException: " + ioe.getMessage()); 
} finally {  


// Place outputs into pipeline 
pipelineCursor.insertAfter("base64Encoded", base64Encoded); 

Thanks all for your help !

Yes this is the code I was talking about.

Can you also share your import statements. It might be useful for other forum members.

Have a nice week off :slight_smile:


You can use the below as part of imports.*

@Mahesh: Definitly it is useful to other members including you :stuck_out_tongue:


@MR as173d,
Dude, Are you kidding :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: I guess there are some more imports missing!

The only one import : org.apache.commons.codec.binary.Base64


Thanks… Not sure whether you have tried using the below import:


I see for the import : org.apache.commons.codec.binary.Base64 you need apache jars to be installed in your IS. Correct me if I am wrong.