1、调用打印模板,并且构造书签数据成map,然后调用aspose替换书签
public ActionForward printNew(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// response.setContentType("text/html;charset=utf-8");
// response.setCharacterEncoding("UTF-8");
// String dialogDiv = "<div id=\"lui-id-83\" class=\"lui-component lui_dialog_main\" data-lui-cid=\"lui-id-83\" style=\"z-index: 61; overflow: hidden; position: fixed; width: 200px; left: 558px; top: 473.5px;\"><div class=\"lui_dialog_loading_frame\"> <div class=\"lui_dialog_loading_centerL\"> <div class=\"lui_dialog_loading_centerR\"> <div class=\"lui_dialog_loading_centerC\"> <div data-lui-mark=\"dialog.content.frame\" class=\"lui_dialog_loading_container clearfloat\"> <div id=\"lui-id-85\" class=\"lui-component\" data-lui-cid=\"lui-id-85\"><div> <div data-lui-mark=\"dialog.content.inside\" class=\"lui_dialog_loading_content\"> <div class=\"load_img\"> </div> <div class=\"load_txt\">打印加载数据中...</div> </div></div></div></div> </div> </div> </div> <div class=\"lui_dialog_loading_bottomL\"> <div class=\"lui_dialog_loading_bottomR\"> <div class=\"lui_dialog_loading_bottomC\"> </div> </div> </div> </div></div>";
//response.getWriter().write("<script type='text/javascript'>alert('加载中。。');</script>");
TimeCounter.logCurrentTime("Action-view", true, getClass());
KmssMessages messages = new KmssMessages();
//定制新打印
Map<String,List<String>> resultMap = new HashMap<String,List<String>>(); //待替换的书签与内容
String printNew = request.getParameter("printNew");
JSONObject jsonObject=JSONObject.fromObject(printNew);
System.out.println("前端书签数据:+++++++++++");
System.out.println(jsonObject);
System.out.println("前端书签数据:+++++++++++");
String fdId = jsonObject.getString("fdId");
YkdContractMain ykdContractMain = null;
if(StringUtil.isNotNull(fdId)) {
ykdContractMain = (YkdContractMain) getServiceImp(
request).findByPrimaryKey(fdId);
}
String fdTemplateId = "";
List attContracts = getSysAttMainService().findByModelKey("com.landray.kmss.ykd.contract.model.YkdContractParameters", fdId, "sysprint_editonline");
if(!"10".equals(ykdContractMain.getIsNeedNewPrint())) {//未打印过
System.out.println("开始重新转换!");
IBaseModel mainModel = (IBaseModel) ykdContractMain;
IExtendForm mainForm = null;
mainForm = getServiceImp(request).convertModelToForm(mainForm, mainModel,new RequestContext(request));//model转form
SysPrintMainCoreServiceImp sysPrintMainCoreServiceImp = new SysPrintMainCoreServiceImp();
sysPrintMainCoreServiceImp.setWordPrintModelData(mainModel, mainForm, request);//反射当前实体类对象成JSONObject对象
JSONObject resultJson = (JSONObject) request.getAttribute("resultJson");
jsonObject = jSONCombine(jsonObject,resultJson);
Iterator it2 = jsonObject.keys();
while (it2.hasNext()) {
String key = String.valueOf(it2.next());
String value = "";
if(jsonObject.get(key) != null){
value = jsonObject.get(key).toString();
List<String> resultList = new ArrayList<String>();
resultList.add("Text");//代表替换书签的是文本
resultList.add(value);
resultMap.put(key, resultList);
}
};
// 开始定制明细表 -- liuwei
//承租单元明细表 start
PrintStream printStream = new PrintStream(new FileOutputStream(
ConfigLocationsUtil.getWebContentPath() + "/ykd/contract/ykd_contract_main/czdy_bookmark.html"));
List<YkdContractHtCzdy> l = ykdContractMain.getFdHtCzdy();
String html = "<!DOCTYPE html><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
+ "</head><style>.xx{font-family:fangsong;font-size: 10.5pt;font-weight:bold;color: black;}.yy{font-family:fangsong;font-size: 10.5pt;font-weight:bold;color: black;}.tb_normal{ background-color: #ffffff;"
+ " border-collapse: collapse;border: 1px black solid;padding: 8px !important;text-align: left;margin: 0 auto;}</style>"
+ "<table class=\"tb_normal\" width=100% border=\"1\" cellspacing=\"0\">" + "<tr class=\"xx\">"
+ "<td align=\"center\">楼栋</td>" + "<td align=\"center\">楼层</td>" + "<td align=\"center\">单元</td>"
+ "</tr>";
for (YkdContractHtCzdy main : l) {
html += "<tr class=\"yy\">" + " <td align=\"center\">" + main.getFdLouyu().getFdLymc() + "</td>"
+ " <td align=\"center\">" + main.getFdLc().getFdLcmc()
+ EnumerationTypeUtil.getColumnEnumsLabel("ykd_space_lcdw", main.getFdLc().getFdLcdy() + "")
+ "</td>" + " <td align=\"center\">" + main.getFdDy().getFdDybh() + "</td>" + "</tr>";
}
html += "</table></html>
2、加载lisense
/**
* 加载license
*
* @return
*/
public static boolean loadLicense(String type) {
boolean result = false;
// return true;
try {
// license路径,必须放到根路径
String lic_file = "Aspose.Total.Java.lic";
if (type.equals("word")) {
license = LicenseUtil.class.getClassLoader().getResourceAsStream(lic_file);
com.aspose.words.License aposeLic = new com.aspose.words.License();
aposeLic.setLicense(license);
result = true;
System.out.println("加载license 成功");
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
3、许可
<License>
<Data>
<LicensedTo>ShenZhen Landray Software Co., LTD</LicensedTo>
<EmailTo>hucq@landray.com.cn</EmailTo>
<LicenseType>Developer OEM</LicenseType>
<LicenseNote>Limited to 1 developer, unlimited physical locations</LicenseNote>
<OrderID>200330023926</OrderID>
<UserID>134966180</UserID>
<OEM>This is a redistributable license</OEM>
<Products>
<Product>Aspose.Total for Java</Product>
</Products>
<EditionType>Enterprise</EditionType>
<SerialNumber>87d291a1-b325-489a-86a9-d0dbbca6e308</SerialNumber>
<SubscriptionExpiry>20210331</SubscriptionExpiry>
<LicenseVersion>3.0</LicenseVersion>
<LicenseInstructions>https://purchase.aspose.com/policies/use-license</LicenseInstructions>
</Data>
<Signature>oyyD1ki7W18O0kKlNcdqh4ejrP6CBQH5BpAAf3/PO0SSRqLi9wwEmZSbGZ/RZa83YtYcQ7hoNhUwjoCyzd8Df+6ETjjncT2Kzx/opG5spu8whNJu1cv24zOMdxv9cd4rSBcA+VtLnzVDhOTXfNk1bEEl5xQpeOIP4b1M4v1PVgY=</Signature>
</License>
4、jar包
aspose-words-20.7.jar
aspose-cells-20.7.jar