html转Pdf,js代码未执行

版本:23.8
编程语言:java

html源文件:
test111.zip (443 字节)

js代码本应该在body中添加字符“ttttt”,但是转换后的PDF中并没有

转换后的PDF:
00001111111.zip (5.9 KB)

代码:

com.aspose.words.Document htmlDoc = new com.aspose.words.Document(new FileInputStream("C:\\Users\\admin\\Documents\\EMobile10 Files\\Downloads\\test111.html"));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
		htmlDoc.save(byteArrayOutputStream, SaveFormat.PDF);
		
		Files.write(Paths.get("C:\\Users\\admin\\Desktop\\00001111111.pdf"), byteArrayOutputStream.toByteArray());

@ZhonghaoSun Aspose.Words 模拟 MS Word 的行为,而 MS Word 不支持 JavaScript 执行。我们不会在 Aspose.Words 中实现 JavaScript 引擎,HTML 文档在加载时将关闭 JavaScript 支持。作为部分解决方法,您可以使用 Aspose.HTML 重新保存文档。例如,使用这种方法可以生成带有经脚本修改的样式的文档,并保存该文档供 Aspose.Words 进一步处理:

// 使用 Aspose.HTML 重新保存 HTML,以便执行 JavaScript 并保存修改。
HTMLDocument htmlDocument = new HTMLDocument("source.html");
htmlDocument.save("processed.html");

Document document = new Document("processed.html");
document.save("output.pdf")); 

我尝试了这种方式,使用了Aspose-html22.8版本,但是JS并未生效,而且内容文字出现了乱码。

测试代码:

HTMLDocument htmlDocument = new HTMLDocument("E:\\private-common\\o-body.html");
		htmlDocument.save("processed2.html");

		Document document = new Document("processed.html");
		document.save("output.pdf");

html源文件:
o-body.zip (130.1 KB)

保存后的html:
processed2.zip (130.4 KB)

转换后的PDF文件:
output.zip (1.7 MB)

@ZhonghaoSun 如果用第一个简单的文档检查 22.8,结果与预期的一样。但是 "o-body.html "已经打开错误,也许这个文件有问题。

A post was merged into an existing topic: 使用了Aspose-html22.8版本,但是JS并未生效,而且内容文字出现了乱码。