Example usage for com.lowagie.text.pdf PdfObject isIndirect

List of usage examples for com.lowagie.text.pdf PdfObject isIndirect

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfObject isIndirect.

Prototype

public boolean isIndirect() 

Source Link

Document

Checks if this PdfObject is of the type PdfIndirectObject.

Usage

From source file:de.offis.health.icardea.cied.pdf.extractor.PDFiText2Extractor.java

License:LGPL

public ArrayList<byte[]> getImages(int pageNumber) throws Exception {
    ArrayList<byte[]> arrayListPageImages = new ArrayList<byte[]>();

    if (pdfReader != null) {
        int numberOfPages = pdfReader.getNumberOfPages();

        if (pageNumber > 0 && pageNumber <= numberOfPages) {

            PdfDictionary pdfDictionary = pdfReader.getPageN(pageNumber);
            if (pdfDictionary != null) {
                //PdfDictionary pdfDictionaryResources = (PdfDictionary)pdfDictionary.get(PdfName.RESOURCES);
                PdfDictionary pdfDictionaryResources = (PdfDictionary) PdfReader
                        .getPdfObject(pdfDictionary.get(PdfName.RESOURCES));

                PdfDictionary pdfDictionaryXObjects = (PdfDictionary) pdfDictionaryResources
                        .get(PdfName.XOBJECT);
                if (pdfDictionaryXObjects != null) {
                    //Set myKeySet = ;
                    //pdfDictionaryXObjects.getKeys().
                    PdfName pdfObjectSubType = null;

                    for (Object pdfKeyObject : pdfDictionaryXObjects.getKeys()) {
                        PdfObject pdfObject = pdfDictionaryXObjects.get((PdfName) pdfKeyObject);

                        if (pdfObject.isIndirect()) {
                            // Eventually check if pdfObject.isDictionary()...we skipped that here
                            PdfDictionary innerPdfDictionary = (PdfDictionary) PdfReader
                                    .getPdfObject(pdfObject);
                            if (innerPdfDictionary.isStream()) {
                                extractImageFromPdfObjectExperimental(null, pageNumber, innerPdfDictionary);

                            } else {
                                //PdfName pdfObjectSubType = (PdfName)PdfReader.getPdfObject(innerPdfDictionary.get(PdfName.SUBTYPE));
                                pdfObjectSubType = (PdfName) PdfReader
                                        .getPdfObject(innerPdfDictionary.get(PdfName.SUBTYPE));

                                /* 
                                * Check if the sub-type is an "IMAGE" and
                                * then get the actual innerPdfObject for
                                * the image extraction code
                                */
                                if (PdfName.IMAGE.equals(pdfObjectSubType)) {
                                    PdfObject innerPdfObject = pdfReader
                                            .getPdfObject(pdfObject.getIndRef().getNumber());
                                    extractImageFromPdfObjectExperimental(null, pageNumber, innerPdfObject);
                                }/*from ww w  .  jav  a2  s.co  m*/
                            }
                        } // end if checking 'pdfObject' is indirect
                    } // end for
                } // end if checking 'XObject'
            } // end if checking 'PdfDictionary'
        } // end if checking page number 
    } else {
        // TODO: Add own exception.
        throw new Exception("There is no open PDF to work with.");
    } // end if..else

    return arrayListPageImages;
}