本文整理匯總了C#中PdfSharp.Pdf.PdfDictionary.Clone方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.Clone方法的具體用法?C# PdfDictionary.Clone怎麽用?C# PdfDictionary.Clone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PdfSharp.Pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.Clone方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ProcessFilters
private static PdfDictionary ProcessFilters(PdfDictionary dictionary)
{
PdfDictionary result;
// Create a dictionary mapping (i.e. switch statement) to process the expected filters.
var map = new Dictionary<string, Func<byte[], byte[]>>() {
{ "/FlateDecode", (d) => {
var decoder = new FlateDecode();
return (decoder.Decode(d));
} }
};
// Get all of the filters.
var filters = ((PdfArray)dictionary.Elements["/Filter"])
.Elements.Where(e => e.IsName())
.Select(e => ((PdfName)e).Value)
.ToList();
// If only one filter in array. Just rewrite the /Filter
if (filters.Count == 1) {
result = dictionary.Clone();
result.Elements["/Filter"] = new PdfName(filters[0]);
return (result);
}
// Process each filter in order. The last filter should be the actual encoded image.
byte[] data = dictionary.Stream.Value;
for(int index = 0; index < (filters.Count - 1); index++) {
if (! map.ContainsKey(filters[index])) {
throw new NotSupportedException(String.Format("Encountered embedded image with multiple filters: \"{0}\". Unable to process the filter: \"{1}\".",
String.Join(",", filters), filters[index]));
}
data = map[filters[index]].Invoke(data);
}
result = new PdfDictionary();
result.Elements.Add("/Filter", new PdfName(filters.Last()));
foreach (var element in dictionary.Elements.Where(e => !String.Equals(e.Key, "/Filter", StringComparison.OrdinalIgnoreCase))) {
result.Elements.Add(element.Key, element.Value);
}
result.CreateStream(data);
return(result);
}