[英]Converting a docx containing a chart to PDF
I've got a docx4j generated file which contains several tables, titles and, finally, an excel-generated curve chart. 我有一个docx4j生成的文件,其中包含几个表,标题以及一个excel生成的曲线图。
I have tried many approaches in order to convert this file to PDF, but did not get to any successful result. 我尝试了许多方法来将该文件转换为PDF,但未获得任何成功的结果。
The code I am using with Apache POI is as follows: 我与Apache POI一起使用的代码如下:
public static void convert(String inputPath, String outputPath)
throws XWPFConverterException, IOException {
PdfConverter converter = new PdfConverter();
converter.convert(new XWPFDocument(new FileInputStream(new File(
inputPath))), new FileOutputStream(new File(outputPath)),
PdfOptions.create());
}
I do not know what to do to get the chart inside the PDF, could anybody tell me how to proceed? 我不知道如何在PDF中获取图表,有人可以告诉我如何进行吗?
Thanks in advance. 提前致谢。
I don't know if this helps you but you could use "jacob" (I don't know if its possible with apache poi or docx4j) With this solution you open "Word" yourself and export it as pdf. 我不知道这是否对您有帮助,但是您可以使用“ jacob”(我不知道是否可以将其用于apache poi或docx4j)使用此解决方案,您可以自己打开“ Word”并将其导出为pdf。
! ! Word needs to be installed on the computer !
Word需要安装在计算机上 !
Heres the download-page: http://sourceforge.net/projects/jacob-project/ 此处是下载页面: http : //sourceforge.net/projects/jacob-project/
try {
if (System.getProperty("os.arch").contains("64")) {
System.load(DLL_64BIT_PATH);
} else {
System.load(DLL_32BIT_PATH);
}
} catch (UnsatisfiedLinkError e) {
//TODO
} catch (IOException e) {
//TODO
}
ActiveXComponent oleComponent = new ActiveXComponent("Word.Application");
oleComponent.setProperty("Visible", false);
Variant var = Dispatch.get(oleComponent, "Documents");
Dispatch document = var.getDispatch();
Dispatch activeDoc = Dispatch.call(document, "Open", fileName).toDispatch();
// https://msdn.microsoft.com/EN-US/library/office/ff845579.aspx
Dispatch.call(activeDoc, "ExportAsFixedFormat", new Object[] { "path to pdfFile.pdf", new Integer(17), false, 0 });
Object args[] = { new Integer(0) };//private static final int DO_NOT_SAVE_CHANGES = 0;
Dispatch.call(activeDoc, "Close", args);
Dispatch.call(oleComponent, "Quit");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.