Here is a script that will save each document in the active book as an .htm file. To use it, copy it to an empty text file and save it with a .jsx extension. Then open your book and choose File > Script > Run and choose the script. Please let me know if you have any questions or comments.
#target framemaker
main ();
function main () {
var book;
book = app.ActiveBook;
if (book.ObjectValid () === 1) {
processBook (book);
}
else {
alert ("There is no active book.", "www.frameexpert.com");
}
}
function saveAsHtml (doc) {
var params, returnParams, saveName, i;
saveName = doc.Name.replace (/\.[^\.]+$/, ".htm");
params = GetSaveDefaultParams ();
returnParams = new PropVals ();
i = GetPropIndex (params, Constants.FS_FileType);
params.propVal.ival = Constants.FV_SaveFmtFilter;
i = GetPropIndex (params, Constants.FS_SaveFileTypeHint);
params.propVal.sval = "0001ADBEHTML ";
doc.Save (saveName, params, returnParams);
}
function processBook (book) {
var bookComp = 0, doc = 0;
// Loop through all of the components in the book.
bookComp = book.FirstComponentInBook;
while (bookComp.ObjectValid ()) {
// Get the document returned in a JavaScript object.
doc = getDocument (bookComp.Name);
if (doc) {
book.StatusLine = "Processing " + File(bookComp.Name).displayName;
// Call the function to process the document.
saveAsHtml (doc);
// If the document was opened by the script, close it.
if (doc.openedByScript === true) {
doc.Close (true);
}
}
bookComp = bookComp.NextBookComponentInDFSOrder;
}
// Reset the book status line.
book.StatusLine = "";
}
function getDocument (filename) {
// See if the document is already open.
var doc = docIsOpen (filename);
if (doc) {
return doc;
} else {
// The document is not already open, so open it.
return openDocOrBook (filename, undefined, false);
}
}
function docIsOpen (filename) {
// Make a File object from the file name.
var file = File (filename);
// Uppercase the filename for easy comparison.
var name = file.fullName.toUpperCase ();
// Loop through the open documents in the session.
var doc = app.FirstOpenDoc;
while (doc.ObjectValid () === 1) {
// Compare the document’s name with the one we are looking for.
if (File (doc.Name).fullName.toUpperCase () === name) {
// The document we are looking for is open.
doc.openedByScript = false;
return doc;
}
doc = doc.NextOpenDocInSession;
}
}
function openDocOrBook (filename, structuredApplication, visible) {
var i = 0, docOrBook = 0;
// Get default property list for opening documents.
var openProps = GetOpenDefaultParams ();
// Get a property list to return any error messages.
var retParm = new PropVals ();
// Set specific open property values to open the document.
i=GetPropIndex (openProps,Constants.FS_AlertUserAboutFailure);
openProps.propVal.ival=false;
i=GetPropIndex (openProps,Constants.FS_MakeVisible);
openProps.propVal.ival=visible;
i=GetPropIndex (openProps,Constants.FS_FileIsOldVersion);
openProps.propVal.ival=Constants.FV_DoOK;
i=GetPropIndex (openProps,Constants.FS_FileIsInUse);
openProps.propVal.ival=Constants.FV_ResetLockAndContinue;
i=GetPropIndex (openProps,Constants.FS_FontChangedMetric);
openProps.propVal.ival=Constants.FV_DoOK;
i=GetPropIndex (openProps,Constants.FS_FontNotFoundInCatalog);
openProps.propVal.ival=Constants.FV_DoOK;
i=GetPropIndex (openProps,Constants.FS_FontNotFoundInDoc);
openProps.propVal.ival=Constants.FV_DoOK;
i=GetPropIndex (openProps,Constants.FS_RefFileNotFound);
openProps.propVal.ival=Constants.FV_AllowAllRefFilesUnFindable;
if (structuredApplication !== undefined) {
i=GetPropIndex (openProps,Constants.FS_StructuredOpenApplication);
openProps.propVal.sval=structuredApplication;
}
// Attempt to open the document.
docOrBook = Open (filename,openProps,retParm);
if (docOrBook.ObjectValid () === 1) {
// Add a property to the document or book, indicating that the script opened it.
docOrBook.openedByScript = true;
}
else {
// If the document can't be open, print the errors to the Console.
PrintOpenStatus (retParm);
}
return docOrBook; // Return the document or book object.
}