You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Tilman Hausherr (Jira)" <ji...@apache.org> on 2020/12/08 04:32:00 UTC

[jira] [Comment Edited] (PDFBOX-5036) IllegalArgumentException in PDImageXObject.getImage(): Numbers of source Raster bands and source color space components do not match

    [ https://issues.apache.org/jira/browse/PDFBOX-5036?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17245665#comment-17245665 ] 

Tilman Hausherr edited comment on PDFBOX-5036 at 12/8/20, 4:31 AM:
-------------------------------------------------------------------

Next time please add the stack trace, which is:
{code}
Exception in thread "main" java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
	at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:482)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1280)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1247)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1050)
	at org.apache.pdfbox.filter.DCTFilter.decode(DCTFilter.java:91)
{code}
This is a java bug. You can catch it like every other exception if you want.

You can avoid it by using the [twelvemonkeys library|https://github.com/haraldk/TwelveMonkeys]. See also PDFBOX-4221 and PDFBOX-4258.


was (Author: tilman):
Next time please add the stack trace, which is:
{code}
Exception in thread "main" java.lang.IllegalArgumentException: Numbers of source Raster bands and source color space components do not match
	at java.awt.image.ColorConvertOp.filter(ColorConvertOp.java:482)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.acceptPixels(JPEGImageReader.java:1280)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImage(Native Method)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:1247)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:1050)
	at org.apache.pdfbox.filter.DCTFilter.decode(DCTFilter.java:91)
{code}
This is a java bug. You can catch it like every other exception if you want.

You can avoid it by using the twelvemonkeys library. See also PDFBOX-4221 and PDFBOX-4258.

> IllegalArgumentException in PDImageXObject.getImage(): Numbers of source Raster bands and source color space components do not match
> ------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: PDFBOX-5036
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5036
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.21
>         Environment: JDK11
>            Reporter: Andreas Gerstinger
>            Priority: Major
>         Attachments: Phaeton.pdf
>
>
> An IllegalArgumentException (runtime exception) is thrown in the getImage() method of PDImageXObject. The method declares to throw IOException, which is fine, but I do not know how to prevent it to throw the IllegalArgumentException. Only happens for some PDFs, one that is affected is attached.
> Here is the code that provokes the exception:
> {noformat}
> 	public static void main(String[] args) {
> 	    try {
> 	        PDDocument document = PDDocument.load(new File("Phaeton.pdf"));  // see attachment for an affected file
> 	        PDResources pdRes = document.getPages().get(0).getResources();
> 	        for (COSName name : pdRes.getXObjectNames()) {
> 	            PDXObject o = pdRes.getXObject(name);
> 	            if (o instanceof PDImageXObject) {
> 	                PDImageXObject img = (PDImageXObject) o;
> 	                img.getImage();  // This throws an java.lang.IllegalArgumentException (runtime exception) - bug in PDFBOX???
> 	            }
> 	        }
> 	    } catch(IOException e) {
> 	        System.out.println("IOException thrown...");  // do something here
> 	    }
> 	}
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org