二手版本:itextpdf-5.5.9和iText-extra-5.5.9
Exception trace:
java.lang.RuntimeException: com.itextpdf.text.exceptions.UnsupportedPdfException: The color depth 1 is not supported.
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.renderImage(PdfCleanUpRenderListener.java:85)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor$ImageXObjectDoHandler.handleXObject(PdfContentStreamProcessor.java:967)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.displayXObject(PdfContentStreamProcessor.java:314)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.access$5000(PdfContentStreamProcessor.java:60)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor$Do.invoke(PdfContentStreamProcessor.java:913)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpContentOperator.invoke(PdfCleanUpContentOperator.java:75)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.invokeOperator(PdfContentStreamProcessor.java:248)
at com.itextpdf.text.pdf.parser.PdfContentStreamProcessor.processContent(PdfContentStreamProcessor.java:354)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpProcessor.cleanUpPage(PdfCleanUpProcessor.java:78)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpProcessor.cleanUp(PdfCleanUpProcessor.java:53)
at com.capsilon.katalyst.packager.util.StampingUtil.drawRedaction(StampingUtil.java:371)
at com.capsilon.katalyst.packager.util.PageUtil.getPages(PageUtil.java:278)
at com.capsilon.katalyst.packager.util.PageUtil.getPages(PageUtil.java:132)
at com.capsilon.katalyst.packager.delivery.DeliveryPackager.fetchPages(DeliveryPackager.java:482)
at com.capsilon.katalyst.packager.delivery.DeliveryPackager.doPDFPackaging(DeliveryPackager.java:188)
at com.capsilon.katalyst.packager.delivery.handler.EmailDeliveryRequestProcessor.doProcessing(EmailDeliveryRequestProcessor.java:42)
at com.capsilon.katalyst.packager.delivery.StandardPackagingTask.doDeliveryPackagingRequestProcessing(StandardPackagingTask.java:100)
at com.capsilon.katalyst.packager.delivery.DeliveryPackagerRequestListener.processMessage(DeliveryPackagerRequestListener.java:80)
at com.capsilon.commons.jms.MessageListener.run(MessageListener.java:157)
Caused by: com.itextpdf.text.exceptions.UnsupportedPdfException: The color depth 1 is not supported.
at com.itextpdf.text.pdf.parser.PdfImageObject.decodeImageBytes(PdfImageObject.java:315)
at com.itextpdf.text.pdf.parser.PdfImageObject.<init>(PdfImageObject.java:200)
at com.itextpdf.text.pdf.parser.PdfImageObject.<init>(PdfImageObject.java:169)
at com.itextpdf.text.pdf.parser.ImageRenderInfo.prepareImageObject(ImageRenderInfo.java:124)
at com.itextpdf.text.pdf.parser.ImageRenderInfo.getImage(ImageRenderInfo.java:114)
at com.itextpdf.text.pdf.pdfcleanup.PdfCleanUpRenderListener.renderImage(PdfCleanUpRenderListener.java:63)
&#34;我使用itext-xtra进行编辑的代码请查看下面的&#34; 我正在使用&#34; PdfCleanUpProcessor&#34;来创建基于PDF的编辑。
List<PdfCleanUpLocation> cleanUpLocations = new ArrayList<PdfCleanUpLocation>();
try
{
for (Annotation annotation : annotationList)
{
HashMap<String, String> rotateCoordinates = rotateCoordinatesRedaction(pdfReader, annotation, (orientation <= 360) ? (360 - orientation): (orientation -360), actualPageRotation);
rectangle = getRectangle(rotateCoordinates);
cleanUpLocations.add(new PdfCleanUpLocation(page, rectangle, BaseColor.BLACK));
}
PdfCleanUpProcessor cleaner = new PdfCleanUpProcessor(cleanUpLocations, pdfStamper);
cleaner.cleanUp();
答案 0 :(得分:1)
此问题的解决方法已添加到iText 5.5.11:iText仍未明确支持此处出现的图像类型,但PdfCleanUp
现在有更好的方法来处理未明确支持的图像现在,不是抛出异常,而是将它们完全移除或保持原样,具体取决于它们是否与编辑区相交。
此修复程序已在2017-02-16 13:43:12的commit bd9d610fb2d77de0ee98de97d3a2911f22d42b29中添加,注释“立即清理处理不支持的图像,忽略它们或完全删除它们。不再抛出任何异常如果遇到不受支持的图像。“
当然这不是真正的解决方法。真正的修复需要iText对PDF中允许的所有图像格式实现至少一定程度的支持,但在单纯的维护模式下,这在产品中是不可预期的。
(在iText 7中,我最终会期待一个真正的解决方案。但是,可能需要付费客户要求修复,但要优先考虑修复...)