public static CosBase GetDictionaryObject(this PdfDictionary dictionary, CosName firstKey, CosName secondKey)
        {
            CosBase result = dictionary.GetDictionaryObject(firstKey);

            if (result == null && secondKey != null)
            {
                result = dictionary.GetDictionaryObject(secondKey);
            }

            return(result);
        }
예제 #2
0
        public PdfDictionary GetFilterParameters(PdfDictionary streamDictionary, int index)
        {
            if (streamDictionary == null)
            {
                throw new ArgumentNullException(nameof(streamDictionary));
            }

            if (index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index), "Index must be 0 or greater");
            }

            var filter = streamDictionary.GetDictionaryObject(CosName.FILTER, CosName.F);

            var parameters = streamDictionary.GetDictionaryObject(CosName.DECODE_PARMS, CosName.DP);

            switch (filter)
            {
            case CosName _:
                if (parameters is PdfDictionary dict)
                {
                    return(dict);
                }
                break;

            case COSArray array:
                if (parameters is COSArray arr)
                {
                    if (index < arr.size() && array.getObject(index) is PdfDictionary dictionary)
                    {
                        return(dictionary);
                    }
                }
                break;

            default:
                if (parameters != null)
                {
                    log?.Error("Expected the decode parameters for the stream to be either an array or dictionary");
                }
                break;
            }

            return(new PdfDictionary());
        }
        public static CosBase GetDictionaryObject(this PdfDictionary dictionary, IEnumerable <string> keyList)
        {
            foreach (var key in keyList)
            {
                var obj = dictionary.GetDictionaryObject(CosName.Create(key));

                if (obj != null)
                {
                    return(obj);
                }
            }

            return(null);
        }
예제 #4
0
파일: Pages.cs 프로젝트: AnilAwadh/Pdf
        public bool FindPage(PdfDictionary currentPageDictionary, int soughtPageNumber, List <int> pageNumbersObserved)
        {
            var type = currentPageDictionary.GetName(CosName.TYPE);

            if (type.Equals(CosName.PAGE))
            {
                var pageNumber = GetNextPageNumber(pageNumbersObserved);

                bool found = pageNumber == soughtPageNumber;

                locatedPages[pageNumber] = currentPageDictionary;
                pageNumbersObserved.Add(pageNumber);

                return(found);
            }

            if (!type.Equals(CosName.PAGES))
            {
                log.Warn("Did not find the expected type (Page or Pages) in dictionary: " + currentPageDictionary);

                return(false);
            }

            var kids = currentPageDictionary.GetDictionaryObject(CosName.KIDS) as COSArray;

            pageFactory.LoadResources(currentPageDictionary, reader, isLenientParsing);

            bool childFound = false;

            foreach (var kid in kids.OfType <CosObject>())
            {
                // todo: exit early
                var child = pdfObjectParser.Parse(kid.ToIndirectReference(), reader, isLenientParsing) as PdfDictionary;

                var thisPageMatches = FindPage(child, soughtPageNumber, pageNumbersObserved);

                if (thisPageMatches)
                {
                    childFound = true;
                    break;
                }
            }

            return(childFound);
        }