public byte[] getData(boolean for_embedding) throws IOException {
ByteArrayOutputStream os = new ByteArrayOutputStream();
for (Iterator i = segs.keySet().iterator(); i.hasNext(); ) {
Integer sn = (Integer) i.next();
JBIG2Segment s = (JBIG2Segment) segs.get(sn);
// pdf reference 1.4, section 3.3.6 JBIG2Decode Filter
// D.3 Embedded organisation
if ( for_embedding &&
( s.type == END_OF_FILE || s.type == END_OF_PAGE ) ) {
continue;
}
if ( for_embedding ) {
// change the page association to page 1
byte[] headerData_emb = copyByteArray(s.headerData);
if ( s.page_association_size ) {
headerData_emb[s.page_association_offset] = 0x0;
headerData_emb[s.page_association_offset+1] = 0x0;
headerData_emb[s.page_association_offset+2] = 0x0;
headerData_emb[s.page_association_offset+3] = 0x1;
} else {
headerData_emb[s.page_association_offset] = 0x1;
}
os.write(headerData_emb);
} else {
os.write(s.headerData);
}
os.write(s.data);
}
os.close();
return os.toByteArray();
}
return as a single byte array the header-data for each segment in segment number
order, EMBEDDED organization, but i am putting the needed segments in SEQUENTIAL organization.
if for_embedding, skip the segment types that are known to be not for acrobat. |