PdfCanvasParser { public List<PdfObject> parse(List<PdfObject> ls) throws IOException { if (ls == null) ls = new ArrayList<>(); else ls.clear(); PdfObject ob = null; while ((ob = readObject()) != null) { ls.add(ob); if (tokeniser.getTokenType() == PdfTokenizer.TokenType.Other) { if ("BI".equals(ob.toString())) { PdfStream inlineImageAsStream = InlineImageParsingUtils.parse(this, currentResources.getResource(PdfName.ColorSpace)); ls.clear(); ls.add(inlineImageAsStream); ls.add(new PdfLiteral("EI")); } break; } } return ls; } PdfCanvasParser(PdfTokenizer tokeniser);  PdfCanvasParser(PdfTokenizer tokeniser, PdfResources currentResources); List<PdfObject> parse(List<PdfObject> ls); PdfTokenizer getTokeniser(); void setTokeniser(PdfTokenizer tokeniser); PdfDictionary readDictionary(); PdfArray readArray(); PdfObject readObject(); boolean nextValidToken();  }
@Test public void innerArraysInContentStreamTest() throws IOException { String inputFileName = sourceFolder + "innerArraysInContentStream.pdf"; PdfDocument pdfDocument = new PdfDocument(new PdfReader(inputFileName)); byte[] docInBytes = pdfDocument.getFirstPage().getContentBytes(); RandomAccessSourceFactory factory = new RandomAccessSourceFactory(); PdfTokenizer tokeniser = new PdfTokenizer(new RandomAccessFileOrArray(factory.createSource(docInBytes))); PdfResources resources = pdfDocument.getPage(1).getResources(); PdfCanvasParser ps = new PdfCanvasParser(tokeniser, resources); List<PdfObject> actual = ps.parse(null); List<PdfObject> expected = new ArrayList<PdfObject>(); expected.add(new PdfString("Cyan")); expected.add(new PdfArray(new int[] {1, 0, 0, 0})); expected.add(new PdfString("Magenta")); expected.add(new PdfArray(new int[] {0, 1, 0, 0})); expected.add(new PdfString("Yellow")); expected.add(new PdfArray(new int[] {0, 0, 1, 0})); PdfArray cmpArray = new PdfArray(expected); Assert.assertTrue(new CompareTool().compareArrays(cmpArray, (((PdfDictionary) actual.get(1)).getAsArray(new PdfName("ColorantsDef"))))); }