@Test
public void partialReadFromByteArrayTest() throws IOException {

    byte[] pdfFile = TestResourceUtils.getResourceAsByteArray(this, "iphone_user_guide.pdf");
    PdfReader reader = new PdfReader(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(pdfFile)), null, true);
    int pagesNum = 0;
    PdfDictionary pagesObj = reader.getCatalog().getAsDict(PdfName.PAGES);
    Stack<PdfDictionary> pages = new Stack<PdfDictionary>();
    pages.push(pagesObj);
    while(pages.size() > 0) {
        PdfDictionary page = pages.pop();
        PdfArray kids = page.getAsArray(PdfName.KIDS);
        if (kids != null) {
            for (int i = 0; i < kids.size(); ++i) {
                pages.push(kids.getAsDict(i));
            }
        } else {
            ++pagesNum;
        }
    }
    assertTrue(String.format("There is 130 pages in document, but iText counted %d", pagesNum), pagesNum == 130);
}