PdfDocumentPage: Fix resource inheritance
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<string, IPdfElement> pair in fonts.Values)
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VAR.PdfTools
|
||||
{
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user