Replace words into a document by script operation

Hello

I have a process to send by email a document with the data of the customer to be sign in by him.

The document is loading when the process execute( in each case)

After a user start a case, el process execute a script task to replace keywords for the customer's data.

This is my code in the taks's operation section:

import java.nio.charset.Charset
import java.nio.charset.CharsetEncoder

import org.bonitasoft.engine.bpm.document.Document
import org.bonitasoft.engine.bpm.document.DocumentValue
import org.codehaus.groovy.runtime.EncodingGroovyMethods

import java.nio.charset.StandardCharsets;

Document doc =apiAccessor.getProcessAPI().getDocument(docuActaAcuerdo.getId());

String storageId = doc.getContentStorageId();

byte[] content =  apiAccessor.getProcessAPI().getDocumentContent(storageId);


String texto =  new String(content,StandardCharsets.UTF_8);

texto = texto.replace("keyWord", solicitud.getLastName());


return new DocumentValue(texto.getBytes(StandardCharsets.UTF_8),"application/pdf","acta.pdf");

 

The process and task execute with out errors, but when I try to open de generated document, is empty because I thought that te problem was here:String texto =  new String(content,StandardCharsets.UTF_8);

 

Any help?

 

Thanks a Lot