1

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

  1. 传入的 pdf
  2. 我们自己生成的 pdf(通过 pdfbox,来自 xml 或 csv 输入)。

转换是在外部 java 类中实现的。它适用于大多数 pdf 文件。只有少数 pdf 文件在我们在 Linux(!!) 上运行的 SAP PI 环境中出现异常。并且相同的转换在本地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 字体和“/Encoding / Identity-H ”......所有不在我们的 Linux 下运行的 pdf 文件系统包含这个“ Identity-H ”。

有没有人在 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
4

0 回答 0