private static void findPages(COSBase kidsObj, List<ObjectRef> pageRefs) {
        if (kidsObj == null) {
            return;
        }
        if (kidsObj instanceof COSArray) {
            for (COSBase kid : ((COSArray) kidsObj)) {
                if (kid instanceof COSObject) {
                    COSBase kidbase = ((COSObject) kid).getObject();
                    if (kidbase instanceof COSDictionary) {
                        COSDictionary dict = (COSDictionary) kidbase;
                        if (COSName.PAGE.equals(dict.getCOSName(COSName.TYPE))) {
                            pageRefs.add(new ObjectRef(((COSObject) kid).getKey().getNumber(),
                                    ((COSObject) kid).getKey().getGeneration()));
                            continue;
                        }
                        if (dict.containsKey(COSName.KIDS)) {
                            findPages(dict.getDictionaryObject(COSName.KIDS), pageRefs);
                        }
                    }
                }
            }
        }
    }
Converts the given PDF document (and related metadata) to a stream
of XHTML SAX events sent to the given content handler.

@param pdDocument PDF document
@param handler    SAX content handler
@param context
@param metadata   PDF metadata
@param config
@throws SAXException  if the content handler fails to process SAX events
@throws TikaException if there was an exception outside of per page processing
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-pdf-module/src/main/java/org/apache/tika/parser/pdf/PDFMarkedContent2XHTML.java