|
@@ -60,47 +60,35 @@ public class HtmlGenerator {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public File ziliaoHtml(String title,String pdfUrl,Integer id){
|
|
|
|
|
|
-
|
|
|
- public static void main(String[] args) {
|
|
|
- // 初始化Velocity引擎
|
|
|
- Properties properties = new Properties();
|
|
|
- properties.setProperty("resource.loader", "class");
|
|
|
- properties.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
|
|
- VelocityEngine velocityEngine = new VelocityEngine(properties);
|
|
|
-
|
|
|
- // 创建Velocity上下文,并设置变量
|
|
|
- VelocityContext context = new VelocityContext();
|
|
|
- context.put("title", "PDFzzzz");
|
|
|
- context.put("pdfUrl", "https://wl-resource.obs.cn-south-1.myhuaweicloud.com:443/ziliao/%E8%AF%8A%E6%96%AD%E4%BB%AA%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E%E4%B9%A6%20-%20%E6%97%A5%E6%96%87.pdf?AccessKeyId=FL8POSPAPQDTW42RL8SN&Expires=2094028867&Signature=HmE4BxnLD849gQKWqRBE7I8Nx%2Fg%3D");
|
|
|
-
|
|
|
- // 加载Velocity模板
|
|
|
- StringWriter writer = new StringWriter();
|
|
|
- velocityEngine.mergeTemplate("template/static/ziliao.html", "UTF-8", context, writer);
|
|
|
-
|
|
|
- // 输出渲染后的HTML到控制台
|
|
|
- String htmlContent = writer.toString();
|
|
|
- System.out.println(htmlContent);
|
|
|
-
|
|
|
- // 生成HTML文件
|
|
|
try {
|
|
|
- // 获取当前日期以创建文件夹
|
|
|
- String yyyyMMdd = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
- String baseStatic = "path/to/output/directory/"; // 更新为实际的输出目录
|
|
|
- String outputPath = baseStatic + yyyyMMdd + "outputH5.html";
|
|
|
+ Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
|
|
|
+ cfg.setClassForTemplateLoading(OperationApplication.class, "../../template/static/");
|
|
|
|
|
|
- // 创建文件并写入内容
|
|
|
- File file = new File(outputPath);
|
|
|
- FileWriter fileWriter = new FileWriter(file);
|
|
|
+ Template template = cfg.getTemplate("ziliao.html");
|
|
|
+ StringWriter out = new StringWriter();
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("title",title);
|
|
|
+ data.put("pdfUrl", pdfUrl);
|
|
|
+ template.process(data, out);
|
|
|
+
|
|
|
+ // 将HTML内容写入文件
|
|
|
+ String htmlContent = out.toString();
|
|
|
+ String outputPath = baseStatic+"ziliao"+id+".html";
|
|
|
+ FileWriter fileWriter = new FileWriter(outputPath);
|
|
|
fileWriter.write(htmlContent);
|
|
|
+ File file = new File(baseStatic+"ziliao"+id+".html");
|
|
|
fileWriter.close();
|
|
|
-
|
|
|
System.out.println("HTML文件已生成:" + outputPath);
|
|
|
+ return file;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|