我已经使用 Apache POI 通过模板生成了 docx 文件。我正在尝试将其转换为 PDF 文件。下面是代码和库。我正在使用 Apache POI 4.1.1。
InputStream is = new FileInputStream(new File(filepath));
OutputStream out = new FileOutputStream(new File("E:\\DominoData\\Temp\\template.pdf"));
XWPFDocument document = new XWPFDocument(is);
PdfOptions options = PdfOptions.create();
PdfConverter.getInstance().convert(document, out, options);
我在下面添加了库
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import org.apache.poi.ooxml.POIXMLDocumentPart;
import fr.opensagres.xdocreport.itext.extension.font.IFontProvider;
import fr.opensagres.xdocreport.itext.extension.font.ITextFontRegistry;
运行代码时出现以下错误。我可以知道我在这里缺少哪些 jar 文件或库吗?
[1D08:0091-28A8] 12/16/2021 07:12:55 AM HTTP JVM: Exception in thread "AgentThread: JavaAgent"
[1D08:0092-28A8] 12/16/2021 07:12:55 AM HTTP JVM: java.lang.NoClassDefFoundError: org/apache/poi/POIXMLDocumentPart
[1D08:0094-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.core.styles.XWPFStylesDocument$DocumentVisitor.visitDocument(XWPFStylesDocument.java:1471)
[1D08:0096-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.core.styles.XWPFStylesDocument.getFontsDocument(XWPFStylesDocument.java:1596)
[1D08:0098-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.core.styles.XWPFStylesDocument.<init>(XWPFStylesDocument.java:194)
[1D08:009A-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.core.styles.XWPFStylesDocument.<init>(XWPFStylesDocument.java:188)
[1D08:009C-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.createStylesDocument(XWPFDocumentVisitor.java:151)
[1D08:009E-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.core.XWPFDocumentVisitor.<init>(XWPFDocumentVisitor.java:144)
[1D08:00A0-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.<init>(PdfMapper.java:138)
[1D08:00A2-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:56)
[1D08:00A4-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:39)
[1D08:00A6-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at fr.opensagres.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:46)
[1D08:00A8-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at JavaAgent.NotesMain(Unknown Source)
[1D08:00AA-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at lotus.domino.AgentBase.runNotes(Unknown Source)
[1D08:00AC-28A8] 12/16/2021 07:12:55 AM HTTP JVM: at lotus.domino.NotesThread.run(Unknown Source)