本文整理匯總了C#中iTextSharp.text.pdf.PdfDictionary.Remove方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.Remove方法的具體用法?C# PdfDictionary.Remove怎麽用?C# PdfDictionary.Remove使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.Remove方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: MoveRectangle
private static void MoveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, String name) {
Rectangle m = r.GetBoxSize(pageImported, name);
if (m == null)
dic2.Remove(key);
else
dic2.Put(key, new PdfRectangle(m));
}
示例2: Close
//.........這裏部分代碼省略.........
if (append) {
int[] keys = marked.GetKeys();
for (int k = 0; k < keys.Length; ++k) {
int j = keys[k];
PdfObject obj = reader.GetPdfObjectRelease(j);
if (obj != null && skip != j && j < initialXrefSize) {
AddToBody(obj, j, j != rootN);
}
}
for (int k = initialXrefSize; k < reader.XrefSize; ++k) {
PdfObject obj = reader.GetPdfObject(k);
if (obj != null) {
AddToBody(obj, GetNewObjectNumber(reader, k, 0));
}
}
}
else {
for (int k = 1; k < reader.XrefSize; ++k) {
PdfObject obj = reader.GetPdfObjectRelease(k);
if (obj != null && skip != k) {
AddToBody(obj, GetNewObjectNumber(reader, k, 0), k != rootN);
}
}
}
}
finally {
try {
file.Close();
}
catch {
// empty on purpose
}
}
PdfIndirectReference encryption = null;
PdfObject fileID = null;
if (crypto != null) {
if (append) {
encryption = reader.GetCryptoRef();
}
else {
PdfIndirectObject encryptionObject = AddToBody(crypto.GetEncryptionDictionary(), false);
encryption = encryptionObject.IndirectReference;
}
fileID = crypto.FileID;
}
PRIndirectReference iRoot = (PRIndirectReference)reader.trailer.Get(PdfName.ROOT);
PdfIndirectReference root = new PdfIndirectReference(0, GetNewObjectNumber(reader, iRoot.Number, 0));
PdfIndirectReference info = null;
PdfDictionary oldInfo = (PdfDictionary)PdfReader.GetPdfObject(iInfo);
PdfDictionary newInfo = new PdfDictionary();
if (oldInfo != null) {
foreach (PdfName key in oldInfo.Keys) {
PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
newInfo.Put(key, value);
}
}
if (moreInfo != null) {
foreach (DictionaryEntry entry in moreInfo) {
PdfName keyName = new PdfName((String)entry.Key);
String value = (String)entry.Value;
if (value == null)
newInfo.Remove(keyName);
else
newInfo.Put(keyName, new PdfString(value, PdfObject.TEXT_UNICODE));
}
}
if (append) {
if (iInfo == null)
info = AddToBody(newInfo, false).IndirectReference;
else
info = AddToBody(newInfo, iInfo.Number, false).IndirectReference;
}
else {
if (newInfo.Size != 0)
info = AddToBody(newInfo, false).IndirectReference;
}
// write the cross-reference table of the body
body.WriteCrossReferenceTable(os, root, info, encryption, fileID, prevxref);
if (fullCompression) {
byte[] tmp = GetISOBytes("startxref\n");
os.Write(tmp, 0, tmp.Length);
tmp = GetISOBytes(body.Offset.ToString());
os.Write(tmp, 0, tmp.Length);
tmp = GetISOBytes("\n%%EOF\n");
os.Write(tmp, 0, tmp.Length);
}
else {
PdfTrailer trailer = new PdfTrailer(body.Size,
body.Offset,
root,
info,
encryption,
fileID, prevxref);
trailer.ToPdf(this, os);
}
os.Flush();
if (CloseStream)
os.Close();
reader.Close();
}
示例3: Close
//.........這裏部分代碼省略.........
}
PdfDictionary oldInfo = reader.Trailer.GetAsDict(PdfName.INFO);
String producer = null;
if (oldInfo != null && oldInfo.Get(PdfName.PRODUCER) != null) {
producer = oldInfo.GetAsString(PdfName.PRODUCER).ToUnicodeString();
}
Version version = Version.GetInstance();
if (producer == null || version.GetVersion.IndexOf(version.Product) == -1) {
producer = version.GetVersion;
} else {
int idx = producer.IndexOf("; modified using");
StringBuilder buf;
if (idx == -1)
buf = new StringBuilder(producer);
else
buf = new StringBuilder(producer.Substring(0, idx));
buf.Append("; modified using ");
buf.Append(version.GetVersion);
producer = buf.ToString();
}
PdfIndirectReference info = null;
PdfDictionary newInfo = new PdfDictionary();
if (oldInfo != null) {
foreach (PdfName key in oldInfo.Keys) {
PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
newInfo.Put(key, value);
}
}
if (moreInfo != null) {
foreach (KeyValuePair<string,string> entry in moreInfo) {
PdfName keyName = new PdfName(entry.Key);
String value = entry.Value;
if (value == null)
newInfo.Remove(keyName);
else
newInfo.Put(keyName, new PdfString(value, PdfObject.TEXT_UNICODE));
}
}
PdfDate date = new PdfDate();
newInfo.Put(PdfName.MODDATE, date);
newInfo.Put(PdfName.PRODUCER, new PdfString(producer, PdfObject.TEXT_UNICODE));
if (append) {
if (iInfo == null) {
info = AddToBody(newInfo, false).IndirectReference;
} else {
info = AddToBody(newInfo, iInfo.Number, false).IndirectReference;
}
} else {
info = AddToBody(newInfo, false).IndirectReference;
}
// XMP
byte[] altMetadata = null;
PdfObject xmpo = PdfReader.GetPdfObject(catalog.Get(PdfName.METADATA));
if (xmpo != null && xmpo.IsStream()) {
altMetadata = PdfReader.GetStreamBytesRaw((PRStream)xmpo);
PdfReader.KillIndirect(catalog.Get(PdfName.METADATA));
}
PdfStream xmp = null;
if (xmpMetadata != null) {
altMetadata = xmpMetadata;
} else if (xmpWriter != null) {
try {
MemoryStream baos = new MemoryStream();
PdfProperties.SetProducer(xmpWriter.XmpMeta, producer);
XmpBasicProperties.SetModDate(xmpWriter.XmpMeta, date.GetW3CDate());
XmpBasicProperties.SetMetaDataDate(xmpWriter.XmpMeta, date.GetW3CDate());
示例4: AddToCatalog
/**
* Adds the viewer preferences defined in the preferences parameter to a
* PdfDictionary (more specifically the root or catalog of a PDF file).
*
* @param catalog
*/
public void AddToCatalog(PdfDictionary catalog)
{
// Page Layout
catalog.Remove(PdfName.PAGELAYOUT);
if ((pageLayoutAndMode & PdfWriter.PageLayoutSinglePage) != 0)
catalog.Put(PdfName.PAGELAYOUT, PdfName.SINGLEPAGE);
else if ((pageLayoutAndMode & PdfWriter.PageLayoutOneColumn) != 0)
catalog.Put(PdfName.PAGELAYOUT, PdfName.ONECOLUMN);
else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnLeft) != 0)
catalog.Put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNLEFT);
else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoColumnRight) != 0)
catalog.Put(PdfName.PAGELAYOUT, PdfName.TWOCOLUMNRIGHT);
else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageLeft) != 0)
catalog.Put(PdfName.PAGELAYOUT, PdfName.TWOPAGELEFT);
else if ((pageLayoutAndMode & PdfWriter.PageLayoutTwoPageRight) != 0)
catalog.Put(PdfName.PAGELAYOUT, PdfName.TWOPAGERIGHT);
// Page Mode
catalog.Remove(PdfName.PAGEMODE);
if ((pageLayoutAndMode & PdfWriter.PageModeUseNone) != 0)
catalog.Put(PdfName.PAGEMODE, PdfName.USENONE);
else if ((pageLayoutAndMode & PdfWriter.PageModeUseOutlines) != 0)
catalog.Put(PdfName.PAGEMODE, PdfName.USEOUTLINES);
else if ((pageLayoutAndMode & PdfWriter.PageModeUseThumbs) != 0)
catalog.Put(PdfName.PAGEMODE, PdfName.USETHUMBS);
else if ((pageLayoutAndMode & PdfWriter.PageModeFullScreen) != 0)
catalog.Put(PdfName.PAGEMODE, PdfName.FULLSCREEN);
else if ((pageLayoutAndMode & PdfWriter.PageModeUseOC) != 0)
catalog.Put(PdfName.PAGEMODE, PdfName.USEOC);
else if ((pageLayoutAndMode & PdfWriter.PageModeUseAttachments) != 0)
catalog.Put(PdfName.PAGEMODE, PdfName.USEATTACHMENTS);
// viewer preferences (Table 8.1 of the PDF Reference)
catalog.Remove(PdfName.VIEWERPREFERENCES);
if (viewerPreferences.Size > 0) {
catalog.Put(PdfName.VIEWERPREFERENCES, viewerPreferences);
}
}
示例5: MoveFields
/**
* Moves the field keys from <CODE>from</CODE> to <CODE>to</CODE>. The moved keys
* are removed from <CODE>from</CODE>.
* @param from the source
* @param to the destination. It may be <CODE>null</CODE>
*/
public static void MoveFields(PdfDictionary from, PdfDictionary to)
{
PdfName[] keys = new PdfName[from.Size];
foreach (PdfName key in keys) {
if (fieldKeys.ContainsKey(key)) {
if (to != null)
to.Put(key, from.Get(key));
from.Remove(key);
}
}
}
示例6: Close
protected internal virtual void Close(IDictionary<String, String> moreInfo)
{
if (closed)
return;
if (useVp) {
SetViewerPreferences();
}
if (flat)
FlatFields();
if (flatFreeText)
FlatFreeTextFields();
AddFieldResources();
PdfDictionary catalog = reader.Catalog;
PdfDictionary acroForm = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.ACROFORM), reader.Catalog);
if (acroFields != null && acroFields.Xfa.Changed) {
MarkUsed(acroForm);
if (!flat)
acroFields.Xfa.SetXfa(this);
}
if (sigFlags != 0) {
if (acroForm != null) {
acroForm.Put(PdfName.SIGFLAGS, new PdfNumber(sigFlags));
MarkUsed(acroForm);
MarkUsed(catalog);
}
}
closed = true;
AddSharedObjectsToBody();
SetOutlines();
SetJavaScript();
AddFileAttachments();
if (openAction != null) {
catalog.Put(PdfName.OPENACTION, openAction);
}
if (pdf.pageLabels != null)
catalog.Put(PdfName.PAGELABELS, pdf.pageLabels.GetDictionary(this));
// OCG
if (documentOCG.Count > 0) {
FillOCProperties(false);
PdfDictionary ocdict = catalog.GetAsDict(PdfName.OCPROPERTIES);
if (ocdict == null) {
reader.Catalog.Put(PdfName.OCPROPERTIES, OCProperties);
}
else {
ocdict.Put(PdfName.OCGS, OCProperties.Get(PdfName.OCGS));
PdfDictionary ddict = ocdict.GetAsDict(PdfName.D);
if (ddict == null) {
ddict = new PdfDictionary();
ocdict.Put(PdfName.D, ddict);
}
ddict.Put(PdfName.ORDER, OCProperties.GetAsDict(PdfName.D).Get(PdfName.ORDER));
ddict.Put(PdfName.RBGROUPS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.RBGROUPS));
ddict.Put(PdfName.OFF, OCProperties.GetAsDict(PdfName.D).Get(PdfName.OFF));
ddict.Put(PdfName.AS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.AS));
}
}
// metadata
int skipInfo = -1;
PdfObject oInfo = reader.Trailer.Get(PdfName.INFO);
PRIndirectReference iInfo = null;
PdfDictionary oldInfo = null;
if (oInfo is PRIndirectReference)
iInfo = (PRIndirectReference)oInfo;
if (iInfo != null)
oldInfo = (PdfDictionary)PdfReader.GetPdfObject(iInfo);
else if (oInfo is PdfDictionary)
oldInfo = (PdfDictionary)oInfo;
String producer = null;
if (iInfo != null)
skipInfo = iInfo.Number;
if (oldInfo != null && oldInfo.Get(PdfName.PRODUCER) != null)
producer = oldInfo.GetAsString(PdfName.PRODUCER).ToUnicodeString();
Version version = Version.GetInstance();
if (producer == null) {
producer = version.GetVersion;
}
else if (producer.IndexOf(version.Product) == -1) {
StringBuilder buf = new StringBuilder(producer);
buf.Append("; modified using ");
buf.Append(version.GetVersion);
producer = buf.ToString();
}
PdfIndirectReference info = null;
PdfDictionary newInfo = new PdfDictionary();
if (oldInfo != null) {
foreach (PdfName key in oldInfo.Keys) {
PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
newInfo.Put(key, value);
}
}
if (moreInfo != null) {
foreach (KeyValuePair<string,string> entry in moreInfo) {
PdfName keyName = new PdfName(entry.Key);
String value = entry.Value;
if (value == null)
newInfo.Remove(keyName);
else
newInfo.Put(keyName, new PdfString(value, PdfObject.TEXT_UNICODE));
}
}
//.........這裏部分代碼省略.........
示例7: BranchForm
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 {
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);
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;
}
示例8: Close
internal void Close(IDictionary<String, String> moreInfo)
{
if (closed)
return;
if (useVp) {
reader.SetViewerPreferences(viewerPreferences);
MarkUsed(reader.Trailer.Get(PdfName.ROOT));
}
if (flat)
FlatFields();
if (flatFreeText)
FlatFreeTextFields();
AddFieldResources();
PdfDictionary catalog = reader.Catalog;
PdfDictionary pages = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.PAGES));
pages.Put(PdfName.ITXT, new PdfString(Document.Release));
MarkUsed(pages);
PdfDictionary acroForm = (PdfDictionary)PdfReader.GetPdfObject(catalog.Get(PdfName.ACROFORM), reader.Catalog);
if (acroFields != null && acroFields.Xfa.Changed) {
MarkUsed(acroForm);
if (!flat)
acroFields.Xfa.SetXfa(this);
}
if (sigFlags != 0) {
if (acroForm != null) {
acroForm.Put(PdfName.SIGFLAGS, new PdfNumber(sigFlags));
MarkUsed(acroForm);
MarkUsed(catalog);
}
}
closed = true;
AddSharedObjectsToBody();
SetOutlines();
SetJavaScript();
AddFileAttachments();
if (openAction != null) {
catalog.Put(PdfName.OPENACTION, openAction);
}
if (pdf.pageLabels != null)
catalog.Put(PdfName.PAGELABELS, pdf.pageLabels.GetDictionary(this));
// OCG
if (documentOCG.Count > 0) {
FillOCProperties(false);
PdfDictionary ocdict = catalog.GetAsDict(PdfName.OCPROPERTIES);
if (ocdict == null) {
reader.Catalog.Put(PdfName.OCPROPERTIES, OCProperties);
}
else {
ocdict.Put(PdfName.OCGS, OCProperties.Get(PdfName.OCGS));
PdfDictionary ddict = ocdict.GetAsDict(PdfName.D);
if (ddict == null) {
ddict = new PdfDictionary();
ocdict.Put(PdfName.D, ddict);
}
ddict.Put(PdfName.ORDER, OCProperties.GetAsDict(PdfName.D).Get(PdfName.ORDER));
ddict.Put(PdfName.RBGROUPS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.RBGROUPS));
ddict.Put(PdfName.OFF, OCProperties.GetAsDict(PdfName.D).Get(PdfName.OFF));
ddict.Put(PdfName.AS, OCProperties.GetAsDict(PdfName.D).Get(PdfName.AS));
}
}
// metadata
int skipInfo = -1;
PdfObject oInfo = reader.Trailer.Get(PdfName.INFO);
PRIndirectReference iInfo = null;
PdfDictionary oldInfo = null;
if (oInfo is PRIndirectReference)
iInfo = (PRIndirectReference)oInfo;
if (iInfo != null)
oldInfo = (PdfDictionary)PdfReader.GetPdfObject(iInfo);
else if (oInfo is PdfDictionary)
oldInfo = (PdfDictionary)oInfo;
String producer = null;
if (iInfo != null)
skipInfo = iInfo.Number;
if (oldInfo != null && oldInfo.Get(PdfName.PRODUCER) != null)
producer = oldInfo.GetAsString(PdfName.PRODUCER).ToUnicodeString();
if (producer == null) {
producer = Document.Version;
}
else if (producer.IndexOf(Document.Product) == -1) {
StringBuilder buf = new StringBuilder(producer);
buf.Append("; modified using ");
buf.Append(Document.Version);
producer = buf.ToString();
}
PdfIndirectReference info = null;
PdfDictionary newInfo = new PdfDictionary();
if (oldInfo != null) {
foreach (PdfName key in oldInfo.Keys) {
PdfObject value = PdfReader.GetPdfObject(oldInfo.Get(key));
newInfo.Put(key, value);
}
}
if (moreInfo != null) {
foreach (KeyValuePair<string,string> entry in moreInfo) {
PdfName keyName = new PdfName(entry.Key);
String value = entry.Value;
if (value == null)
newInfo.Remove(keyName);
else
//.........這裏部分代碼省略.........
示例9: KidNode
protected virtual void KidNode(PdfDictionary merged, String name) {
PdfArray kids = merged.GetAsArray(PdfName.KIDS);
if (kids == null || kids.Size == 0) {
if (name.Length > 0)
name = name.Substring(1);
fields[name] = merged;
}
else {
merged.Remove(PdfName.KIDS);
for (int k = 0; k < kids.Size; ++k) {
PdfDictionary dic = new PdfDictionary();
dic.Merge(merged);
PdfDictionary newDic = kids.GetAsDict(k);
PdfString t = newDic.GetAsString(PdfName.T);
String newName = name;
if (t != null)
newName += "." + t.ToUnicodeString();
dic.Merge(newDic);
dic.Remove(PdfName.T);
KidNode(dic, newName);
}
}
}
示例10: KidNode
protected virtual void KidNode(PdfDictionary merged, String name)
{
PdfArray kids = (PdfArray)GetPdfObject(merged.Get(PdfName.KIDS));
if (kids == null || kids.ArrayList.Count == 0) {
if (name.Length > 0)
name = name.Substring(1);
fields[name] = merged;
}
else {
merged.Remove(PdfName.KIDS);
ArrayList ar = kids.ArrayList;
for (int k = 0; k < ar.Count; ++k) {
PdfDictionary dic = new PdfDictionary();
dic.Merge(merged);
PdfDictionary newDic = (PdfDictionary)GetPdfObject((PdfObject)ar[k]);
PdfString t = (PdfString)GetPdfObject(newDic.Get(PdfName.T));
String newName = name;
if (t != null)
newName += "." + t.ToUnicodeString();
dic.Merge(newDic);
dic.Remove(PdfName.T);
KidNode(dic, newName);
}
}
}
示例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.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.ContainsKey(list)) {
mergedRadioButtons[list] = null;
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.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;
}