本文整理匯總了C#中iTextSharp.text.pdf.PdfDictionary.Merge方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfDictionary.Merge方法的具體用法?C# PdfDictionary.Merge怎麽用?C# PdfDictionary.Merge使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfDictionary
的用法示例。
在下文中一共展示了PdfDictionary.Merge方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SetOriginalResources
internal void SetOriginalResources(PdfDictionary resources, int[] newNamePtr) {
if (newNamePtr != null)
namePtr = newNamePtr;
forbiddenNames = new Dictionary<PdfName,object>();
usedNames = new Dictionary<PdfName,PdfName>();
if (resources == null)
return;
originalResources = new PdfDictionary();
originalResources.Merge(resources);
foreach (PdfName key in resources.Keys) {
PdfObject sub = PdfReader.GetPdfObject(resources.Get(key));
if (sub != null && sub.IsDictionary()) {
PdfDictionary dic = (PdfDictionary)sub;
foreach (PdfName name in dic.Keys) {
forbiddenNames[name] = null;
}
PdfDictionary dic2 = new PdfDictionary();
dic2.Merge(dic);
originalResources.Put(key, dic2);
}
}
}
示例2: AddComments
/**
* @param fdf
* @throws IOException
*/
virtual public void AddComments(FdfReader fdf) {
if (readers2intrefs.ContainsKey(fdf))
return;
PdfDictionary catalog = fdf.Catalog;
catalog = catalog.GetAsDict(PdfName.FDF);
if (catalog == null)
return;
PdfArray annots = catalog.GetAsArray(PdfName.ANNOTS);
if (annots == null || annots.Size == 0)
return;
RegisterReader(fdf, false);
IntHashtable hits = new IntHashtable();
Dictionary<String, PdfObject> irt = new Dictionary<string,PdfObject>();
List<PdfObject> an = new List<PdfObject>();
for (int k = 0; k < annots.Size; ++k) {
PdfObject obj = annots[k];
PdfDictionary annot = (PdfDictionary)PdfReader.GetPdfObject(obj);
PdfNumber page = annot.GetAsNumber(PdfName.PAGE);
if (page == null || page.IntValue >= reader.NumberOfPages)
continue;
FindAllObjects(fdf, obj, hits);
an.Add(obj);
if (obj.Type == PdfObject.INDIRECT) {
PdfObject nm = PdfReader.GetPdfObject(annot.Get(PdfName.NM));
if (nm != null && nm.Type == PdfObject.STRING)
irt[nm.ToString()] = obj;
}
}
int[] arhits = hits.GetKeys();
for (int k = 0; k < arhits.Length; ++k) {
int n = arhits[k];
PdfObject obj = fdf.GetPdfObject(n);
if (obj.Type == PdfObject.DICTIONARY) {
PdfObject str = PdfReader.GetPdfObject(((PdfDictionary)obj).Get(PdfName.IRT));
if (str != null && str.Type == PdfObject.STRING) {
PdfObject i;
irt.TryGetValue(str.ToString(), out i);
if (i != null) {
PdfDictionary dic2 = new PdfDictionary();
dic2.Merge((PdfDictionary)obj);
dic2.Put(PdfName.IRT, i);
obj = dic2;
}
}
}
AddToBody(obj, GetNewObjectNumber(fdf, n, 0));
}
for (int k = 0; k < an.Count; ++k) {
PdfObject obj = an[k];
PdfDictionary annot = (PdfDictionary)PdfReader.GetPdfObject(obj);
PdfNumber page = annot.GetAsNumber(PdfName.PAGE);
PdfDictionary dic = reader.GetPageN(page.IntValue + 1);
PdfArray annotsp = (PdfArray)PdfReader.GetPdfObject(dic.Get(PdfName.ANNOTS), dic);
if (annotsp == null) {
annotsp = new PdfArray();
dic.Put(PdfName.ANNOTS, annotsp);
MarkUsed(dic);
}
MarkUsed(annotsp);
annotsp.Add(obj);
}
}
示例3: MergeAttrib
/**
* merge field attributes from two dictionaries
* @param parent one dictionary
* @param child the other dictionary
* @return a merged dictionary
*/
virtual protected PdfDictionary MergeAttrib(PdfDictionary parent, PdfDictionary child) {
PdfDictionary targ = new PdfDictionary();
if (parent != null) targ.Merge(parent);
foreach (PdfName key in child.Keys) {
if (key.Equals(PdfName.DR) || key.Equals(PdfName.DA) ||
key.Equals(PdfName.Q) || key.Equals(PdfName.FF) ||
key.Equals(PdfName.DV) || key.Equals(PdfName.V)
|| key.Equals(PdfName.FT) || key.Equals(PdfName.NM)
|| key.Equals(PdfName.F)) {
targ.Put(key,child.Get(key));
}
}
return targ;
}
示例4: AddFieldMDP
/**
* Adds keys to the signature dictionary that define
* the field permissions.
* This method is only used for signatures that lock fields.
* @param crypto the signature dictionary
*/
private void AddFieldMDP(PdfDictionary crypto, PdfDictionary fieldLock) {
PdfDictionary reference = new PdfDictionary();
PdfDictionary transformParams = new PdfDictionary();
transformParams.Merge(fieldLock);
transformParams.Put(PdfName.TYPE, PdfName.TRANSFORMPARAMS);
transformParams.Put(PdfName.V, new PdfName("1.2"));
reference.Put(PdfName.TRANSFORMMETHOD, PdfName.FIELDMDP);
reference.Put(PdfName.TYPE, PdfName.SIGREF);
reference.Put(PdfName.TRANSFORMPARAMS, transformParams);
reference.Put(new PdfName("DigestValue"), new PdfString("aa"));
PdfArray loc = new PdfArray();
loc.Add(new PdfNumber(0));
loc.Add(new PdfNumber(0));
reference.Put(new PdfName("DigestLocation"), loc);
reference.Put(new PdfName("DigestMethod"), new PdfName("MD5"));
reference.Put(PdfName.DATA, writer.reader.Trailer.Get(PdfName.ROOT));
PdfArray types = crypto.GetAsArray(PdfName.REFERENCE);
if (types == null)
types = new PdfArray();
types.Add(reference);
crypto.Put(PdfName.REFERENCE, types);
}
示例5: 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;
}
示例6: FileEmbedded
/**
* Creates a file specification with the file embedded. The file may
* come from the file system or from a byte array.
* @param writer the <CODE>PdfWriter</CODE>
* @param filePath the file path
* @param fileDisplay the file information that is presented to the user
* @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
* it takes precedence over <CODE>filePath</CODE>
* @param mimeType the optional mimeType
* @param fileParameter the optional extra file parameters such as the creation or modification date
* @param compressionLevel the level of compression
* @throws IOException on error
* @return the file specification
* @since 2.1.3
*/
public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) {
PdfFileSpecification fs = new PdfFileSpecification();
fs.writer = writer;
fs.Put(PdfName.F, new PdfString(fileDisplay));
PdfEFStream stream;
Stream inp = null;
PdfIndirectReference refi;
PdfIndirectReference refFileLength;
try {
refFileLength = writer.PdfIndirectReference;
if (fileStore == null) {
if (File.Exists(filePath)) {
inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
}
else {
if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) {
WebRequest w = WebRequest.Create(filePath);
inp = w.GetResponse().GetResponseStream();
}
else {
inp = BaseFont.GetResourceStream(filePath);
if (inp == null)
throw new IOException(filePath + " not found as file or resource.");
}
}
stream = new PdfEFStream(inp, writer);
}
else
stream = new PdfEFStream(fileStore);
stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
stream.FlateCompress(compressionLevel);
stream.Put(PdfName.PARAMS, refFileLength);
if (mimeType != null)
stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));
refi = writer.AddToBody(stream).IndirectReference;
if (fileStore == null) {
stream.WriteLength();
}
PdfDictionary param = new PdfDictionary();
if (fileParameter != null)
param.Merge(fileParameter);
param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
writer.AddToBody(param, refFileLength);
}
finally {
if (inp != null)
try{inp.Close();}catch{}
}
PdfDictionary f = new PdfDictionary();
f.Put(PdfName.F, refi);
fs.Put(PdfName.EF, f);
return fs;
}
示例7: GetFormXObject
/**
* Gets the content stream of a page as a PdfStream object.
* @param pageNumber the page of which you want the stream
* @param compressionLevel the compression level you want to apply to the stream
* @return a PdfStream object
* @since 2.1.3 (the method already existed without param compressionLevel)
*/
internal PdfStream GetFormXObject(int pageNumber, int compressionLevel) {
PdfDictionary page = reader.GetPageNRelease(pageNumber);
PdfObject contents = PdfReader.GetPdfObjectRelease(page.Get(PdfName.CONTENTS));
PdfDictionary dic = new PdfDictionary();
byte[] bout = null;
if (contents != null) {
if (contents.IsStream())
dic.Merge((PRStream)contents);
else
bout = reader.GetPageContent(pageNumber, file);
}
else
bout = new byte[0];
dic.Put(PdfName.RESOURCES, PdfReader.GetPdfObjectRelease(page.Get(PdfName.RESOURCES)));
dic.Put(PdfName.TYPE, PdfName.XOBJECT);
dic.Put(PdfName.SUBTYPE, PdfName.FORM);
PdfImportedPage impPage = importedPages[pageNumber];
dic.Put(PdfName.BBOX, new PdfRectangle(impPage.BoundingBox));
PdfArray matrix = impPage.Matrix;
if (matrix == null)
dic.Put(PdfName.MATRIX, IDENTITYMATRIX);
else
dic.Put(PdfName.MATRIX, matrix);
dic.Put(PdfName.FORMTYPE, ONE);
PRStream stream;
if (bout == null) {
stream = new PRStream((PRStream)contents, dic);
}
else {
stream = new PRStream(reader, bout);
stream.Merge(dic);
}
return stream;
}
示例8: PushPageAttributes
private void PushPageAttributes(PdfDictionary nodePages) {
PdfDictionary dic = new PdfDictionary();
if (pageInh.Count != 0) {
dic.Merge(pageInh[pageInh.Count - 1]);
}
for (int k = 0; k < pageInhCandidates.Length; ++k) {
PdfObject obj = nodePages.Get(pageInhCandidates[k]);
if (obj != null)
dic.Put(pageInhCandidates[k], obj);
}
pageInh.Add(dic);
}
示例9: Fill
internal void Fill()
{
fields = new Hashtable();
PdfDictionary top = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
if (top == null)
return;
PdfArray arrfds = (PdfArray)PdfReader.GetPdfObjectRelease(top.Get(PdfName.FIELDS));
if (arrfds == null || arrfds.Size == 0)
return;
for (int k = 1; k <= reader.NumberOfPages; ++k) {
PdfDictionary page = reader.GetPageNRelease(k);
PdfArray annots = (PdfArray)PdfReader.GetPdfObjectRelease(page.Get(PdfName.ANNOTS), page);
if (annots == null)
continue;
for (int j = 0; j < annots.Size; ++j) {
PdfDictionary annot = annots.GetAsDict(j);
if (annot == null) {
PdfReader.ReleaseLastXrefPartial(annots.GetAsIndirectObject(j));
continue;
}
if (!PdfName.WIDGET.Equals(annot.GetAsName(PdfName.SUBTYPE))) {
PdfReader.ReleaseLastXrefPartial(annots.GetAsIndirectObject(j));
continue;
}
PdfDictionary widget = annot;
PdfDictionary dic = new PdfDictionary();
dic.Merge(annot);
String name = "";
PdfDictionary value = null;
PdfObject lastV = null;
while (annot != null) {
dic.MergeDifferent(annot);
PdfString t = annot.GetAsString(PdfName.T);
if (t != null)
name = t.ToUnicodeString() + "." + name;
if (lastV == null && annot.Get(PdfName.V) != null)
lastV = PdfReader.GetPdfObjectRelease(annot.Get(PdfName.V));
if (value == null && t != null) {
value = annot;
if (annot.Get(PdfName.V) == null && lastV != null)
value.Put(PdfName.V, lastV);
}
annot = annot.GetAsDict(PdfName.PARENT);
}
if (name.Length > 0)
name = name.Substring(0, name.Length - 1);
Item item = (Item)fields[name];
if (item == null) {
item = new Item();
fields[name] = item;
}
if (value == null)
item.AddValue(widget);
else
item.AddValue(value);
item.AddWidget(widget);
item.AddWidgetRef(annots.GetAsIndirectObject(j)); // must be a reference
if (top != null)
dic.MergeDifferent(top);
item.AddMerged(dic);
item.AddPage(k);
item.AddTabOrder(j);
}
}
// some tools produce invisible signatures without an entry in the page annotation array
// look for a single level annotation
PdfNumber sigFlags = top.GetAsNumber(PdfName.SIGFLAGS);
if (sigFlags == null || (sigFlags.IntValue & 1) != 1)
return;
for (int j = 0; j < arrfds.Size; ++j) {
PdfDictionary annot = arrfds.GetAsDict(j);
if (annot == null) {
PdfReader.ReleaseLastXrefPartial(arrfds.GetAsIndirectObject(j));
continue;
}
if (!PdfName.WIDGET.Equals(annot.GetAsName(PdfName.SUBTYPE))) {
PdfReader.ReleaseLastXrefPartial(arrfds.GetAsIndirectObject(j));
continue;
}
PdfArray kids = (PdfArray)PdfReader.GetPdfObjectRelease(annot.Get(PdfName.KIDS));
if (kids != null)
continue;
PdfDictionary dic = new PdfDictionary();
dic.Merge(annot);
PdfString t = annot.GetAsString(PdfName.T);
if (t == null)
continue;
String name = t.ToUnicodeString();
if (fields.ContainsKey(name))
continue;
Item item = new Item();
fields[name] = item;
item.AddValue(dic);
item.AddWidget(dic);
item.AddWidgetRef(arrfds.GetAsIndirectObject(j)); // must be a reference
item.AddMerged(dic);
item.AddPage(-1);
item.AddTabOrder(-1);
}
}
示例10: FileEmbedded
/**
* Creates a file specification with the file embedded. The file may
* come from the file system or from a byte array.
* @param writer the <CODE>PdfWriter</CODE>
* @param filePath the file path
* @param fileDisplay the file information that is presented to the user
* @param fileStore the byte array with the file. If it is not <CODE>null</CODE>
* it takes precedence over <CODE>filePath</CODE>
* @param mimeType the optional mimeType
* @param fileParameter the optional extra file parameters such as the creation or modification date
* @param compressionLevel the level of compression
* @throws IOException on error
* @return the file specification
* @since 2.1.3
*/
public static PdfFileSpecification FileEmbedded(PdfWriter writer, String filePath, String fileDisplay, byte[] fileStore, String mimeType, PdfDictionary fileParameter, int compressionLevel) {
PdfFileSpecification fs = new PdfFileSpecification();
fs.writer = writer;
fs.Put(PdfName.F, new PdfString(fileDisplay));
fs.SetUnicodeFileName(fileDisplay, false);
PdfEFStream stream;
Stream inp = null;
PdfIndirectReference refi;
PdfIndirectReference refFileLength = null;
try {
if (fileStore == null) {
refFileLength = writer.PdfIndirectReference;
if (File.Exists(filePath)) {
inp = new FileStream(filePath, FileMode.Open, FileAccess.Read);
}
else {
if (filePath.StartsWith("file:/") || filePath.StartsWith("http://") || filePath.StartsWith("https://")) {
WebRequest wr = WebRequest.Create(filePath);
wr.Credentials = CredentialCache.DefaultCredentials;
inp = wr.GetResponse().GetResponseStream();
}
else {
inp = StreamUtil.GetResourceStream(filePath);
if (inp == null)
throw new IOException(MessageLocalization.GetComposedMessage("1.not.found.as.file.or.resource", filePath));
}
}
stream = new PdfEFStream(inp, writer);
}
else
stream = new PdfEFStream(fileStore);
stream.Put(PdfName.TYPE, PdfName.EMBEDDEDFILE);
stream.FlateCompress(compressionLevel);
PdfDictionary param = new PdfDictionary();
if (fileParameter != null)
param.Merge(fileParameter);
if (!param.Contains(PdfName.MODDATE)) {
param.Put(PdfName.MODDATE, new PdfDate());
}
if (fileStore != null) {
param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
stream.Put(PdfName.PARAMS, param);
}
else {
stream.Put(PdfName.PARAMS, refFileLength);
}
if (mimeType != null)
stream.Put(PdfName.SUBTYPE, new PdfName(mimeType));
refi = writer.AddToBody(stream).IndirectReference;
if (fileStore == null) {
stream.WriteLength();
param.Put(PdfName.SIZE, new PdfNumber(stream.RawLength));
writer.AddToBody(param, refFileLength);
}
}
finally {
if (inp != null)
try{inp.Close();}catch{}
}
PdfDictionary f = new PdfDictionary();
f.Put(PdfName.F, refi);
f.Put(PdfName.UF, refi);
fs.Put(PdfName.EF, f);
return fs;
}
示例11: ReadXRefStream
virtual protected internal bool ReadXRefStream(long ptr) {
tokens.Seek(ptr);
int thisStream = 0;
if (!tokens.NextToken())
return false;
if (tokens.TokenType != PRTokeniser.TokType.NUMBER)
return false;
thisStream = tokens.IntValue;
if (!tokens.NextToken() || tokens.TokenType != PRTokeniser.TokType.NUMBER)
return false;
if (!tokens.NextToken() || !tokens.StringValue.Equals("obj"))
return false;
PdfObject objecto = ReadPRObject();
PRStream stm = null;
if (objecto.IsStream()) {
stm = (PRStream)objecto;
if (!PdfName.XREF.Equals(stm.Get(PdfName.TYPE)))
return false;
}
else
return false;
if (trailer == null) {
trailer = new PdfDictionary();
trailer.Merge(stm);
}
stm.Length = ((PdfNumber)stm.Get(PdfName.LENGTH)).IntValue;
int size = ((PdfNumber)stm.Get(PdfName.SIZE)).IntValue;
PdfArray index;
PdfObject obj = stm.Get(PdfName.INDEX);
if (obj == null) {
index = new PdfArray();
index.Add(new int[]{0, size});
}
else
index = (PdfArray)obj;
PdfArray w = (PdfArray)stm.Get(PdfName.W);
long prev = -1;
obj = stm.Get(PdfName.PREV);
if (obj != null)
prev = ((PdfNumber)obj).LongValue;
// Each xref pair is a position
// type 0 -> -1, 0
// type 1 -> offset, 0
// type 2 -> index, obj num
EnsureXrefSize(size * 2);
if (objStmMark == null && !partial)
objStmMark = new Dictionary<int,IntHashtable>();
if (objStmToOffset == null && partial)
objStmToOffset = new LongHashtable();
byte[] b = GetStreamBytes(stm, tokens.File);
int bptr = 0;
int[] wc = new int[3];
for (int k = 0; k < 3; ++k)
wc[k] = w.GetAsNumber(k).IntValue;
for (int idx = 0; idx < index.Size; idx += 2) {
int start = index.GetAsNumber(idx).IntValue;
int length = index.GetAsNumber(idx + 1).IntValue;
EnsureXrefSize((start + length) * 2);
while (length-- > 0) {
int type = 1;
if (wc[0] > 0) {
type = 0;
for (int k = 0; k < wc[0]; ++k)
type = (type << 8) + (b[bptr++] & 0xff);
}
long field2 = 0;
for (int k = 0; k < wc[1]; ++k)
field2 = (field2 << 8) + (b[bptr++] & 0xff);
int field3 = 0;
for (int k = 0; k < wc[2]; ++k)
field3 = (field3 << 8) + (b[bptr++] & 0xff);
int baseb = start * 2;
if (xref[baseb] == 0 && xref[baseb + 1] == 0) {
switch (type) {
case 0:
xref[baseb] = -1;
break;
case 1:
xref[baseb] = field2;
break;
case 2:
xref[baseb] = field3;
xref[baseb + 1] = field2;
if (partial) {
objStmToOffset[field2] = 0;
}
else {
IntHashtable seq;
if (!objStmMark.TryGetValue((int)field2, out seq)) {
seq = new IntHashtable();
seq[field3] = 1;
objStmMark[(int)field2] = seq;
}
else
seq[field3] = 1;
}
break;
}
}
++start;
//.........這裏部分代碼省略.........
示例12: 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);
}
}
}
示例13: 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);
}
}
}
示例14: 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;
}
示例15: Fill
internal void Fill()
{
fields = new Hashtable();
PdfDictionary top = (PdfDictionary)PdfReader.GetPdfObjectRelease(reader.Catalog.Get(PdfName.ACROFORM));
if (top == null)
return;
PdfArray arrfds = (PdfArray)PdfReader.GetPdfObjectRelease(top.Get(PdfName.FIELDS));
if (arrfds == null || arrfds.Size == 0)
return;
arrfds = null;
for (int k = 1; k <= reader.NumberOfPages; ++k) {
PdfDictionary page = reader.GetPageNRelease(k);
PdfArray annots = (PdfArray)PdfReader.GetPdfObjectRelease(page.Get(PdfName.ANNOTS), page);
if (annots == null)
continue;
ArrayList arr = annots.ArrayList;
for (int j = 0; j < arr.Count; ++j) {
PdfObject annoto = PdfReader.GetPdfObject((PdfObject)arr[j], annots);
if (!(annoto is PdfDictionary)) {
PdfReader.ReleaseLastXrefPartial((PdfObject)arr[j]);
continue;
}
PdfDictionary annot = (PdfDictionary)annoto;
if (!PdfName.WIDGET.Equals(annot.Get(PdfName.SUBTYPE))) {
PdfReader.ReleaseLastXrefPartial((PdfObject)arr[j]);
continue;
}
PdfDictionary widget = annot;
PdfDictionary dic = new PdfDictionary();
dic.Merge(annot);
String name = "";
PdfDictionary value = null;
PdfObject lastV = null;
while (annot != null) {
dic.MergeDifferent(annot);
PdfString t = (PdfString)PdfReader.GetPdfObject(annot.Get(PdfName.T));
if (t != null)
name = t.ToUnicodeString() + "." + name;
if (lastV == null && annot.Get(PdfName.V) != null)
lastV = PdfReader.GetPdfObjectRelease(annot.Get(PdfName.V));
if (value == null && t != null) {
value = annot;
if (annot.Get(PdfName.V) == null && lastV != null)
value.Put(PdfName.V, lastV);
}
annot = (PdfDictionary)PdfReader.GetPdfObject(annot.Get(PdfName.PARENT), annot);
}
if (name.Length > 0)
name = name.Substring(0, name.Length - 1);
Item item = (Item)fields[name];
if (item == null) {
item = new Item();
fields[name] = item;
}
if (value == null)
item.values.Add(widget);
else
item.values.Add(value);
item.widgets.Add(widget);
item.widget_refs.Add(arr[j]); // must be a reference
if (top != null)
dic.MergeDifferent(top);
item.merged.Add(dic);
item.page.Add(k);
item.tabOrder.Add(j);
}
}
}