graalvm nodejs + spire office 实现office 处理

发布时间 2023-06-08 23:07:53作者: 荣锋亮

实际上是一个比较简单的处理,主要是利用了graalvm 的nodejs 可以方便的使用外部jar ,我们就可以使用其他nodejs web 框架,结合spire
office 实现专业可靠的office 转换处理

预备

主要是安装graalvm 以及nodejs graalvm 已经不支持包含nodejs 了,需要独立安装

  • 参考
    对于grralvm 安装使用了sdk 比较方便的cli
 
sdk install java 22.3.r19-grl
sdk java use 22.3.r19-grl
$JAVA_HOME/bin/gu install nodejs

参考代码

// com.spire.license.LicenseProvider.setLicenseKey("your license key")"; 此处可以使用自己的license
var doc = new com.spire.doc.Document(false);
//Save the differences in a third document
//Load a sample Word document
doc.loadFromFile("mydemo.docx");
var ppl = new com.spire.doc.ToPdfParameterList();
 
//Embed all fonts in the PDF document
ppl.isEmbeddedAllFonts(true);
 
//Remove the hyperlinks and keep the character formats
ppl.setDisableLink(true);
 
//Save the document as PDF
doc.saveToFile("mydemo.pdf", ppl);

运行

$JAVA_HOME/bin/node --jvm --vm.cp=spire.office-8.5.6.jar  app.js

说明

技术上没有太多东西,核心是利用graalvm nodejs 方便的java 互调用能力,结合spire office 强大的office 处理能力,大家可以使用nodejs 就能做专业的转换服务
利用好graalvm 强大的语言互调用能力,一些跨语言以及其他语言的缺点就可以很好的解决了

参考资料

https://www.graalvm.org/22.0/reference-manual/js/JavaInteroperability/
https://www.graalvm.org/22.0/reference-manual/js/NodeJS/
https://www.e-iceblue.com/Tutorials/Java/Spire.Doc-for-Java/Program-Guide/Spire.Doc-Program-Guide-Content-for-Java.html