/** * 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]; 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); ++currentPageNumber; }
/** * 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; } 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); }
public override bool Equals(object o) { if (!(o is RefKey)) { return(false); } RefKey other = (RefKey)o; return(this.gen == other.gen && this.num == other.num); }
/** * 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); }
public static AttachedFileMetadata GetMetaData(RefKey fileType, AttachedFileMetadata[] data) { foreach (var metadata in data) { if (metadata.AttachedFileType.UID == fileType.UID) { return(metadata); } } return(null); }
private List <RequisitionInfo> GetRequisitionInfos(dynamic docsInfo) { var requisitionInfos = new List <RequisitionInfo>(); foreach (var item in docsInfo) { var docStatus = new RefKey { Note = item.StatusName, UID = item.OnlineRequisitionStatusId }; requisitionInfos.Add(new RequisitionInfo { DocumentID = item.Barcode, DocumentDate = item.DocumentDate.Date, StatusDate = item.StatusDate.Date, DocumentStatus = docStatus }); } return(requisitionInfos); }
/** * 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 = (IndirectReferences)indirects[key]; 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); } }
private bool ObjectsIsEquals(PdfObject outObj, PdfObject cmpObj) { PdfObject outDirectObj = PdfReader.GetPdfObject(outObj); PdfObject cmpDirectObj = PdfReader.GetPdfObject(cmpObj); if (outDirectObj == null || cmpDirectObj.Type != outDirectObj.Type) { return(false); } if (cmpDirectObj.IsDictionary()) { PdfDictionary cmpDict = (PdfDictionary)cmpDirectObj; PdfDictionary outDict = (PdfDictionary)outDirectObj; if (cmpDict.IsPage()) { if (!outDict.IsPage()) { return(false); } RefKey cmpRefKey = new RefKey((PRIndirectReference)cmpObj); RefKey outRefKey = new RefKey((PRIndirectReference)outObj); if (cmpPagesRef.Contains(cmpRefKey) && cmpPagesRef.IndexOf(cmpRefKey) == outPagesRef.IndexOf(outRefKey)) { return(true); } return(false); } if (!ObjectsIsEquals(outDict, cmpDict)) { return(false); } } else if (cmpDirectObj.IsStream()) { if (!ObjectsIsEquals((PRStream)outDirectObj, (PRStream)cmpDirectObj)) { return(false); } } else if (cmpDirectObj.IsArray()) { if (!ObjectsIsEquals((PdfArray)outDirectObj, (PdfArray)cmpDirectObj)) { return(false); } } else if (cmpDirectObj.IsName()) { if (!ObjectsIsEquals((PdfName)outDirectObj, (PdfName)cmpDirectObj)) { return(false); } } else if (cmpDirectObj.IsNumber()) { if (!ObjectsIsEquals((PdfNumber)outDirectObj, (PdfNumber)cmpDirectObj)) { return(false); } } else if (cmpDirectObj.IsString()) { if (!ObjectsIsEquals((PdfString)outDirectObj, (PdfString)cmpDirectObj)) { return(false); } } else if (cmpDirectObj.IsBoolean()) { if (!ObjectsIsEquals((PdfBoolean)outDirectObj, (PdfBoolean)cmpDirectObj)) { return(false); } } else { throw new InvalidOperationException(); } return(true); }
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) { 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); }
/** * 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; } 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; }
/** * 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 = (IndirectReferences)indirects[key] ; 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); } }
/** * 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] ; 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); ++currentPageNumber; }
/** * 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; }
public void SetInstance(object source, Type targetType, object targetInstance) { RefKey key = new RefKey(source, targetType); _cache[key] = targetInstance; }
public object GetValue(object source, Type targetType) { RefKey key = new RefKey(source, targetType); return(_cache[key]); }