打开与关闭文档
打开文档
在iWebPDF2018集成示例中,参考JS中的WebOpen方法,里面调用的是控件的open方法,用于打开服务器文件。
调用示例
function WebOpen() { iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.WebUrl = url + "PDFServer.jsp"; var tempFile = iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.CreateTempFileName(); iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.SetMsgByName("DBSTEP","DBSTEP"); iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.SetMsgByName("OPTION","LOADFILE"); iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.SetMsgByName("FILETYPE","PDF"); iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.SetMsgByName("USERNAME","演示人"); iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.SetMsgByName("RECORDID",mRecordID); iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.SetMsgByName("FILENAME","1385716767003.pdf"); alert(tempFile); if ( iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.PostDBPacket(false)) { iWebPDF.COMAddins.Item("KingGrid.MsgServer2000").Object.MsgFileSave(tempFile); iWebPDF.Documents.Open(tempFile); addState("打开成功"); } else { addState("打开失败"); } }
if (mOption.equalsIgnoreCase("LOADFILE")) { //下面的代码为打开服务器数据库里的文件 mRecordID = MsgObj.GetMsgByName("RECORDID"); //取得文档编号 mFileName = MsgObj.GetMsgByName("FILENAME"); //取得文档名称 mFileType = MsgObj.GetMsgByName("FILETYPE"); //取得文档类型 MsgObj.MsgTextClear(); //清除文本信息 //if (MsgObj.MsgFileLoad(mFilePath+"Document111.pdf")) //从文件夹调入文档 //{ if (LoadFile()) { //从数据库调入文档 MsgObj.SetMsgByName("STATUS", "打开成功!"); //设置状态信息 MsgObj.MsgError(""); //清除错误信息 } else { MsgObj.MsgError("打开失败!"); //设置错误信息 } }
关闭文档
当用户打开文档,编辑完成后需要关闭当前的PDF文档时,可以通过调用Close方法来实现。
调用示例
//关闭当前的文档 function CloseFile(){ if ( 0 == iWebPDF.Documents.Count ){ alert("没有已打开文档"); return; } iWebPDF.Documents.ActiveDocument.Close(); }