У меня есть файл .docx
с двумя таблицами:
Я пытаюсь сделать следующее:
На первом этапе прочитайте файл .docx
, а затем замените точки в первой таблице содержимым динамического c. Это сработало хорошо.
На втором шаге мне нужно скопировать эту первую таблицу и вставить новую таблицу между первой и второй существующими таблицами.
На третьем шаге сохраните .docx
как файл .pdf
.
Чтобы скопировать существующую первую таблицу в новую, я запускаю ее в java
:
XWPFDocument doc = new XWPFDocument(OPCPackage.open("path\\file.docx"));
XWPFTable table = doc.getTableArray(0);
CTTbl ctTbl = CTTbl.Factory.newInstance();
ctTbl.set(table.getCTTbl());
XWPFTable table2 = new XWPFTable(ctTbl, doc);
doc.createParagraph();
doc.createTable();
doc.setTable(3, table2); //The 3 here is just to test. I know it isn't the place between 1st and 2nd tables.
Чтобы сохранить как pdf:
FileOutputStream out = new FileOutputStream(new File("path\\newFile.pdf"));
// 2) Prepare Pdf options
PdfOptions options = PdfOptions.create();
// 3) Convert XWPFDocument to Pdf
PdfConverter.getInstance().convert(doc, out, options);
out.close();
И тогда я получаю эту ошибку:
org.apache.poi.xwpf.converter.core.XWPFConverterException: org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:59)
at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:37)
at org.apache.poi.xwpf.converter.core.AbstractXWPFConverter.convert(AbstractXWPFConverter.java:45)
at com.neomind.fusion.custom.equiplex.controleMudanca.CreateFinalReport.runGCM(CreateFinalReport.java:219)
at com.neomind.fusion.custom.equiplex.controleMudanca.CreateFinalReport.start(CreateFinalReport.java:75)
at com.neomind.fusion.workflow.adapter.CustomActivityAdapter.start(CustomActivityAdapter.java:73)
at com.neomind.fusion.workflow.handler.ActivityHandlerImpl.start(ActivityHandlerImpl.java:62)
at jdk.internal.reflect.GeneratedMethodAccessor1780.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.neomind.fusion.workflow.handler.HandlerProxy.invoke(HandlerProxy.java:33)
at com.sun.proxy.$Proxy221.start(Unknown Source)
at com.neomind.fusion.workflow.ActivityJoinXor.conditionTriggeredImpl(ActivityJoinXor.java:32)
at com.neomind.fusion.workflow.ActivityJoin.conditionTriggered(ActivityJoin.java:161)
at com.neomind.fusion.workflow.ActivitySplit.triggerCondition(ActivitySplit.java:339)
at com.neomind.fusion.workflow.ActivitySplit.split(ActivitySplit.java:180)
at com.neomind.fusion.workflow.handler.ActivityHandlerImpl.finish(ActivityHandlerImpl.java:174)
at com.neomind.fusion.workflow.handler.ActivityHandlerImpl.finish(ActivityHandlerImpl.java:37)
at jdk.internal.reflect.GeneratedMethodAccessor1722.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.neomind.fusion.workflow.handler.HandlerProxy.invoke(HandlerProxy.java:33)
at com.sun.proxy.$Proxy221.finish(Unknown Source)
at com.neomind.fusion.workflow.handler.TaskHandlerImpl.finish(TaskHandlerImpl.java:159)
at com.neomind.fusion.workflow.handler.TaskHandlerImpl.finish(TaskHandlerImpl.java:46)
at jdk.internal.reflect.GeneratedMethodAccessor1722.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.neomind.fusion.workflow.handler.HandlerProxy.invoke(HandlerProxy.java:33)
at com.sun.proxy.$Proxy222.finish(Unknown Source)
at com.neomind.fusion.workflow.service.TaskServiceImpl.complete(TaskServiceImpl.java:340)
at com.neomind.fusion.workflow.service.TaskServiceImpl.complete(TaskServiceImpl.java:332)
at com.neomind.fusion.portal.portlets.workflow.TaskPortlet.doSend(TaskPortlet.java:519)
at com.neomind.fusion.portal.portlets.workflow.TaskPortlet.processAction(TaskPortlet.java:265)
at com.neomind.fusion.portal.PortalServlet.doGet(PortalServlet.java:225)
at com.neomind.fusion.portal.PortalServlet.doPost(PortalServlet.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.security.license.filter.SecurityFilter.doFilter(SecurityFilter.java:136)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.ResourcesFilter.doFilter(ResourcesFilter.java:142)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.framework.base.resources.InitializeFilter.doFilter(InitializeFilter.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.sso.filter.AuthenticationFilterChain.doFilter(AuthenticationFilterChain.java:33)
at com.neomind.sso.filter.impl.AuthenticationFilterImpl.doFilter(AuthenticationFilterImpl.java:90)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.MultipartFilter.doFilter(MultipartFilter.java:88)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.PortalFilter.lambda$doFilter$0(PortalFilter.java:182)
at com.neomind.fusion.persist.PersistEngine.managedRun(PersistEngine.java:3122)
at com.neomind.fusion.persist.PersistEngine.managedRun(PersistEngine.java:3050)
at com.neomind.fusion.persist.PersistEngine.managedRun(PersistEngine.java:3027)
at com.neomind.fusion.portal.PortalFilter.doFilter(PortalFilter.java:148)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.neomind.fusion.portal.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:83)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:853)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1587)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.apache.xmlbeans.impl.values.XmlValueDisconnectedException
at org.apache.xmlbeans.impl.values.XmlObjectBase.check_orphaned(XmlObjectBase.java:1258)
at org.openxmlformats.schemas.wordprocessingml.x2006.main.impl.CTTcImpl.getTcPr(Unknown Source)
at org.apache.poi.xwpf.converter.core.utils.XWPFTableUtil.getGridSpan(XWPFTableUtil.java:225)
at org.apache.poi.xwpf.converter.core.utils.XWPFTableUtil.getNumberOfColumns(XWPFTableUtil.java:200)
at org.apache.poi.xwpf.converter.core.utils.XWPFTableUtil.computeColWidths(XWPFTableUtil.java:95)
at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitTable(XWPFDocumentVisitor.java:813)
at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.visitBodyElements(XWPFDocumentVisitor.java:237)
at org.apache.poi.xwpf.converter.core.XWPFDocumentVisitor.start(XWPFDocumentVisitor.java:186)
at org.apache.poi.xwpf.converter.pdf.PdfConverter.doConvert(PdfConverter.java:55)
... 85 more
Если я не пытаюсь создать эту новую таблицу путем копирования первой, код работает нормально, PDF создается с правильным содержимым внутри него .
Что я делаю не так?
Спасибо
PS: я использую poi-oo xml -3.15.jar.