PDF到Multipage TIFF(pdfbox / icafe4j) - 在Windows上运行,在Linux上出错

时间:2017-12-06 14:15:38

标签: java linux pdfbox tiff multipage

我们在SAP PI(7.40)环境中遇到问题。我们从不同的接口获得发票(xml,csv,pdf),在此过程中我们必须发送一个tiff文件(从pdf通过pdfbox / icafe4j转换)到OCR提供商。 pdf可以是:

  1. 传入的pdf
  2. 由我们自己生成的pdf(通过pdfbox,来自xml或csv输入)。
  3. 转换是在外部java类中实现的。它适用于大多数pdf文件。只有少数pdf文件,我们在SAP PI环境中得到异常,在Linux(!!)上运行。 在本地 Windows(!!)环境中,相同的转化运行精细,没有任何错误。

    Linux环境的部分例外:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <ErrorHandling>
    <ExceptionType>class java.lang.IndexOutOfBoundsException</ExceptionType
    <ExceptionLocalizedMsg>Index: 0, Size: 0</ExceptionLocalizedMsg>
    ....
    

    摘自java实现:

    // pDoc is the PDDocument object, returns byte[]
    bTiff = tiffFromPdf.createMultipageTIFF(pDoc);
    sTiffBase64 = DatatypeConverter.printBase64Binary(bTiff);
    this.fireTrace(1, "Content of sTiffBase64 -> [" + sTiffBase64 + "]");
    
    // Trace 'normally' contains:
    <Trace type="T" level="1">Content of sTiffBase64 -> [base64-encoded tiff data] </Trace>
    
    // In createMultipageTIFF the exception occurs in this line
    TIFFTweaker.writeMultipageTIFF(rout, param, images);
    

    在我们找到有关TIFFTweaker类更新的以下内容之后,我们实现了更新,之后不会抛出异常,但是如链接中提到的那样,它被吞下。

    https://github.com/dragon66/icafe/issues/63

    // Trace of byte[] then is emtpy:
    <Trace type="T" level="1">Content of sTiffBase64 -> [] </Trace>
    

    这不是很有用,因为我们必须有OCR的tiff文件。

    我们还看了一下pdf字节流的内部结构,发现有一些特殊的部件处理字体/编码: TrueType字体和&#34; /编码/ 标识-H &#34; ...所有不在我们的Linux系统下运行的pdf文件都包含这个&#34; Identity-H &#34;。

    有没有人在Linux上进行此转换时有类似的经验/错误?

    除了我们的尝试之外,还有什么可以做的吗? 也许某些库在Linux或其他地方缺失了!?

    请同时查看此转换(可能有助于理解):

    https://www.mail-archive.com/users@pdfbox.apache.org/msg09569.html

    我在没有任何代码或受影响的pdf文件的情况下开始此问题的初始条目,但如果需要,请提供。

    堆栈追踪:

    RuntimeException during appliction Java mapping com/covestro/eai/cov/x01/apb/CheckAndPrepareEmailPDF
    Thrown:
    java.lang.RuntimeException: com.bbs.eai.bay0.x01.interfaces.MappingError: <?xml version="1.0" encoding="ISO-8859-1"?>
    <ErrorHandling>
    <ExceptionType>class java.lang.IndexOutOfBoundsException</ExceptionType>
    <CauseInfo>CheckAndPrepareEmailPDF: Check EmailPDF problem</CauseInfo>
    <ExceptionCause>null</ExceptionCause>
    <ExceptionMsg>Index: 0, Size: 0</ExceptionMsg>
    <ExceptionLocalizedMsg>Index: 0, Size: 0</ExceptionLocalizedMsg>
    <ExceptionStackTrace>
    <Trace> at java.util.ArrayList.RangeCheck Line 547</Trace>
    <Trace> at java.util.ArrayList.get Line 322</Trace>
    <Trace> at com.icafe4j.image.tiff.TIFFTweaker.writeMultipageTIFF Line 3154</Trace>
    <Trace> at com.covestro.eai.cov.x01.apb.pdf.CreateMultiTIFFFromPDF.createMultipageTIFF Line 113</Trace>
    <Trace> at com.covestro.eai.cov.x01.apb.CheckAndPrepareEmailPDF.transformStreamMapping Line 234</Trace>
    <Trace> at com.bbs.eai.bay0.x01.templates.JavaMappingTemplateV2.transform Line 731</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.JavaMapping.executeStep Line 112</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.Mapping.execute Line 60</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.SequenceMapping.executeStep Line 40</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.Mapping.execute Line 60</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.MappingHandler.map Line 87</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.MappingHandler.map Line 71</Trace>
    <Trace> at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleMappingRequest Line 123</Trace>
    <Trace> at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleRequest Line 73</Trace>
    <Trace> at com.sap.aii.ibrun.sbeans.mapping.MappingServiceImpl.processFunction Line 79</Trace>
    <Trace> at sun.reflect.GeneratedMethodAccessor406.invoke Line -1</Trace>
    <Trace> at sun.reflect.DelegatingMethodAccessorImpl.invoke Line 25</Trace>
    <Trace> at java.lang.reflect.Method.invoke Line 597</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal Line 47</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 166</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke Line 19</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke Line 50</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.doWorkWithAttribute Line 37</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.invoke Line 21</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_MethodRetry.invoke Line 46</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 191</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke Line 23</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke Line 25</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke Line 17</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain Line 138</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke Line 172</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke Line 99</Trace>
    <Trace> at com.sun.proxy.$Proxy645.processFunction Line -1</Trace>
    <Trace> at sun.reflect.NativeMethodAccessorImpl.invoke0 Line -2</Trace>
    <Trace> at sun.reflect.NativeMethodAccessorImpl.invoke Line 39</Trace>
    <Trace> at sun.reflect.DelegatingMethodAccessorImpl.invoke Line 25</Trace>
    <Trace> at java.lang.reflect.Method.invoke Line 597</Trace>
    <Trace> at com.sap.engine.services.rfcengine.RFCDefaultRequestHandler.handleRequest Line 183</Trace>
    <Trace> at com.sap.engine.services.rfcengine.RFCJCOServer$J2EEApplicationRunnable.run Line 267</Trace>
    <Trace> at com.sap.engine.core.thread.impl3.ActionObject.run Line 37</Trace>
    <Trace> at java.security.AccessController.doPrivileged Line -2</Trace>
    <Trace> at com.sap.engine.core.thread.impl3.SingleThread.execute Line 185</Trace>
    <Trace> at com.sap.engine.core.thread.impl3.SingleThread.run Line 302</Trace>
    </ExceptionStackTrace>
    </ErrorHandling>
    
    at com.bbs.eai.bay0.x01.templates.JavaMappingTemplateV2.transform(JavaMappingTemplateV2.java:740)
    at com.sap.aii.ib.server.mapping.execution.JavaMapping.executeStep(JavaMapping.java:112)
    at com.sap.aii.ib.server.mapping.execution.Mapping.execute(Mapping.java:60)
    at com.sap.aii.ib.server.mapping.execution.SequenceMapping.executeStep(SequenceMapping.java:40)
    at com.sap.aii.ib.server.mapping.execution.Mapping.execute(Mapping.java:60)
    at com.sap.aii.ib.server.mapping.execution.MappingHandler.map(MappingHandler.java:87)
    at com.sap.aii.ib.server.mapping.execution.MappingHandler.map(MappingHandler.java:71)
    at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleMappingRequest(MappingRequestHandler.java:123)
    at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleRequest(MappingRequestHandler.java:73)
    at com.sap.aii.ibrun.sbeans.mapping.MappingServiceImpl.processFunction(MappingServiceImpl.java:79)
    at sun.reflect.GeneratedMethodAccessor406.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal(RequestInvocationContext.java:47)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:166)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke(Interceptors_StatesTransition.java:19)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke(Interceptors_Resource.java:50)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.doWorkWithAttribute(Interceptors_Transaction.java:37)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.invoke(Interceptors_Transaction.java:21)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_MethodRetry.invoke(Interceptors_MethodRetry.java:46)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:191)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke(Interceptors_StatelessInstanceGetter.java:23)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke(Interceptors_SecurityCheck.java:25)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
    at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke(Interceptors_ExceptionTracer.java:17)
    at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed(AbstractInvocationContext.java:179)
    at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain(DefaultInvocationChainsManager.java:138)
    at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:172)
    at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke(DefaultEJBProxyInvocationHandler.java:99)
    at com.sun.proxy.$Proxy645.processFunction(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.sap.engine.services.rfcengine.RFCDefaultRequestHandler.handleRequest(RFCDefaultRequestHandler.java:183)
    at com.sap.engine.services.rfcengine.RFCJCOServer$J2EEApplicationRunnable.run(RFCJCOServer.java:267)
    at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:185)
    at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:302)
    Caused by: com.bbs.eai.bay0.x01.interfaces.MappingError: <?xml version="1.0" encoding="ISO-8859-1"?>
    <ErrorHandling>
    <ExceptionType>class java.lang.IndexOutOfBoundsException</ExceptionType>
    <CauseInfo>CheckAndPrepareEmailPDF: Check EmailPDF problem</CauseInfo>
    <ExceptionCause>null</ExceptionCause>
    <ExceptionMsg>Index: 0, Size: 0</ExceptionMsg>
    <ExceptionLocalizedMsg>Index: 0, Size: 0</ExceptionLocalizedMsg>
    <ExceptionStackTrace>
    <Trace> at java.util.ArrayList.RangeCheck Line 547</Trace>
    <Trace> at java.util.ArrayList.get Line 322</Trace>
    <Trace> at com.icafe4j.image.tiff.TIFFTweaker.writeMultipageTIFF Line 3154</Trace>
    <Trace> at com.covestro.eai.cov.x01.apb.pdf.CreateMultiTIFFFromPDF.createMultipageTIFF Line 113</Trace>
    <Trace> at com.covestro.eai.cov.x01.apb.CheckAndPrepareEmailPDF.transformStreamMapping Line 234</Trace>
    <Trace> at com.bbs.eai.bay0.x01.templates.JavaMappingTemplateV2.transform Line 731</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.JavaMapping.executeStep Line 112</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.Mapping.execute Line 60</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.SequenceMapping.executeStep Line 40</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.Mapping.execute Line 60</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.MappingHandler.map Line 87</Trace>
    <Trace> at com.sap.aii.ib.server.mapping.execution.MappingHandler.map Line 71</Trace>
    <Trace> at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleMappingRequest Line 123</Trace>
    <Trace> at com.sap.aii.ibrun.sbeans.mapping.MappingRequestHandler.handleRequest Line 73</Trace>
    <Trace> at com.sap.aii.ibrun.sbeans.mapping.MappingServiceImpl.processFunction Line 79</Trace>
    <Trace> at sun.reflect.GeneratedMethodAccessor406.invoke Line -1</Trace>
    <Trace> at sun.reflect.DelegatingMethodAccessorImpl.invoke Line 25</Trace>
    <Trace> at java.lang.reflect.Method.invoke Line 597</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.RequestInvocationContext.proceedFinal Line 47</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 166</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatesTransition.invoke Line 19</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Resource.invoke Line 50</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.doWorkWithAttribute Line 37</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_Transaction.invoke Line 21</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_MethodRetry.invoke Line 46</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 191</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_StatelessInstanceGetter.invoke Line 23</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_SecurityCheck.invoke Line 25</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.Interceptors_ExceptionTracer.invoke Line 17</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.AbstractInvocationContext.proceed Line 179</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.DefaultInvocationChainsManager.startChain Line 138</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke Line 172</Trace>
    <Trace> at com.sap.engine.services.ejb3.runtime.impl.DefaultEJBProxyInvocationHandler.invoke Line 99</Trace>
    <Trace> at com.sun.proxy.$Proxy645.processFunction Line -1</Trace>
    <Trace> at sun.reflect.NativeMethodAccessorImpl.invoke0 Line -2</Trace>
    <Trace> at sun.reflect.NativeMethodAccessorImpl.invoke Line 39</Trace>
    <Trace> at sun.reflect.DelegatingMethodAccessorImpl.invoke Line 25</Trace>
    <Trace> at java.lang.reflect.Method.invoke Line 597</Trace>
    <Trace> at com.sap.engine.services.rfcengine.RFCDefaultRequestHandler.handleRequest Line 183</Trace>
    <Trace> at com.sap.engine.services.rfcengine.RFCJCOServer$J2EEApplicationRunnable.run Line 267</Trace>
    <Trace> at com.sap.engine.core.thread.impl3.ActionObject.run Line 37</Trace>
    <Trace> at java.security.AccessController.doPrivileged Line -2</Trace>
    <Trace> at com.sap.engine.core.thread.impl3.SingleThread.execute Line 185</Trace>
    <Trace> at com.sap.engine.core.thread.impl3.SingleThread.run Line 302</Trace>
    </ExceptionStackTrace>
    </ErrorHandling>
    
    at com.bbs.eai.bay0.x01.templates.JavaMappingTemplateV2.makeAndLogMappingError(JavaMappingTemplateV2.java:717)
    at com.covestro.eai.cov.x01.apb.CheckAndPrepareEmailPDF.transformStreamMapping(CheckAndPrepareEmailPDF.java:351)
    at com.bbs.eai.bay0.x01.templates.JavaMappingTemplateV2.transform(JavaMappingTemplateV2.java:731)
    ... 44 more
    Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at com.icafe4j.image.tiff.TIFFTweaker.writeMultipageTIFF(TIFFTweaker.java:3154)
    at com.covestro.eai.cov.x01.apb.pdf.CreateMultiTIFFFromPDF.createMultipageTIFF(CreateMultiTIFFFromPDF.java:113)
    at com.covestro.eai.cov.x01.apb.CheckAndPrepareEmailPDF.transformStreamMapping(CheckAndPrepareEmailPDF.java:234)
    ... 45 more
    

0 个答案:

没有答案