PdfReader implements PdfViewerPreferences { public PdfDictionary getCatalog() { return catalog; } private  PdfReader(RandomAccessSource byteSource, boolean partialRead, byte ownerPassword[], Certificate certificate, Key certificateKey, String certificateKeyProvider, ExternalDecryptionProcess externalDecryptionProcess, boolean closeSourceOnConstructorError); private  PdfReader(RandomAccessSource byteSource, ReaderProperties properties);  PdfReader(final String filename);  PdfReader(ReaderProperties properties, final String filename);  PdfReader(final String filename, final byte ownerPassword[]);  PdfReader(final String filename, final byte ownerPassword[], boolean partial);  PdfReader(final byte pdfIn[]);  PdfReader(final byte pdfIn[], final byte ownerPassword[]);  PdfReader(final String filename, final Certificate certificate, final Key certificateKey, final String certificateKeyProvider);  PdfReader(final String filename, Certificate certificate, final ExternalDecryptionProcess externalDecryptionProcess);  PdfReader(final byte[] pdfIn, Certificate certificate, final ExternalDecryptionProcess externalDecryptionProcess);  PdfReader(final InputStream inputStream, final Certificate certificate, final ExternalDecryptionProcess externalDecryptionProcess);  PdfReader(final URL url);  PdfReader(final URL url, final byte ownerPassword[]);  PdfReader(final InputStream is, final byte ownerPassword[]);  PdfReader(final InputStream is);  PdfReader(ReaderProperties properties, final InputStream is);  PdfReader(ReaderProperties properties, final RandomAccessFileOrArray raf);  PdfReader(final RandomAccessFileOrArray raf, final byte ownerPassword[]);  PdfReader(final RandomAccessFileOrArray raf, final byte ownerPassword[], boolean partial);  PdfReader(final PdfReader reader); RandomAccessFileOrArray getSafeFile(); int getNumberOfPages(); PdfDictionary getCatalog(); PRAcroForm getAcroForm(); int getPageRotation(final int index); Rectangle getPageSizeWithRotation(final int index); Rectangle getPageSizeWithRotation(final PdfDictionary page); Rectangle getPageSize(final int index); Rectangle getPageSize(final PdfDictionary page); Rectangle getCropBox(final int index); Rectangle getBoxSize(final int index, final String boxName); HashMap<String, String> getInfo(); static Rectangle getNormalizedRectangle(final PdfArray box); boolean isTagged(); static PdfObject getPdfObjectRelease(final PdfObject obj); static PdfObject getPdfObject(PdfObject obj); static PdfObject getPdfObjectRelease(final PdfObject obj, final PdfObject parent); static PdfObject getPdfObject(PdfObject obj, final PdfObject parent); PdfObject getPdfObjectRelease(final int idx); PdfObject getPdfObject(final int idx); void resetLastXrefPartial(); void releaseLastXrefPartial(); static void releaseLastXrefPartial(final PdfObject obj); PRIndirectReference addPdfObject(final PdfObject obj); double dumpPerc(); static PdfObject killIndirect(final PdfObject obj); static byte[] FlateDecode(final byte in[]); static byte[] decodePredictor(final byte in[], final PdfObject dicPar); static byte[] FlateDecode(final byte in[], final boolean strict); static byte[] ASCIIHexDecode(final byte in[]); static byte[] ASCII85Decode(final byte in[]); static byte[] LZWDecode(final byte in[]); boolean isRebuilt(); PdfDictionary getPageN(final int pageNum); PdfDictionary getPageNRelease(final int pageNum); void releasePage(final int pageNum); void resetReleasePage(); PRIndirectReference getPageOrigRef(final int pageNum); byte[] getPageContent(final int pageNum, final RandomAccessFileOrArray file); static byte[] getPageContent(final PdfDictionary page); PdfDictionary getPageResources(final int pageNum); PdfDictionary getPageResources(final PdfDictionary pageDict); byte[] getPageContent(final int pageNum); void setPageContent(final int pageNum, final byte content[]); void setPageContent(final int pageNum, final byte content[], final int compressionLevel); void setPageContent(final int pageNum, final byte content[], final int compressionLevel, final boolean killOldXRefRecursively); static byte[] decodeBytes(byte[] b, final PdfDictionary streamDictionary); static byte[] decodeBytes(byte[] b, final PdfDictionary streamDictionary, Map<PdfName, FilterHandlers.FilterHandler> filterHandlers); static byte[] getStreamBytes(final PRStream stream, final RandomAccessFileOrArray file); static byte[] getStreamBytes(final PRStream stream); static byte[] getStreamBytesRaw(final PRStream stream, final RandomAccessFileOrArray file); static byte[] getStreamBytesRaw(final PRStream stream); void eliminateSharedStreams(); boolean isTampered(); void setTampered(final boolean tampered); byte[] getMetadata(); long getLastXref(); int getXrefSize(); long getEofPos(); char getPdfVersion(); boolean isEncrypted(); long getPermissions(); boolean is128Key(); PdfDictionary getTrailer(); int shuffleSubsetNames(); int createFakeFontSubsets(); HashMap<Object, PdfObject> getNamedDestination(); HashMap<Object, PdfObject> getNamedDestination(final boolean keepNames); @SuppressWarnings("unchecked") HashMap<String, PdfObject> getNamedDestinationFromNames(); HashMap<Object, PdfObject> getNamedDestinationFromNames(final boolean keepNames); HashMap<String, PdfObject> getNamedDestinationFromStrings(); void removeFields(); void removeAnnotations(); ArrayList<PdfAnnotation.PdfImportedLink> getLinks(final int page); void makeRemoteNamedDestinationsLocal(); void consolidateNamedDestinations(); void close(); int removeUnusedObjects(); AcroFields getAcroFields(); String getJavaScript(final RandomAccessFileOrArray file); String getJavaScript(); void selectPages(final String ranges); void selectPages(final List<Integer> pagesToKeep); void setViewerPreferences(final int preferences); void addViewerPreference(final PdfName key, final PdfObject value); void setViewerPreferences(final PdfViewerPreferencesImp vp); int getSimpleViewerPreferences(); boolean isAppendable(); void setAppendable(final boolean appendable); boolean isNewXrefType(); long getFileLength(); boolean isHybridXref(); boolean hasUsageRights(); void removeUsageRights(); int getCertificationLevel(); final boolean isOpenedWithFullPermissions(); int getCryptoMode(); boolean isMetadataEncrypted(); byte[] computeUserPassword(); static boolean unethicalreading; static boolean debugmode; }
@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); }