{
/*
Approach 1: Modifying the existing data object.
*/
// Get the existing data object from the corresponding indirect object!
PdfStream toUnicodeStream = (PdfStream)toUnicodeReference.getDataObject();
// Editing the data object...
IBuffer streamBody = toUnicodeStream.getBody();
streamBody.setLength(0); // Erases the stream content to prepare it for new content insertion.
streamBody.append("... modified ..."); // Adds arbitrary contents (NOTE: this would NOT be done in a real ToUnicode stream! We are just testing the editing functionality...).
}
else
{
/*
Approach 2: Creating a new data object.
*/
// Create a new data object!
PdfStream toUnicodeStream = new PdfStream();
// Associate the new data object to the existing indirect object, replacing the old one!
toUnicodeReference.setDataObject(toUnicodeStream);
// Editing the data object...
IBuffer streamBody = toUnicodeStream.getBody();
streamBody.append("... created ..."); // Adds arbitrary contents (NOTE: this would NOT be done in a real ToUnicode stream! We are just testing the editing functionality...).
}
toUnicodeReference.getIndirectObject().update(); // Ensures that the indirect object is updated.
}