private PDFCosDictionary CopyResources(PDFCosDictionary resourcesDict) { PDFCosDictionary copy = new PDFCosDictionary(); copy[PDFNames.XObject] = Copy(resourcesDict[PDFNames.XObject] as PDFCosDictionary); copy[PDFNames.Font] = Copy(resourcesDict[PDFNames.Font] as PDFCosDictionary); copy[PDFNames.ColorSpace] = Copy(resourcesDict[PDFNames.ColorSpace] as PDFCosDictionary); copy[PDFNames.Pattern] = Copy(resourcesDict[PDFNames.Pattern] as PDFCosDictionary); copy[PDFNames.Shading] = resourcesDict[PDFNames.Shading] as PDFCosDictionary; copy[PDFNames.Properties] = resourcesDict[PDFNames.Properties] as PDFCosDictionary; copy[PDFNames.ProcSet] = resourcesDict[PDFNames.ProcSet] as PDFCosArray; return(copy); }
protected override void CleanUp() { base.CleanUp(); PDFCosDictionary resourcesDict = this.Context.ContentStreamContainer[PDFNames.Resources] as PDFCosDictionary; if (resourcesDict != null) { resourcesDict = CopyResources(resourcesDict); CleanUpResources(resourcesDict[PDFNames.ColorSpace] as PDFCosDictionary, colorspaces); CleanUpResources(resourcesDict[PDFNames.XObject] as PDFCosDictionary, xObjects); CleanUpResources(resourcesDict[PDFNames.Font] as PDFCosDictionary, fonts); CleanUpResources(resourcesDict[PDFNames.Pattern] as PDFCosDictionary, patterns); this.Context.ContentStreamContainer[PDFNames.Resources] = resourcesDict; } }
private PDFCosDictionary Copy(PDFCosDictionary dict) { if (dict == null) { return(null); } PDFCosDictionary copy = new PDFCosDictionary(); string[] keys = dict.Keys; foreach (string key in keys) { copy[key] = dict[key]; } return(copy); }
private void CleanUpResources(PDFCosDictionary resourcesDict, HashSet <string> usedResources) { if (resourcesDict == null) { return; } string[] keys = resourcesDict.Keys; foreach (string key in keys) { // The resources dictionary contains a key that is not used, remove it. if (!usedResources.Contains(key)) { resourcesDict[key] = null; } } }