Each notes in a .ppt file is an entry in the OLE file system. In this
sense, adding of notes is pretty much similar to adding a new slide.
A prototype of the SlideShow.createNotes() method might look as follows:
public Notes createNotes() {
SlideListWithText slist = null;
// Register a new Notes in the Document
slist = _documentRecord.getNotesSlideListWithText();
if (slist == null) {
// Need to add a new one
slist = new SlideListWithText();
slist.setInstance(SlideListWithText.NOTES);
_documentRecord.addSlideListWithText(slist);
}
SlidePersistAtom prev = null;
SlideAtomsSet[] sas = slist.getSlideAtomsSets();
for (int j = 0; j < sas.length; j++) {
SlidePersistAtom spa = sas[j].getSlidePersistAtom();
if (prev == null) {
prev = spa;
}
if (prev.getSlideIdentifier() < spa.getSlideIdentifier()) {
prev = spa;
}
}
// Set up a new SlidePersistAtom for this slide
SlidePersistAtom sp = new SlidePersistAtom();
// First slideId is always 256
sp.setSlideIdentifier(prev == null ? 256 :
(prev.getSlideIdentifier() + 1));
// Add this new SlidePersistAtom to the SlideListWithText
slist.addSlidePersistAtom(sp);
// Create a new Slide
Notes notes = new Notes(sp.getSlideIdentifier(),
sp.getRefID(), _notes.length + 1);
notes.setSlideShow(this);
notes.onCreate();
// Add in to the list of Slides
Notes[] s = new Notes[_slides.length + 1];
System.arraycopy(_slides, 0, s, 0, _slides.length);
s[_slides.length] = notes;
_notes = s;
logger.log(POILogger.INFO, "Added notes " + _notes.length + "
with ref " + sp.getRefID()
+ " and identifier " + sp.getSlideIdentifier());
// Add the core records for this new Slide to the record tree
org.apache.poi.hslf.record.Notes notesRecord =
(org.apache.poi.hslf.record.Notes)notes.getSheetContainer();
int slideRecordPos = _hslfSlideShow.appendRootLevelRecord(notesRecord);
_records = _hslfSlideShow.getRecords();
// Add the new Notes into the PersistPtr stuff
int offset = 0;
int slideOffset = 0;
PersistPtrHolder ptr = null;
UserEditAtom usr = null;
for (int i = 0; i < _records.length; i++) {
Record record = _records[i];
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
record.writeOut(out);
} catch (IOException e) {
throw new HSLFException(e);
}
// Grab interesting records as they come past
if (_records[i].getRecordType() ==
RecordTypes.PersistPtrIncrementalBlock.typeID) {
ptr = (PersistPtrHolder) _records[i];
}
if (_records[i].getRecordType() ==
RecordTypes.UserEditAtom.typeID) {
usr = (UserEditAtom) _records[i];
}
if (i == slideRecordPos) {
slideOffset = offset;
}
offset += out.size();
}
// persist ID is UserEditAtom.maxPersistWritten + 1
int psrId = usr.getMaxPersistWritten() + 1;
sp.setRefID(psrId);
notesRecord.setSheetId(psrId);
// Last view is now of the slide
usr.setLastViewType((short) UserEditAtom.LAST_VIEW_SLIDE_VIEW);
usr.setMaxPersistWritten(psrId); // increment the number of persit
// objects
// Add the new slide into the last PersistPtr
// (Also need to tell it where it is)
notesRecord.setLastOnDiskOffset(slideOffset);
ptr.addSlideLookup(sp.getRefID(), slideOffset);
logger.log(POILogger.INFO, "New notes ended up at " + slideOffset);
// All done and added
return notes;
}
The second thing you need to do is to create a define a new
constructor for creating new notes (see how new slide is constructed):
public Notes(){
_header = new byte[8];
LittleEndian.putUShort(_header, 0, 15);
LittleEndian.putUShort(_header, 2, (int)_type);
LittleEndian.putInt(_header, 4, 0);
notesAtom = new NotesAtom();
ppDrawing = new PPDrawing();
ColorSchemeAtom colorAtom = new ColorSchemeAtom();
_children = new Record[] {
notesAtom,
ppDrawing,
colorAtom
};
}
Thirdly, you need to figure out how to link slides and notes. This is
a TODO for you.
Finally, you need a user-friendly method like Notes.setText(String
text) to set notes text.
That's it. The PPT spec and reverse engineering are your friends. If
something goes wrong, then try to compare your output with PowerPoint
and eliminate differences.
Regards,
Yegor
On Thu, Sep 8, 2011 at 11:32 AM, crazyjoelv <[email protected]> wrote:
> Thank You! Now I know the structure, but I'm really confused about next
> steps. It turned out, that if notes are correctly added, they are saved
> normally, so the only thing that's required is create the required
> structure, but I really can't figure out where to start from. Any ideas?
>
> --
> View this message in context:
> http://apache-poi.1045710.n5.nabble.com/ppt-Notes-tp4761497p4781557.html
> Sent from the POI - Dev mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]