Hi All,
I am facing an issue while creating the pdf from the book file. I have a book file which consists of multiple chapters some are in the same folder(where book file is present ) and some are in a different folder. I have a cross-reference for every chapter in the book file. But when I run the extends script to create a pdf then pdf created successfully but the cross-reference of those chapters which are in the different folders is broken. And Cross-reference of those chapters which are in the same folders is working normally.
Could anyone suggest me what to change in my script to take care of this cross-reference
Please find my script below.
Thanks,
Manish
--------------------------BookToPdf.jsx---------------------------------------------
var book = app.ActiveBook;
//book.BookDontUpdateReferences=0;
var n =0;
var i=3;
if(!book.ObjectValid())
{
book = app.FirstOpenBook;
//book.BookDontUpdateReferences=0;
}
if(book.ObjectValid())
{
app.ActiveBook = book;
var comp = book.FirstComponentInBook;
var name=comp.Name;
// alert("Importing Variables from"+ "\n"+ name);
var FactsFile =OpenFile(comp.Name);
while(comp.ObjectValid())
{
if(FactsFile.ObjectValid())
{
var FormatFlags = Constants.FF_UFF_VAR;
var doc = comp.NextComponentInBook;
var docFile =OpenFile(doc.Name);
doc = app.ActiveDoc;
doc.SimpleImportFormats(FactsFile, FormatFlags);
}
n++;
comp = comp.NextBookComponentInDFSOrder;
}
}
if(book.ObjectValid())
{
app.ActiveBook = book;
var comp = book.FirstComponentInBook;
var rev = comp.NextComponentInBook;
var revname=rev.Name;
// alert("Importing PageLayout and ColorDefinition from" + "\n"+ revname);
var FactsFile =OpenFile(rev.Name);
for (var i = 3; i <=n-1; i++)
{
if(comp.ComponentType == Constants.FV_BK_FILE)
if(FactsFile.ObjectValid())
{
var FormatFlags = Constants.FF_UFF_PAGE|Constants.FF_UFF_COLOR;
var doc = rev.NextComponentInBook;
var docFile =OpenFile(doc.Name);
doc = app.ActiveDoc;
doc.SimpleImportFormats(FactsFile, FormatFlags);
}
rev = rev.NextBookComponentInDFSOrder;
}
}
if(book.ObjectValid())
{
app.ActiveBook = book;
var comp = book.FirstComponentInBook;
while(comp.ObjectValid())
{
if(comp.ComponentType == Constants.FV_BK_FILE)
{
var doc=OpenFile(comp.Name);
if(doc.ObjectValid())
{
var name, saveParams, i;
doc = app.ActiveDoc;
name = doc.Name;
saveParams = GetSaveDefaultParams();
returnParams = new PropVals();
i = GetPropIndex(saveParams, Constants.FS_FileType);
saveParams[i].propVal.ival =Constants.FV_SaveFmtBinary90;
doc.Save(name, saveParams, returnParams);
}
}
comp = comp.NextBookComponentInDFSOrder;
}
}
else
alert("No book is open or active. Cannot run the script.");
var props = GetUpdateBookDefaultParams();
var index = GetPropIndex(props, Constants.FS_ShowBookErrorLog);
props[index].propVal.ival = true;
var index = GetPropIndex(props,Constants.FS_UpdateBookTextReferences);
props[index].propVal.ival = true;
var index = GetPropIndex(props,Constants.FS_UpdateBookXRefs);
props[index].propVal.ival = true;
var returnp = new PropVals();
book.UpdateBook(props, returnp);
saveAsPdf (book);
function saveAsPdf(book)
{
// alert("Preparing to save the book as pdf!");
var saveParams, name, i, baseName, status, fullName;
name = book.Name;
baseName = name.substr(0,name.lastIndexOf("."));
fullName = baseName + ".pdf";
saveParams = GetSaveDefaultParams();
returnParams = new PropVals();
i = GetPropIndex(saveParams, Constants.FS_FileType);
saveParams[i].propVal.ival =Constants.FV_SaveFmtPdf;
book.Save(fullName, saveParams, returnParams);
i = GetPropIndex(returnParams, Constants.FS_SaveNativeError);
status = returnParams[i].propVal.ival;
if (status === Constants.FE_Success)
{
return (true);
}
else
{
return (false);
}
}
/* comp = book.FirstComponentInBook;
while(comp.ObjectValid())
{
if(comp.ComponentType == Constants.FV_BK_FILE)
{
var doc=OpenFile(comp.Name);
if(doc.ObjectValid())
{
var name = doc.Name;
doc.Close(Constants.FF_CLOSE_MODIFIED);
}
}
comp = comp.NextBookComponentInDFSOrder;
}*/
function OpenFile(path)
{
var index;
props = GetOpenDefaultParams();
index = GetPropIndex(props, Constants.FS_AlertUserAboutFailure);
if(index > -1)
props[index].propVal.ival = false;
index = GetPropIndex(props, Constants.FS_FileIsInUse);
if(index > -1)
props[index].propVal.ival = Constants.FV_ResetLockAndContinue;
index = GetPropIndex(props, Constants.FS_BookIsInUse);
if(index > -1)
props[index].propVal.ival = Constants.FV_ResetLockAndContinue;
index = GetPropIndex(props, Constants.FS_LockCantBeReset);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
index = GetPropIndex(props, Constants.FS_DisallowMIF);
if(index > -1)
props[index].propVal.ival = false;
index = GetPropIndex(props, Constants.FS_DisallowXml);
if(index > -1)
props[index].propVal.ival = false;
index = GetPropIndex(props, Constants.FS_FileIsOldVersion);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
index = GetPropIndex(props, Constants.FS_FontChangedMetric);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
index = GetPropIndex(props, Constants.FS_FontNotFoundInCatalog);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
index = GetPropIndex(props, Constants.FS_FontNotFoundInDoc);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
index = GetPropIndex(props, Constants.FS_LanguageNotAvailable);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
index = GetPropIndex(props, Constants.FS_OpenAsType);
if(index > -1)
props[index].propVal.ival = Constants.FV_AUTORECOGNIZE;
index = GetPropIndex(props, Constants.FS_UpdateTextReferences);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoNo;
index = GetPropIndex(props, Constants.FS_UpdateXRefs);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoNo;
index = GetPropIndex(props, Constants.FS_UseRecoverFile);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoNo;
index = GetPropIndex(props, Constants.FS_UseAutoSaveFile);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoNo;
index = GetPropIndex(props, Constants.FS_OpenFileNotWritable);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
index = GetPropIndex(props, Constants.FS_RefFileNotFound);
if(index > -1)
props[index].propVal.ival = Constants.FV_DoOK;
returnp = new PropVals();
var file = Open(path, props, returnp);
return file;
}