这里主要需要生成一个合同的pdf文档,拿到的合同格式是word文档,为了便于处理,我们用DW将其内容手动转为html。
所以接下来的问题主要就是如何从一个html的合同模板变成一个pdf文件。
首先我们定义好freemaker的util方法,使其易于调用
public class TemplateUtils {
private static FreeMarkerConfigurer templateEngine = new FreeMarkerConfigurer();
static {
try {
templateEngine.setConfiguration(templateEngine.createConfiguration());
TemplateLoader loader = new FileTemplateLoader(new ClassPathResource("template").getFile());
templateEngine.getConfiguration().setTemplateLoader(loader);
} catch (IOException e) {
e.printStackTrace();
} catch (TemplateException e) {
e.printStackTrace();
}
}
public static String generateTemplateContent(String templateName, Map map) {
try {
Template t = templateEngine
.getConfiguration().getTemplate(templateName);
return FreeMarkerTemplateUtils.processTemplateIntoString(t, map);
} catch (Exception e) {