本文整理汇总了C#中iTextSharp.text.pdf.RefKey类的典型用法代码示例。如果您正苦于以下问题:C# RefKey类的具体用法?C# RefKey怎么用?C# RefKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RefKey类属于iTextSharp.text.pdf命名空间,在下文中一共展示了RefKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyIndirect
protected override PdfIndirectReference CopyIndirect(PRIndirectReference @in) {
PdfObject srcObj = PdfReader.GetPdfObjectRelease(@in);
PdfSmartCopy.ByteStore streamKey = null;
bool validStream = false;
if (srcObj.IsStream()) {
streamKey = new PdfSmartCopy.ByteStore((PRStream) srcObj, serialized);
validStream = true;
PdfIndirectReference streamRef;
if (streamMap.TryGetValue(streamKey, out streamRef)) {
return streamRef;
}
} else if (srcObj.IsDictionary()) {
streamKey = new PdfSmartCopy.ByteStore((PdfDictionary) srcObj, serialized);
validStream = true;
PdfIndirectReference streamRef;
if (streamMap.TryGetValue(streamKey, out streamRef)) {
return streamRef;
}
}
PdfIndirectReference theRef;
RefKey key = new RefKey(@in);
IndirectReferences iRef;
if (indirects.TryGetValue(key, out iRef)) {
theRef = iRef.Ref;
if (iRef.Copied) {
return theRef;
}
} else {
theRef = body.PdfIndirectReference;
iRef = new IndirectReferences(theRef);
indirects[key] = iRef;
}
if (srcObj.IsDictionary()) {
PdfObject type = PdfReader.GetPdfObjectRelease(((PdfDictionary) srcObj).Get(PdfName.TYPE));
if (type != null && PdfName.PAGE.Equals(type)) {
return theRef;
}
}
iRef.SetCopied();
if (validStream) {
streamMap[streamKey] = theRef;
}
PdfObject obj = CopyObject(srcObj);
AddToBody(obj, theRef);
return theRef;
}
示例2: CopyIndirect
/**
* Translate a PRIndirectReference to a PdfIndirectReference
* In addition, translates the object numbers, and copies the
* referenced object to the output file if it wasn't available
* in the cache yet. If it's in the cache, the reference to
* the already used stream is returned.
*
* NB: PRIndirectReferences (and PRIndirectObjects) really need to know what
* file they came from, because each file has its own namespace. The translation
* we do from their namespace to ours is *at best* heuristic, and guaranteed to
* fail under some circumstances.
*/
protected override PdfIndirectReference CopyIndirect(PRIndirectReference inp)
{
PdfObject srcObj = PdfReader.GetPdfObjectRelease(inp);
ByteStore streamKey = null;
if (srcObj.Type == PdfObject.STREAM) {
byte[] streamContent = PdfReader.GetStreamBytesRaw((PRStream) srcObj);
// Only the content is compared, probably the keys should also be compared
streamKey = new ByteStore(streamContent);
PdfIndirectReference streamRef = (PdfIndirectReference) streamMap[streamKey];
if (streamRef != null) {
return streamRef;
}
}
PdfIndirectReference theRef;
RefKey key = new RefKey(inp);
IndirectReferences iRef = (IndirectReferences) indirects[key];
if (iRef != null) {
theRef = iRef.Ref;
if (iRef.Copied) {
return theRef;
}
} else {
theRef = body.PdfIndirectReference;
iRef = new IndirectReferences(theRef);
indirects[key] = iRef;
}
iRef.SetCopied();
if (srcObj.Type == PdfObject.STREAM) {
streamMap[streamKey] = theRef;
}
PdfObject obj = CopyObject(srcObj);
AddToBody(obj, theRef);
return theRef;
}
示例3: CopyIndirect
/**
* Translate a PRIndirectReference to a PdfIndirectReference
* In addition, translates the object numbers, and copies the
* referenced object to the output file.
* NB: PRIndirectReferences (and PRIndirectObjects) really need to know what
* file they came from, because each file has its own namespace. The translation
* we do from their namespace to ours is *at best* heuristic, and guaranteed to
* fail under some circumstances.
*/
protected virtual PdfIndirectReference CopyIndirect(PRIndirectReference inp)
{
PdfIndirectReference theRef;
RefKey key = new RefKey(inp);
IndirectReferences iRef;
indirects.TryGetValue(key, out iRef);
if (iRef != null) {
theRef = iRef.Ref;
if (iRef.Copied) {
return theRef;
}
}
else {
theRef = body.PdfIndirectReference;
iRef = new IndirectReferences(theRef);
indirects[key] = iRef;
}
PdfObject obj = PdfReader.GetPdfObjectRelease(inp);
if (obj != null && obj.IsDictionary()) {
PdfObject type = PdfReader.GetPdfObjectRelease(((PdfDictionary)obj).Get(PdfName.TYPE));
if (type != null && PdfName.PAGE.Equals(type)) {
return theRef;
}
}
iRef.SetCopied();
obj = CopyObject(obj);
AddToBody(obj, theRef);
return theRef;
}
示例4: AddPage
/**
* Add an imported page to our output
* @param iPage an imported page
* @throws IOException, BadPdfFormatException
*/
public void AddPage(PdfImportedPage iPage)
{
int pageNum = SetFromIPage(iPage);
PdfDictionary thePage = reader.GetPageN(pageNum);
PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);
reader.ReleasePage(pageNum);
RefKey key = new RefKey(origRef);
PdfIndirectReference pageRef;
IndirectReferences iRef;
indirects.TryGetValue(key, out iRef);
if (iRef != null && !iRef.Copied) {
pageReferences.Add(iRef.Ref);
iRef.SetCopied();
}
pageRef = CurrentPage;
if (iRef == null) {
iRef = new IndirectReferences(pageRef);
indirects[key] = iRef;
}
iRef.SetCopied();
PdfDictionary newPage = CopyDictionary(thePage);
root.AddPage(newPage);
iPage.SetCopied();
++currentPageNumber;
}
示例5: FindActivesFromReference
private void FindActivesFromReference(PdfIndirectReference iref, List<PdfIndirectReference> actives, HashSet2<RefKey> activeKeys) {
RefKey key = new RefKey(iref);
PdfIndirectObject iobj;
if (indirectObjects.TryGetValue(key, out iobj)
&& iobj.objecti.IsDictionary() && ContainsInactivePg((PdfDictionary) iobj.objecti, activeKeys))
return;
if(!activeKeys.Contains(key)) {
activeKeys.Add(key);
actives.Add(iref);
}
}
示例6: FindActives
private void FindActives(List<PdfIndirectReference> actives, HashSet2<RefKey> activeKeys, HashSet2<PdfName> activeClassMaps){
//collect all active objects from current active set (include kids, classmap, attributes)
for (int i = 0; i < actives.Count; ++i) {
RefKey key = new RefKey(actives[i]);
PdfIndirectObject iobj;
if (!indirectObjects.TryGetValue(key, out iobj) || iobj.objecti == null)
continue;
switch (iobj.objecti.Type){
case 0://PdfIndirectReference
FindActivesFromReference((PdfIndirectReference)iobj.objecti, actives, activeKeys);
break;
case PdfObject.ARRAY:
FindActivesFromArray((PdfArray)iobj.objecti, actives, activeKeys, activeClassMaps);
break;
case PdfObject.DICTIONARY:
case PdfObject.STREAM:
FindActivesFromDict((PdfDictionary)iobj.objecti, actives, activeKeys, activeClassMaps);
break;
}
}
}
示例7: FindActiveParents
//return new found objects
private List<PdfIndirectReference> FindActiveParents(HashSet2<RefKey> activeKeys){
List<PdfIndirectReference> newRefs = new List<PdfIndirectReference>();
List<RefKey> tmpActiveKeys = new List<RefKey>(activeKeys);
for (int i = 0; i < tmpActiveKeys.Count; ++i) {
PdfIndirectObject iobj;
if (!indirectObjects.TryGetValue(tmpActiveKeys[i], out iobj)
|| !iobj.objecti.IsDictionary())
continue;
PdfObject parent = ((PdfDictionary)iobj.objecti).Get(PdfName.P);
if (parent != null && parent.Type == 0) {
RefKey key = new RefKey((PdfIndirectReference)parent);
if (!activeKeys.Contains(key)) {
activeKeys.Add(key);
tmpActiveKeys.Add(key);
newRefs.Add((PdfIndirectReference) parent);
}
}
}
return newRefs;
}
示例8: CopyIndirect
/**
* Translate a PRIndirectReference to a PdfIndirectReference
* In addition, translates the object numbers, and copies the
* referenced object to the output file.
* NB: PRIndirectReferences (and PRIndirectObjects) really need to know what
* file they came from, because each file has its own namespace. The translation
* we do from their namespace to ours is *at best* heuristic, and guaranteed to
* fail under some circumstances.
*/
protected virtual PdfIndirectReference CopyIndirect(PRIndirectReference inp)
{
PdfIndirectReference theRef;
RefKey key = new RefKey(inp);
IndirectReferences iRef = (IndirectReferences)indirects[key] ;
if (iRef != null) {
theRef = iRef.Ref;
if (iRef.Copied) {
return theRef;
}
}
else {
theRef = body.PdfIndirectReference;
iRef = new IndirectReferences(theRef);
indirects[key] = iRef;
}
iRef.SetCopied();
PdfObject obj = CopyObject(PdfReader.GetPdfObjectRelease(inp));
AddToBody(obj, theRef);
return theRef;
}
示例9: AddPage
/**
* Add an imported page to our output
* @param iPage an imported page
* @throws IOException, BadPdfFormatException
*/
public void AddPage(PdfImportedPage iPage)
{
int pageNum = SetFromIPage(iPage);
PdfDictionary thePage = reader.GetPageN(pageNum);
PRIndirectReference origRef = reader.GetPageOrigRef(pageNum);
reader.ReleasePage(pageNum);
RefKey key = new RefKey(origRef);
PdfIndirectReference pageRef;
IndirectReferences iRef = (IndirectReferences)indirects[key] ;
iRef = null; // temporary hack to have multiple pages, may break is some cases
// if we already have an iref for the page (we got here by another link)
if (iRef != null) {
pageRef = iRef.Ref;
}
else {
pageRef = body.PdfIndirectReference;
iRef = new IndirectReferences(pageRef);
indirects[key] = iRef;
}
pageReferences.Add(pageRef);
++currentPageNumber;
if (! iRef.Copied) {
iRef.SetCopied();
PdfDictionary newPage = CopyDictionary(thePage);
newPage.Put(PdfName.PARENT, topPageParent);
AddToBody(newPage, pageRef);
}
root.AddPage(pageRef);
pageNumbersToRefs.Add(pageRef);
}
示例10: CacheObject
protected internal override void CacheObject(PdfIndirectObject iobj) {
if ((tagged || mergeFields) && indirectObjects != null) {
savedObjects.Add(iobj);
RefKey key = new RefKey(iobj.Number, iobj.Generation);
if (!indirectObjects.ContainsKey(key))
indirectObjects[key] = iobj;
}
}
示例11: FixTaggedStructure
virtual protected void FixTaggedStructure()
{
Dictionary<int, PdfIndirectReference> numTree = structureTreeRoot.NumTree;
HashSet2<RefKey> activeKeys = new HashSet2<RefKey>();
List<PdfIndirectReference> actives = new List<PdfIndirectReference>();
int pageRefIndex = 0;
if (mergeFields && acroForm != null) {
actives.Add(acroForm);
activeKeys.Add(new RefKey(acroForm));
}
foreach (PdfIndirectReference page in pageReferences) {
actives.Add(page);
activeKeys.Add(new RefKey(page));
}
//from end, because some objects can appear on several pages because of MCR (out16.pdf)
for (int i = numTree.Count - 1; i >= 0; --i) {
PdfIndirectReference currNum = numTree[i];
RefKey numKey = new RefKey(currNum);
PdfObject obj = indirectObjects[numKey].objecti;
if (obj.IsDictionary()) {
bool addActiveKeys = false;
if (pageReferences.Contains((PdfIndirectReference) ((PdfDictionary) obj).Get(PdfName.PG))) {
addActiveKeys = true;
}
else {
PdfDictionary k = PdfStructTreeController.GetKDict((PdfDictionary) obj);
if (k != null && pageReferences.Contains((PdfIndirectReference) k.Get(PdfName.PG))) {
addActiveKeys = true;
}
}
if (addActiveKeys) {
activeKeys.Add(numKey);
actives.Add(currNum);
}
else {
numTree.Remove(i);
}
}
else if (obj.IsArray()) {
activeKeys.Add(numKey);
actives.Add(currNum);
PdfArray currNums = (PdfArray) obj;
PdfIndirectReference currPage = pageReferences[pageRefIndex++];
actives.Add(currPage);
activeKeys.Add(new RefKey(currPage));
PdfIndirectReference prevKid = null;
for (int j = 0; j < currNums.Size; j++) {
PdfIndirectReference currKid = (PdfIndirectReference) currNums.GetDirectObject(j);
if (currKid.Equals(prevKid))
continue;
RefKey kidKey = new RefKey(currKid);
activeKeys.Add(kidKey);
actives.Add(currKid);
PdfIndirectObject iobj = indirectObjects[kidKey];
if (iobj.objecti.IsDictionary()) {
PdfDictionary dict = (PdfDictionary) iobj.objecti;
PdfIndirectReference pg = (PdfIndirectReference) dict.Get(PdfName.PG);
//if pg is real page - do nothing, else set correct pg and remove first MCID if exists
if (pg != null && !pageReferences.Contains(pg) && !pg.Equals(currPage)) {
dict.Put(PdfName.PG, currPage);
PdfArray kids = dict.GetAsArray(PdfName.K);
if (kids != null) {
PdfObject firstKid = kids.GetDirectObject(0);
if (firstKid.IsNumber()) kids.Remove(0);
}
}
}
prevKid = currKid;
}
}
}
HashSet2<PdfName> activeClassMaps = new HashSet2<PdfName>();
//collect all active objects from current active set (include kids, classmap, attributes)
FindActives(actives, activeKeys, activeClassMaps);
//find parents of active objects
List<PdfIndirectReference> newRefs = FindActiveParents(activeKeys);
//find new objects with incorrect Pg; if find, set Pg from first correct kid. This correct kid must be.
FixPgKey(newRefs, activeKeys);
//remove unused kids of StructTreeRoot and remove unused objects from class map
FixStructureTreeRoot(activeKeys, activeClassMaps);
List<RefKey> inactiveKeys = new List<RefKey>();
foreach(KeyValuePair<RefKey, PdfIndirectObject> entry in indirectObjects) {
if (!activeKeys.Contains(entry.Key)) {
inactiveKeys.Add(entry.Key);
}
else {
if (entry.Value.objecti.IsArray()) {
RemoveInactiveReferences((PdfArray)entry.Value.objecti, activeKeys);
} else if (entry.Value.objecti.IsDictionary()) {
PdfObject kids = ((PdfDictionary)entry.Value.objecti).Get(PdfName.K);
if (kids != null && kids.IsArray())
RemoveInactiveReferences((PdfArray)kids, activeKeys);
}
}
}
//.........这里部分代码省略.........
示例12: CopyAcroForm
/**
* Copy the acroform for an input document. Note that you can only have one,
* we make no effort to merge them.
* @param reader The reader of the input file that is being copied
* @throws IOException, BadPdfFormatException
*/
public void CopyAcroForm(PdfReader reader)
{
SetFromReader(reader);
PdfDictionary catalog = reader.Catalog;
PRIndirectReference hisRef = null;
PdfObject o = catalog.Get(PdfName.ACROFORM);
if (o != null && o.Type == PdfObject.INDIRECT)
hisRef = (PRIndirectReference)o;
if (hisRef == null) return; // bugfix by John Engla
RefKey key = new RefKey(hisRef);
PdfIndirectReference myRef;
IndirectReferences iRef;
indirects.TryGetValue(key, out iRef);
if (iRef != null) {
acroForm = myRef = iRef.Ref;
}
else {
acroForm = myRef = body.PdfIndirectReference;
iRef = new IndirectReferences(myRef);
indirects[key] = iRef;
}
if (! iRef.Copied) {
iRef.SetCopied();
PdfDictionary theForm = CopyDictionary((PdfDictionary)PdfReader.GetPdfObject(hisRef));
AddToBody(theForm, myRef);
}
}
示例13: CopyIndirect
/**
* Translate a PRIndirectReference to a PdfIndirectReference
* In addition, translates the object numbers, and copies the
* referenced object to the output file if it wasn't available
* in the cache yet. If it's in the cache, the reference to
* the already used stream is returned.
*
* NB: PRIndirectReferences (and PRIndirectObjects) really need to know what
* file they came from, because each file has its own namespace. The translation
* we do from their namespace to ours is *at best* heuristic, and guaranteed to
* fail under some circumstances.
*/
protected override PdfIndirectReference CopyIndirect(PRIndirectReference inp)
{
PdfObject srcObj = PdfReader.GetPdfObjectRelease(inp);
ByteStore streamKey = null;
bool validStream = false;
if (srcObj.IsStream()) {
streamKey = new ByteStore((PRStream)srcObj);
validStream = true;
PdfIndirectReference streamRef = (PdfIndirectReference) streamMap[streamKey];
if (streamRef != null) {
return streamRef;
}
}
PdfIndirectReference theRef;
RefKey key = new RefKey(inp);
IndirectReferences iRef = (IndirectReferences) indirects[key];
if (iRef != null) {
theRef = iRef.Ref;
if (iRef.Copied) {
return theRef;
}
} else {
theRef = body.PdfIndirectReference;
iRef = new IndirectReferences(theRef);
indirects[key] = iRef;
}
if (srcObj != null && srcObj.IsDictionary()) {
PdfObject type = PdfReader.GetPdfObjectRelease(((PdfDictionary)srcObj).Get(PdfName.TYPE));
if (type != null && PdfName.PAGE.Equals(type)) {
return theRef;
}
}
iRef.SetCopied();
if (validStream) {
streamMap[streamKey] = theRef;
}
PdfObject obj = CopyObject(srcObj);
AddToBody(obj, theRef);
return theRef;
}
示例14: SerObject
private void SerObject(PdfObject obj, int level, ByteBuffer bb, Dictionary<RefKey, int> serialized)
{
if (level <= 0)
return;
if (obj == null) {
bb.Append("$Lnull");
return;
}
PdfIndirectReference refe = null;
ByteBuffer savedBb = null;
if (obj.IsIndirect()) {
refe = (PdfIndirectReference)obj;
RefKey key = new RefKey(refe);
if (serialized.ContainsKey(key)) {
bb.Append(serialized[key]);
return;
}
else {
savedBb = bb;
bb = new ByteBuffer();
}
}
obj = PdfReader.GetPdfObject(obj);
if (obj.IsStream()) {
bb.Append("$B");
SerDic((PdfDictionary)obj, level - 1, bb, serialized);
if (level > 0) {
bb.Append(DigestAlgorithms.Digest("MD5", PdfReader.GetStreamBytesRaw((PRStream)obj)));
}
}
else if (obj.IsDictionary()) {
SerDic((PdfDictionary)obj, level - 1, bb,serialized);
}
else if (obj.IsArray()) {
SerArray((PdfArray)obj, level - 1, bb,serialized);
}
else if (obj.IsString()) {
bb.Append("$S").Append(obj.ToString());
}
else if (obj.IsName()) {
bb.Append("$N").Append(obj.ToString());
}
else
bb.Append("$L").Append(obj.ToString());
if (savedBb != null) {
RefKey key = new RefKey(refe);
if (!serialized.ContainsKey(key))
serialized[key] = CalculateHash(bb.Buffer);
savedBb.Append(bb);
}
}
示例15: CopyIndirect
/**
* Translate a PRIndirectReference to a PdfIndirectReference
* In addition, translates the object numbers, and copies the
* referenced object to the output file if it wasn't available
* in the cache yet. If it's in the cache, the reference to
* the already used stream is returned.
*
* NB: PRIndirectReferences (and PRIndirectObjects) really need to know what
* file they came from, because each file has its own namespace. The translation
* we do from their namespace to ours is *at best* heuristic, and guaranteed to
* fail under some circumstances.
*/
protected override PdfIndirectReference CopyIndirect(PRIndirectReference inp) {
PdfObject srcObj = PdfReader.GetPdfObjectRelease(inp);
ByteStore streamKey = null;
bool validStream = false;
if (srcObj.IsStream()) {
streamKey = new ByteStore((PRStream)srcObj, serialized);
validStream = true;
PdfIndirectReference streamRef;
if (streamMap.TryGetValue(streamKey, out streamRef)) {
return streamRef;
}
} else if (srcObj.IsDictionary()) {
streamKey = new ByteStore((PdfDictionary)srcObj, serialized);
validStream = true;
PdfIndirectReference streamRef;
if (streamMap.TryGetValue(streamKey, out streamRef)) {
return streamRef;
}
}
PdfIndirectReference theRef;
RefKey key = new RefKey(inp);
IndirectReferences iRef;
indirects.TryGetValue(key, out iRef);
if (iRef != null) {
theRef = iRef.Ref;
if (iRef.Copied) {
return theRef;
}
} else {
theRef = body.PdfIndirectReference;
iRef = new IndirectReferences(theRef);
indirects[key] = iRef;
}
if (srcObj.IsDictionary()) {
PdfObject type = PdfReader.GetPdfObjectRelease(((PdfDictionary)srcObj).Get(PdfName.TYPE));
if (type != null) {
if ((PdfName.PAGE.Equals(type))) {
return theRef;
}
if ((PdfName.CATALOG.Equals(type))) {
LOGGER.Warn(MessageLocalization.GetComposedMessage("make.copy.of.catalog.dictionary.is.forbidden"));
return null;
}
}
}
iRef.SetCopied();
if (validStream) {
streamMap[streamKey] = theRef;
}
PdfObject obj = CopyObject(srcObj);
AddToBody(obj, theRef);
return theRef;
}