private void RemovePageTagFromParent(IStructureNode pageTag, IStructureNode parent) { if (parent is PdfStructElem) { PdfStructElem structParent = (PdfStructElem)parent; if (!structParent.IsFlushed()) { structParent.RemoveKid(pageTag); PdfDictionary parentStructDict = structParent.GetPdfObject(); if (waitingTagsManager.GetObjForStructDict(parentStructDict) == null && parent.GetKids().Count == 0 && !(structParent .GetParent() is PdfStructTreeRoot)) { RemovePageTagFromParent(structParent, parent.GetParent()); PdfIndirectReference indRef = parentStructDict.GetIndirectReference(); if (indRef != null) { // TODO how about possible references to structure element from refs or structure destination for instance? indRef.SetFree(); } } } else { if (pageTag is PdfMcr) { throw new PdfException(PdfException.CannotRemoveTagBecauseItsParentIsFlushed); } } } }
/// <summary>Removes annotation content item from the tag structure.</summary> /// <remarks> /// Removes annotation content item from the tag structure. /// If annotation is not added to the document or is not tagged, nothing will happen. /// </remarks> /// <param name="annotation"> /// the /// <see cref="iText.Kernel.Pdf.Annot.PdfAnnotation"/> /// that will be removed from the tag structure /// </param> /// <returns> /// /// <see cref="TagTreePointer"/> /// instance which points at annotation tag parent if annotation was removed, /// otherwise returns null /// </returns> public virtual TagTreePointer RemoveAnnotationTag(PdfAnnotation annotation) { PdfStructElem structElem = null; PdfDictionary annotDic = annotation.GetPdfObject(); PdfNumber structParentIndex = (PdfNumber)annotDic.Get(PdfName.StructParent); if (structParentIndex != null) { PdfObjRef objRef = document.GetStructTreeRoot().FindObjRefByStructParentIndex(annotDic.GetAsDictionary(PdfName .P), structParentIndex.IntValue()); if (objRef != null) { PdfStructElem parent = (PdfStructElem)objRef.GetParent(); parent.RemoveKid(objRef); structElem = parent; } } annotDic.Remove(PdfName.StructParent); annotDic.SetModified(); if (structElem != null) { return(new TagTreePointer(document).SetCurrentStructElem(structElem)); } return(null); }
private void RemovePageTagFromParent(IPdfStructElem pageTag, IPdfStructElem parent) { if (parent is PdfStructElem) { PdfStructElem structParent = (PdfStructElem)parent; if (!structParent.IsFlushed()) { structParent.RemoveKid(pageTag); PdfDictionary parentObject = structParent.GetPdfObject(); if (!connectedStructToModel.ContainsKey(parentObject) && parent.GetKids().Count == 0 && parentObject != rootTagElement .GetPdfObject()) { RemovePageTagFromParent(structParent, parent.GetParent()); parentObject.GetIndirectReference().SetFree(); } } else { if (pageTag is PdfMcr) { throw new PdfException(PdfException.CannotRemoveTagBecauseItsParentIsFlushed); } } } }
/// <summary>Removes the current tag.</summary> /// <remarks> /// Removes the current tag. If it has kids, they will become kids of the current tag parent. /// This method call moves this /// <c>TagTreePointer</c> /// to the current tag parent. /// <br/><br/> /// You cannot remove root tag, and also you cannot remove any tag if document's tag structure was partially flushed; /// in this two cases an exception will be thrown. /// </remarks> /// <returns> /// this /// <see cref="TagStructureContext"/> /// instance. /// </returns> public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer RemoveTag() { IPdfStructElem parentElem = GetCurrentStructElem().GetParent(); if (parentElem is PdfStructTreeRoot) { throw new PdfException(PdfException.CannotRemoveDocumentRootTag); } IList <IPdfStructElem> kids = GetCurrentStructElem().GetKids(); PdfStructElem parent = (PdfStructElem)parentElem; if (parent.IsFlushed()) { throw new PdfException(PdfException.CannotRemoveTagBecauseItsParentIsFlushed); } int removedKidIndex = parent.RemoveKid(GetCurrentStructElem()); GetCurrentStructElem().GetPdfObject().GetIndirectReference().SetFree(); foreach (IPdfStructElem kid in kids) { if (kid is PdfStructElem) { parent.AddKid(removedKidIndex++, (PdfStructElem)kid); } else { PdfMcr mcr = PrepareMcrForMovingToNewParent((PdfMcr)kid, parent); parent.AddKid(removedKidIndex++, mcr); } } SetCurrentStructElem(parent); return(this); }
/// <summary>Removes content item from the tag structure.</summary> /// <remarks> /// Removes content item from the tag structure. /// <br /> /// Nothing happens if there is no such mcid on given page. /// </remarks> /// <param name="page">page, which contains this content item</param> /// <param name="mcid">marked content id of this content item</param> /// <returns> /// /// <c>TagTreePointer</c> /// which points at the parent of the removed content item, or null if there is no /// such mcid on given page. /// </returns> public virtual TagTreePointer RemoveContentItem(PdfPage page, int mcid) { PdfMcr mcr = document.GetStructTreeRoot().FindMcrByMcid(page.GetPdfObject(), mcid); if (mcr == null) { return(null); } PdfStructElem parent = (PdfStructElem)mcr.GetParent(); parent.RemoveKid(mcr); return(new TagTreePointer(document).SetCurrentStructElem(parent)); }
/// <summary>Removes the current tag.</summary> /// <remarks> /// Removes the current tag. If it has kids, they will become kids of the current tag parent. /// This method call moves this /// <c>TagTreePointer</c> /// to the current tag parent. /// <br /><br /> /// You cannot remove root tag, and also you cannot remove the tag if it's parent is already flushed; /// in this two cases an exception will be thrown. /// </remarks> /// <returns> /// this /// <see cref="TagStructureContext"/> /// instance. /// </returns> public virtual iText.Kernel.Pdf.Tagutils.TagTreePointer RemoveTag() { PdfStructElem currentStructElem = GetCurrentStructElem(); IStructureNode parentElem = currentStructElem.GetParent(); if (parentElem is PdfStructTreeRoot) { throw new PdfException(PdfException.CannotRemoveDocumentRootTag); } IList <IStructureNode> kids = currentStructElem.GetKids(); PdfStructElem parent = (PdfStructElem)parentElem; if (parent.IsFlushed()) { throw new PdfException(PdfException.CannotRemoveTagBecauseItsParentIsFlushed); } // remove waiting tag state if tag is removed Object objForStructDict = tagStructureContext.GetWaitingTagsManager().GetObjForStructDict(currentStructElem .GetPdfObject()); tagStructureContext.GetWaitingTagsManager().RemoveWaitingState(objForStructDict); int removedKidIndex = parent.RemoveKid(currentStructElem); PdfIndirectReference indRef = currentStructElem.GetPdfObject().GetIndirectReference(); if (indRef != null) { // TODO how about possible references to structure element from refs or structure destination for instance? indRef.SetFree(); } foreach (IStructureNode kid in kids) { if (kid is PdfStructElem) { parent.AddKid(removedKidIndex++, (PdfStructElem)kid); } else { PdfMcr mcr = PrepareMcrForMovingToNewParent((PdfMcr)kid, parent); parent.AddKid(removedKidIndex++, mcr); } } currentStructElem.GetPdfObject().Clear(); SetCurrentStructElem(parent); return(this); }