예제 #1
0
파일: Catalog.cs 프로젝트: zyj0021/PdfPig
        /// <summary>
        /// Create a new <see cref="CatalogDictionary"/>.
        /// </summary>
        internal Catalog(DictionaryToken catalogDictionary, DictionaryToken pagesDictionary,
                         PageTreeNode pageTree)
        {
            CatalogDictionary = catalogDictionary ?? throw new ArgumentNullException(nameof(catalogDictionary));
            PagesDictionary   = pagesDictionary ?? throw new ArgumentNullException(nameof(pagesDictionary));
            PageTree          = pageTree ?? throw new ArgumentNullException(nameof(pageTree));

            if (!pageTree.IsRoot)
            {
                throw new ArgumentException("Page tree must be the root page tree node.", nameof(pageTree));
            }

            var byNumber = new Dictionary <int, PageTreeNode>();

            PopulatePageByNumberDictionary(pageTree, byNumber);
            pagesByNumber = byNumber;
        }
예제 #2
0
파일: Catalog.cs 프로젝트: zyj0021/PdfPig
        private static void PopulatePageByNumberDictionary(PageTreeNode node, Dictionary <int, PageTreeNode> result)
        {
            if (node.IsPage)
            {
                if (!node.PageNumber.HasValue)
                {
                    throw new InvalidOperationException($"Node was page but did not have page number: {node}.");
                }

                result[node.PageNumber.Value] = node;
                return;
            }

            foreach (var child in node.Children)
            {
                PopulatePageByNumberDictionary(child, result);
            }
        }