Filenet Eform 转成 PDF 方法
By:Roy.LiuLast updated:2012-07-14
eform 是 Filenet 自带的一个表单设计器。就其本身来说,功能远远不及 lotus form , 而且 lotus form 可以和 Filenet 很好的集成在一起。
不过很多企业,不会另外花钱买 LOTUS FORM ,所以还是一直沿用了 Eform。在做Eform输出表单的时候,其实在 FILENET workplace 中是可以看到导出为PDF 文档的。
但真实的情况是,客户根本不愿意用WORKPLACE 来工作,workplace 给用户直接使用,实在是很不友好。而且 workplace (xt),一般来说是给管理员用的。终端用户使用的,都需要定制开发,调用API,或者REST API方式自己做应用。
在做应用的过程中,就有需要把EFORM 直接导出为PDF 的需求。其实是可行的。自己编码实现。
另外附上代码下载:
点击下载此文件
不过很多企业,不会另外花钱买 LOTUS FORM ,所以还是一直沿用了 Eform。在做Eform输出表单的时候,其实在 FILENET workplace 中是可以看到导出为PDF 文档的。
但真实的情况是,客户根本不愿意用WORKPLACE 来工作,workplace 给用户直接使用,实在是很不友好。而且 workplace (xt),一般来说是给管理员用的。终端用户使用的,都需要定制开发,调用API,或者REST API方式自己做应用。
在做应用的过程中,就有需要把EFORM 直接导出为PDF 的需求。其实是可行的。自己编码实现。
package com.filenet.wcm.toolkit.server.operations.contentmanager;
import com.filenet.wcm.api.*;
import com.filenet.wcm.toolkit.server.operations.util.CIConfigProperties;
import com.filenet.wcm.toolkit.server.operations.contentmanager.CEDocument;
import com.filenet.wcm.toolkit.server.operations.util.opsUtil;
import filenet.vw.api.*;
import java.io.*;
import java.util.Date;
import java.net.*;
public class CEeForms
{
private static CIConfigProperties conf = null;
private static String userId = "Administrator";
private static String password = "password";
private static String appId = "eForm2PDF";
private static ObjectStore docObjectStore = null;
private static Folder docFolder = null;
private static Session sess = null;
private static Session sess2 = null;
private static boolean error = false;
private static VWAttachment vwa = null;
private static String guidObjStore;
private static String guideFormTemplate;
private static String guideFormDocument;
private static String tmpFile = "C:\\pe";
private static GettableObject myAttachment = null;
private static opsUtil opUtils = null;
private static Document d = null;
private static void log(String message)
{
String logfilename = "C:\\Integrator.log";
try
{
if (conf==null) conf = new CIConfigProperties();
logfilename = conf.getValue("logfilename",logfilename);
FileWriter file = new FileWriter(logfilename, true);
BufferedWriter w = new BufferedWriter(file);
w.write(new Date() + ": ");
w.write(message);
w.newLine();
w.close();
}
catch (Exception e)
{
}
}
public static VWAttachment eForm2PDF
(
String hostName,
String appId,
String objStore,
VWAttachment eFormTemplate,
String eFormDocumentID,
String params,
String filename,
String docClassName,
String destFolder
)
{
log("eForm2PDF");
String myURL = "";
opUtils = new opsUtil();
VWAttachment returnAttachment = new VWAttachment();
try
{
initialize(objStore);
if (error) return null;
guidObjStore = getObjStoreGUID(objStore);
if (error) return null;
log ("GUID Object Store = "+ guidObjStore);
sess2 = opUtils.getSession();
log("ok getsession");
guideFormTemplate = eFormTemplate.getVersion();
log ("ID Form template (getVersion) = "+ guideFormTemplate);
myAttachment = opUtils.getAttachment(eFormTemplate, sess2);
Document doc = (Document)myAttachment;
guideFormTemplate = doc.getId();
log ("ID Form template (doc) = "+guideFormTemplate);
guideFormDocument = eFormDocumentID;
log ("ID Form document (doc) = "+ guideFormDocument);
myURL = "http://"+hostName+"/" + appId + "/FormServlet?" +
"cmd=image&" +
"user=" + userId + "&" +
"pwd=" +password + "&" +
"appID=" + appId + "&" +
"template=local," + guidObjStore + "." + guideFormTemplate + "&" +
"data=local," + guidObjStore + "." + guideFormDocument + "&" +
params;
URL url = new URL(myURL);
log("Opening connection to "+myURL);
URLConnection urlC = url.openConnection();
InputStream is = url.openStream();
log("Copying resource (type: "+urlC.getContentType());
Date date = new Date(urlC.getLastModified());
log(", modified on; " + date.toLocaleString() + ")...");
System.out.flush();
String fileExt = "." + params.substring( 2, 5 );
log ("writing stream to "+ tmpFile + fileExt );
FileOutputStream fos = null;
fos= new FileOutputStream(tmpFile + fileExt );
int oneChar, count=0;
while ((oneChar=is.read()) != -1)
{
fos.write(oneChar);
count++;
}
is.close();
fos.close();
log(count+" byte(s) saved to "+tmpFile + fileExt );
log("creating document (objstore = "+objStore+", class = "+docClassName+", folder= "+destFolder);
String docType = ( fileExt.compareTo( ".pdf" ) == 0 ) ? "application/pdf" : "image/tiff";
d = CEDocument.newDoc(objStore, docClassName, destFolder, tmpFile + fileExt, docType, filename );
if (d!= null)
{
log ("document successfully created");
returnAttachment.setLibraryName(objStore);
returnAttachment.setLibraryType(VWLibraryType.LIBRARY_TYPE_CONTENT_ENGINE);
returnAttachment.setType(VWAttachmentType.ATTACHMENT_TYPE_DOCUMENT);
returnAttachment.setId(d.getId());
returnAttachment.setVersion(d.getId());
log ("return attachment set");
}
}
catch (Exception e)
{
log("Error: "+e);
return null;
}
return returnAttachment;
}
private static void initialize(String objStore)
{
userId = conf.getValue("ce_user", userId);
password = conf.getValue("ce_password", password);
tmpFile = conf.getValue("ce_tmpfile", tmpFile);
sess = ObjectFactory.getSession(appId, null, userId, password);
if (sess == null)
{
error=true;
log("No session object got!");
return;
}
log("Session object okay");
if (sess.verify() == null)
{
error=true;
log("No user object got or wrong credentials!");
return;
}
log("User object okay");
objStore = conf.getValue("ce_objStore", objStore);
docObjectStore = ObjectFactory.getObjectStore(objStore, sess);
if (docObjectStore == null)
{
error=true;
log("No object store object got!");
return;
}
log("Object store object okay");
log("Initialze okay");
}
private static String getObjStoreGUID(String objStore)
{
String guid = "";
sess = ObjectFactory.getSession(appId, null, userId, password);
if (sess == null)
{
error=true;
log("No session object got!");
return null;
}
log("Session object okay");
if (sess.verify() == null)
{
error=true;
log("No user object got or wrong credentials!");
return null;
}
log("User object okay");
docObjectStore = ObjectFactory.getObjectStore(objStore, sess);
if (docObjectStore == null)
{
error=true;
log("No object store object got!");
return null;
}
log("Object store object okay");
guid = docObjectStore.getId();
return guid;
}
}
另外附上代码下载:
点击下载此文件
From:一号门
Previous:FileNet 安装 列表(Filenet install list)
Next:IBM bluepage API 查询

COMMENTS