本文整理匯總了C#中iTextSharp.text.pdf.PdfDictionary.GetAsName方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.GetAsName方法的具體用法?C# PdfDictionary.GetAsName怎麽用?C# PdfDictionary.GetAsName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.GetAsName方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: UnembedTTF
/**
* Processes a dictionary.
* In case of font dictionaries, the dictionary is processed.
*/
public void UnembedTTF(PdfDictionary dict)
{
// we ignore all dictionaries that aren't font dictionaries
if (!dict.IsFont())
return;
// we only remove TTF fonts
if (dict.GetAsDict(PdfName.FONTFILE2) != null)
{
return;
}
// check if a subset was used (in which case we remove the prefix)
PdfName baseFont = dict.GetAsName(PdfName.BASEFONT);
if (baseFont.GetBytes()[7] == '+')
{
baseFont = new PdfName(baseFont.ToString().Substring(8));
dict.Put(PdfName.BASEFONT, baseFont);
}
// we check if there's a font descriptor
PdfDictionary fontDescriptor = dict.GetAsDict(PdfName.FONTDESCRIPTOR);
if (fontDescriptor == null)
return;
// is there is, we replace the fontname and remove the font file
fontDescriptor.Put(PdfName.FONTNAME, baseFont);
fontDescriptor.Remove(PdfName.FONTFILE2);
}
示例2: DocumentFont
/** Creates a new instance of DocumentFont */
internal DocumentFont(PRIndirectReference refFont) {
encoding = "";
fontSpecific = false;
this.refFont = refFont;
fontType = FONT_TYPE_DOCUMENT;
font = (PdfDictionary)PdfReader.GetPdfObject(refFont);
PdfName baseFont = font.GetAsName(PdfName.BASEFONT);
fontName = baseFont != null ? PdfName.DecodeName(baseFont.ToString()) : "Unspecified Font Name";
PdfName subType = font.GetAsName(PdfName.SUBTYPE);
if (PdfName.TYPE1.Equals(subType) || PdfName.TRUETYPE.Equals(subType))
DoType1TT();
else {
for (int k = 0; k < cjkNames.Length; ++k) {
if (fontName.StartsWith(cjkNames[k])) {
fontName = cjkNames[k];
cjkMirror = BaseFont.CreateFont(fontName, cjkEncs[k], false);
return;
}
}
PdfName encodingName = font.GetAsName(PdfName.ENCODING);
if (encodingName != null){
String enc = PdfName.DecodeName(encodingName.ToString());
for (int k = 0; k < cjkEncs2.Length; ++k) {
if (enc.StartsWith(cjkEncs2[k])) {
if (k > 3)
k -= 4;
cjkMirror = BaseFont.CreateFont(cjkNames2[k], cjkEncs2[k], false);
return;
}
}
if (PdfName.TYPE0.Equals(subType) && enc.Equals("Identity-H")) {
ProcessType0(font);
isType0 = true;
}
}
}
}
示例3: GetAppearance
internal PdfAppearance GetAppearance(PdfDictionary merged, String text, String fieldName)
{
topFirst = 0;
TextField tx = null;
if (fieldCache == null || !fieldCache.ContainsKey(fieldName)) {
tx = new TextField(writer, null, null);
tx.SetExtraMargin(extraMarginLeft, extraMarginTop);
tx.BorderWidth = 0;
tx.SubstitutionFonts = substitutionFonts;
DecodeGenericDictionary(merged, tx);
//rect
PdfArray rect = merged.GetAsArray(PdfName.RECT);
Rectangle box = PdfReader.GetNormalizedRectangle(rect);
if (tx.Rotation == 90 || tx.Rotation == 270)
box = box.Rotate();
tx.Box = box;
if (fieldCache != null)
fieldCache[fieldName] = tx;
}
else {
tx = (TextField)fieldCache[fieldName];
tx.Writer = writer;
}
PdfName fieldType = merged.GetAsName(PdfName.FT);
if (PdfName.TX.Equals(fieldType)) {
tx.Text = text;
return tx.GetAppearance();
}
if (!PdfName.CH.Equals(fieldType))
throw new DocumentException("An appearance was requested without a variable text field.");
PdfArray opt = merged.GetAsArray(PdfName.OPT);
int flags = 0;
PdfNumber nfl = merged.GetAsNumber(PdfName.FF);
if (nfl != null)
flags = nfl.IntValue;
if ((flags & PdfFormField.FF_COMBO) != 0 && opt == null) {
tx.Text = text;
return tx.GetAppearance();
}
if (opt != null) {
String[] choices = new String[opt.Size];
String[] choicesExp = new String[opt.Size];
for (int k = 0; k < opt.Size; ++k) {
PdfObject obj = opt[k];
if (obj.IsString()) {
choices[k] = choicesExp[k] = ((PdfString)obj).ToUnicodeString();
}
else {
PdfArray a = (PdfArray) obj;
choicesExp[k] = a.GetAsString(0).ToUnicodeString();
choices[k] = a.GetAsString(1).ToUnicodeString();
}
}
if ((flags & PdfFormField.FF_COMBO) != 0) {
for (int k = 0; k < choices.Length; ++k) {
if (text.Equals(choicesExp[k])) {
text = choices[k];
break;
}
}
tx.Text = text;
return tx.GetAppearance();
}
int idx = 0;
for (int k = 0; k < choicesExp.Length; ++k) {
if (text.Equals(choicesExp[k])) {
idx = k;
break;
}
}
tx.Choices = choices;
tx.ChoiceExports = choicesExp;
tx.ChoiceSelection = idx;
}
PdfAppearance app = tx.GetListAppearance();
topFirst = tx.TopFirst;
return app;
}
示例4: InspectChildDictionary
/**
* If the child of a structured element is a dictionary, we inspect the
* child; we may also draw a tag.
*
* @param k
* the child dictionary to inspect
*/
public void InspectChildDictionary(PdfDictionary k) {
if (k == null)
return;
PdfName s = k.GetAsName(PdfName.S);
if (s != null) {
String tagN = PdfName.DecodeName(s.ToString());
String tag = FixTagName(tagN);
outp.Write("<");
outp.Write(tag);
outp.Write(">");
PdfDictionary dict = k.GetAsDict(PdfName.PG);
if (dict != null)
ParseTag(tagN, k.GetDirectObject(PdfName.K), dict);
InspectChild(k.Get(PdfName.K));
outp.Write("</");
outp.Write(tag);
outp.WriteLine(">");
} else
InspectChild(k.Get(PdfName.K));
}
示例5: CopyDictionary
/**
* Translate a PRDictionary to a PdfDictionary. Also translate all of the
* objects contained in it.
*/
protected PdfDictionary CopyDictionary(PdfDictionary inp, bool keepStruct, bool directRootKids) {
PdfDictionary outp = new PdfDictionary();
PdfObject type = PdfReader.GetPdfObjectRelease(inp.Get(PdfName.TYPE));
if (keepStruct)
{
if ((directRootKids) && (inp.Contains(PdfName.PG)))
{
PdfObject curr = inp;
disableIndirects.Add(curr);
while (parentObjects.ContainsKey(curr) && !(disableIndirects.Contains(curr))) {
curr = parentObjects[curr];
disableIndirects.Add(curr);
}
return null;
}
PdfName structType = inp.GetAsName(PdfName.S);
structTreeController.AddRole(structType);
structTreeController.AddClass(inp);
}
if (structTreeController != null && structTreeController.reader != null && (inp.Contains(PdfName.STRUCTPARENTS) || inp.Contains(PdfName.STRUCTPARENT))) {
PdfName key = PdfName.STRUCTPARENT;
if (inp.Contains(PdfName.STRUCTPARENTS)) {
key = PdfName.STRUCTPARENTS;
}
PdfObject value = inp.Get(key);
outp.Put(key, new PdfNumber(currentStructArrayNumber));
structTreeController.CopyStructTreeForPage((PdfNumber) value, currentStructArrayNumber++);
}
foreach (PdfName key in inp.Keys) {
PdfObject value = inp.Get(key);
if (structTreeController != null && structTreeController.reader != null &&
(key.Equals(PdfName.STRUCTPARENTS) || key.Equals(PdfName.STRUCTPARENT))) {
continue;
}
if (PdfName.PAGE.Equals(type))
{
if (!key.Equals(PdfName.B) && !key.Equals(PdfName.PARENT))
{
parentObjects[value] = inp;
PdfObject res = CopyObject(value, keepStruct, directRootKids);
if ((res != null) && !(res is PdfNull))
outp.Put(key, res);
}
}
else
{
PdfObject res;
if (tagged && value.IsIndirect() && IsStructTreeRootReference((PRIndirectReference) value))
res = structureTreeRoot.Reference;
else
res = CopyObject(value, keepStruct, directRootKids);
if ((res != null) && !(res is PdfNull))
outp.Put(key, res);
}
}
return outp;
}
示例6: BranchForm
virtual protected PdfArray BranchForm(Dictionary<string,object> level, PdfIndirectReference parent, String fname) {
PdfArray arr = new PdfArray();
foreach (KeyValuePair<string,object> entry in level) {
String name = entry.Key;
Object obj = entry.Value;
PdfIndirectReference ind = PdfIndirectReference;
PdfDictionary dic = new PdfDictionary();
if (parent != null)
dic.Put(PdfName.PARENT, parent);
dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
String fname2 = fname + "." + name;
int coidx = calculationOrder.IndexOf(fname2);
if (coidx >= 0)
calculationOrderRefs[coidx] = ind;
if (obj is Dictionary<string,object>) {
dic.Put(PdfName.KIDS, BranchForm((Dictionary<string,object>)obj, ind, fname2));
arr.Add(ind);
AddToBody(dic, ind);
}
else {
List<object> list = (List<object>)obj;
dic.MergeDifferent((PdfDictionary)list[0]);
if (list.Count == 3) {
dic.MergeDifferent((PdfDictionary)list[2]);
int page = (int)list[1];
PdfDictionary pageDic = pageDics[page - 1];
PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
if (annots == null) {
annots = new PdfArray();
pageDic.Put(PdfName.ANNOTS, annots);
}
PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
dic.Remove(iTextTag);
AdjustTabOrder(annots, ind, nn);
}
else {
PdfDictionary field = (PdfDictionary) list[0];
PdfName v = field.GetAsName(PdfName.V);
PdfArray kids = new PdfArray();
for (int k = 1; k < list.Count; k += 2) {
int page = (int)list[k];
PdfDictionary pageDic = pageDics[page - 1];
PdfArray annots = pageDic.GetAsArray(PdfName.ANNOTS);
if (annots == null) {
annots = new PdfArray();
pageDic.Put(PdfName.ANNOTS, annots);
}
PdfDictionary widget = new PdfDictionary();
widget.Merge((PdfDictionary) list[k + 1]);
widget.Put(PdfName.PARENT, ind);
PdfNumber nn = (PdfNumber) widget.Get(iTextTag);
widget.Remove(iTextTag);
if (PdfCopy.IsCheckButton(field)) {
PdfName _as = widget.GetAsName(PdfName.AS);
if (v != null && _as != null)
widget.Put(PdfName.AS, v);
} else if (PdfCopy.IsRadioButton(field)) {
PdfName _as = widget.GetAsName(PdfName.AS);
if (v != null && _as != null && !_as.Equals(GetOffStateName(widget))) {
if (!mergedRadioButtons.ContainsKey(list)) {
mergedRadioButtons[list] = null;
widget.Put(PdfName.AS, v);
} else {
widget.Put(PdfName.AS, GetOffStateName(widget));
}
}
}
PdfIndirectReference wref = AddToBody(widget).IndirectReference;
AdjustTabOrder(annots, wref, nn);
kids.Add(wref);
Propagate(widget, null, false);
}
dic.Put(PdfName.KIDS, kids);
}
arr.Add(ind);
AddToBody(dic, ind);
Propagate(dic, null, false);
}
}
return arr;
}
示例7: ComputeBytesPerRow
/**
* Computes the number of unfiltered bytes that each row of the image will contain.
* If the number of bytes results in a partial terminating byte, this number is rounded up
* per the PDF specification
* @param imageDictionary the dictionary of the inline image
* @return the number of bytes per row of the image
*/
private static int ComputeBytesPerRow(PdfDictionary imageDictionary, PdfDictionary colorSpaceDic)
{
PdfNumber wObj = imageDictionary.GetAsNumber(PdfName.WIDTH);
PdfNumber bpcObj = imageDictionary.GetAsNumber(PdfName.BITSPERCOMPONENT);
int cpp = GetComponentsPerPixel(imageDictionary.GetAsName(PdfName.COLORSPACE), colorSpaceDic);
int w = wObj.IntValue;
int bpc = bpcObj != null ? bpcObj.IntValue : 1;
int bytesPerRow = (w * bpc * cpp + 7) / 8;
return bytesPerRow;
}
示例8: DocumentFont
/** Creates a new instance of DocumentFont */
internal DocumentFont(PRIndirectReference refFont, PdfDictionary drEncoding) {
this.refFont = refFont;
font = (PdfDictionary) PdfReader.GetPdfObject(refFont);
if (font.GetAsName(PdfName.ENCODING) == null
&& drEncoding != null) {
foreach (PdfName key in drEncoding.Keys) {
font.Put(PdfName.ENCODING, drEncoding.Get(key));
}
}
Init();
}
示例9: IsTextField
internal static bool IsTextField(PdfDictionary field) {
PdfName type = field.GetAsName(PdfName.FT);
return PdfName.TX.Equals(type);
}
示例10: GetFlags
internal static int? GetFlags(PdfDictionary field) {
PdfName type = field.GetAsName(PdfName.FT);
if (!PdfName.BTN.Equals(type))
return null;
PdfNumber flags = field.GetAsNumber(PdfName.FF);
if (flags == null)
return null;
return flags.IntValue;
}
示例11: BranchForm
private PdfArray BranchForm(Dictionary<String, Object> level, PdfIndirectReference parent, String fname) {
PdfArray arr = new PdfArray();
foreach (KeyValuePair<String, Object> entry in level) {
String name = entry.Key;
Object obj = entry.Value;
PdfIndirectReference ind = PdfIndirectReference;
PdfDictionary dic = new PdfDictionary();
if (parent != null)
dic.Put(PdfName.PARENT, parent);
dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
String fname2 = fname + "." + name;
int coidx = calculationOrder.IndexOf(fname2);
if (coidx >= 0)
calculationOrderRefs[coidx] = ind;
if (obj is Dictionary<String, Object>) {
dic.Put(PdfName.KIDS, BranchForm((Dictionary<String, Object>) obj, ind, fname2));
arr.Add(ind);
AddToBody(dic, ind, true);
} else {
List<Object> list = (List<Object>)obj;
dic.MergeDifferent((PdfDictionary) list[0]);
if (list.Count == 3) {
dic.MergeDifferent((PdfDictionary)list[2]);
int page = (int)list[1];
PdfArray annots = importedPages[page - 1].mergedFields;
PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
dic.Remove(iTextTag);
dic.Put(PdfName.TYPE, PdfName.ANNOT);
AdjustTabOrder(annots, ind, nn);
} else {
PdfDictionary field = (PdfDictionary)list[0];
PdfArray kids = new PdfArray();
for (int k = 1; k < list.Count; k += 2) {
int page = (int)list[k];
PdfArray annots = importedPages[page - 1].mergedFields;
PdfDictionary widget = new PdfDictionary();
widget.Merge((PdfDictionary)list[k + 1]);
widget.Put(PdfName.PARENT, ind);
PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
widget.Remove(iTextTag);
if (PdfCopy.IsTextField(field)) {
PdfString v = field.GetAsString(PdfName.V);
PdfObject ap = widget.GetDirectObject(PdfName.AP);
if (v != null && ap != null) {
if (!mergedTextFields.ContainsKey(list)) {
mergedTextFields[list] = v;
} else {
try {
TextField tx = new TextField(this, null, null);
fields[0].DecodeGenericDictionary(widget, tx);
Rectangle box =
PdfReader.GetNormalizedRectangle(widget.GetAsArray(PdfName.RECT));
if (tx.Rotation == 90 || tx.Rotation == 270) {
box = box.Rotate();
}
tx.Box = box;
tx.Text = mergedTextFields[list].ToUnicodeString();
PdfAppearance app = tx.GetAppearance();
((PdfDictionary) ap).Put(PdfName.N, app.IndirectReference);
}
catch (DocumentException ex) {
//do nothing
}
}
}
} else if (PdfCopy.IsCheckButton(field)) {
PdfName v = field.GetAsName(PdfName.V);
PdfName as_ = widget.GetAsName(PdfName.AS);
if (v != null && as_ != null)
widget.Put(PdfName.AS, v);
} else if (PdfCopy.IsRadioButton(field)) {
PdfName v = field.GetAsName(PdfName.V);
PdfName as_ = widget.GetAsName(PdfName.AS);
if (v != null && as_ != null && !as_.Equals(GetOffStateName(widget))) {
if (!mergedRadioButtons.Contains(list)) {
mergedRadioButtons.Add(list);
widget.Put(PdfName.AS, v);
} else {
widget.Put(PdfName.AS, GetOffStateName(widget));
}
}
}
widget.Put(PdfName.TYPE, PdfName.ANNOT);
PdfIndirectReference wref = AddToBody(widget, PdfIndirectReference, true).IndirectReference;
AdjustTabOrder(annots, wref, nn);
kids.Add(wref);
}
dic.Put(PdfName.KIDS, kids);
}
arr.Add(ind);
AddToBody(dic, ind, true);
}
}
return arr;
}
示例12: BranchForm
private PdfArray BranchForm(Dictionary<String, Object> level, PdfIndirectReference parent, String fname) {
PdfArray arr = new PdfArray();
foreach (KeyValuePair<String, Object> entry in level) {
String name = entry.Key;
Object obj = entry.Value;
PdfIndirectReference ind = PdfIndirectReference;
PdfDictionary dic = new PdfDictionary();
if (parent != null)
dic.Put(PdfName.PARENT, parent);
dic.Put(PdfName.T, new PdfString(name, PdfObject.TEXT_UNICODE));
String fname2 = fname + "." + name;
int coidx = calculationOrder.IndexOf(fname2);
if (coidx >= 0)
calculationOrderRefs[coidx] = ind;
if (obj is Dictionary<String, Object>) {
dic.Put(PdfName.KIDS, BranchForm((Dictionary<String, Object>) obj, ind, fname2));
arr.Add(ind);
AddToBody(dic, ind, true);
} else {
List<Object> list = (List<Object>)obj;
dic.MergeDifferent((PdfDictionary) list[0]);
if (list.Count == 3) {
dic.MergeDifferent((PdfDictionary)list[2]);
int page = (int)list[1];
PdfArray annots = importedPages[page - 1].mergedFields;
PdfNumber nn = (PdfNumber)dic.Get(iTextTag);
dic.Remove(iTextTag);
dic.Put(PdfName.TYPE, PdfName.ANNOT);
AdjustTabOrder(annots, ind, nn);
} else {
PdfDictionary field = (PdfDictionary)list[0];
PdfArray kids = new PdfArray();
for (int k = 1; k < list.Count; k += 2) {
int page = (int)list[k];
PdfArray annots = importedPages[page - 1].mergedFields;
PdfDictionary widget = new PdfDictionary();
widget.Merge((PdfDictionary)list[k + 1]);
widget.Put(PdfName.PARENT, ind);
PdfNumber nn = (PdfNumber)widget.Get(iTextTag);
widget.Remove(iTextTag);
if (PdfCopy.IsTextField(field)) {
PdfString v = field.GetAsString(PdfName.V);
PdfObject ap = widget.Get(PdfName.AP);
if (v != null && ap != null) {
if (!mergedTextFields.ContainsKey(list)) {
mergedTextFields[list] = ap;
} else {
PdfObject ap1 = mergedTextFields[list];
widget.Put(PdfName.AP, CopyObject(ap1));
}
}
} else if (PdfCopy.IsCheckButton(field)) {
PdfName v = field.GetAsName(PdfName.V);
PdfName as_ = widget.GetAsName(PdfName.AS);
if (v != null && as_ != null)
widget.Put(PdfName.AS, v);
} else if (PdfCopy.IsRadioButton(field)) {
PdfName v = field.GetAsName(PdfName.V);
PdfName as_ = widget.GetAsName(PdfName.AS);
if (v != null && as_ != null && !as_.Equals(GetOffStateName(widget))) {
if (!mergedRadioButtons.Contains(list)) {
mergedRadioButtons.Add(list);
widget.Put(PdfName.AS, v);
} else {
widget.Put(PdfName.AS, GetOffStateName(widget));
}
}
}
widget.Put(PdfName.TYPE, PdfName.ANNOT);
PdfIndirectReference wref = AddToBody(widget, PdfIndirectReference, true).IndirectReference;
AdjustTabOrder(annots, wref, nn);
kids.Add(wref);
}
dic.Put(PdfName.KIDS, kids);
}
arr.Add(ind);
AddToBody(dic, ind, true);
}
}
return arr;
}