Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-5036

IllegalArgumentException in PDImageXObject.getImage(): Numbers of source Raster bands and source color space components do not match

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 2.0.21
    • None
    • None
    • None
    • JDK11

    Description

      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:

      	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
      	    }
      	}
      

      Attachments

        1. Phaeton.pdf
          2.28 MB
          Andreas Gerstinger

        Issue Links

          Activity

            People

              Unassigned Unassigned
              agerstin Andreas Gerstinger
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: