diff --git a/VAR.PdfTools/PdfDocument.cs b/VAR.PdfTools/PdfDocument.cs index d6f55e2..3f6c141 100644 --- a/VAR.PdfTools/PdfDocument.cs +++ b/VAR.PdfTools/PdfDocument.cs @@ -158,17 +158,12 @@ namespace VAR.PdfTools return elem; } - private static void ExtractPages(PdfDictionary page, PdfDocument doc) + private static void ExtractPages(PdfDictionary page, PdfDocument doc, PdfDictionary resources) { string type = page.GetParamAsString("Type"); if (type == "Page") { - PdfDocumentPage prevDocPage = null; - if (doc._pages.Count > 0) - { - prevDocPage = doc._pages.Last(); - } - PdfDocumentPage docPage = new PdfDocumentPage(page, prevDocPage); + PdfDocumentPage docPage = new PdfDocumentPage(page, resources); doc._pages.Add(docPage); return; } @@ -183,7 +178,12 @@ namespace VAR.PdfTools { PdfDictionary childPage = elem as PdfDictionary; if (page == null) { continue; } - ExtractPages(childPage, doc); + PdfDictionary resourcesAux = null; + if (page.Values.ContainsKey("Resources")) + { + resourcesAux = page.Values["Resources"] as PdfDictionary; + } + ExtractPages(childPage, doc, resourcesAux); } } else @@ -290,7 +290,12 @@ namespace VAR.PdfTools throw new Exception("PdfDocument: Pages not found"); } PdfDictionary pages = (PdfDictionary)doc.Catalog.Values["Pages"]; - ExtractPages(pages, doc); + PdfDictionary resources = null; + if (doc.Catalog.Values.ContainsKey("Resources")) + { + resources = doc.Catalog.Values["Resources"] as PdfDictionary; + } + ExtractPages(pages, doc, resources); return doc; } diff --git a/VAR.PdfTools/PdfDocumentPage.cs b/VAR.PdfTools/PdfDocumentPage.cs index 1c7faf4..bc80c1a 100644 --- a/VAR.PdfTools/PdfDocumentPage.cs +++ b/VAR.PdfTools/PdfDocumentPage.cs @@ -33,7 +33,7 @@ namespace VAR.PdfTools #region Life cycle - public PdfDocumentPage(PdfDictionary baseData, PdfDocumentPage prevDocPage) + public PdfDocumentPage(PdfDictionary baseData, PdfDictionary resources) { _baseData = baseData; string type = baseData.GetParamAsString("Type"); @@ -46,13 +46,13 @@ namespace VAR.PdfTools _content = _baseData.GetParamAsStream("Contents"); if (_baseData.Values.ContainsKey("Resources") == false) { - _resources = prevDocPage._resources; + _resources = resources; } else { _resources = _baseData.Values["Resources"] as PdfDictionary; } - if (_resources.Values.ContainsKey("Font")) + if (_resources != null && _resources.Values.ContainsKey("Font")) { PdfDictionary fonts = _resources.Values["Font"] as PdfDictionary; foreach (KeyValuePair pair in fonts.Values) diff --git a/VAR.PdfTools/PdfFont.cs b/VAR.PdfTools/PdfFont.cs index 037da5b..108743d 100644 --- a/VAR.PdfTools/PdfFont.cs +++ b/VAR.PdfTools/PdfFont.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace VAR.PdfTools { diff --git a/VAR.PdfTools/PdfTextExtractor.cs b/VAR.PdfTools/PdfTextExtractor.cs index 8260048..90e0391 100644 --- a/VAR.PdfTools/PdfTextExtractor.cs +++ b/VAR.PdfTools/PdfTextExtractor.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Text; -using System.Threading.Tasks; namespace VAR.PdfTools {