示例#1
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void ParseTag(PdfMcr kid)
        {
            int           mcid       = kid.GetMcid();
            PdfDictionary pageDic    = kid.GetPageObject();
            String        tagContent = "";

            if (mcid != -1)
            {
                if (!parsedTags.ContainsKey(pageDic))
                {
                    TaggedPdfReaderTool.MarkedContentEventListener listener = new TaggedPdfReaderTool.MarkedContentEventListener
                                                                                  (this);
                    PdfCanvasProcessor processor = new PdfCanvasProcessor(listener);
                    PdfPage            page      = document.GetPage(pageDic);
                    processor.ProcessContent(page.GetContentBytes(), page.GetResources());
                    parsedTags[pageDic] = listener.GetMcidContent();
                }
                if (parsedTags.Get(pageDic).ContainsKey(mcid))
                {
                    tagContent = parsedTags.Get(pageDic).Get(mcid);
                }
            }
            else
            {
                PdfObjRef objRef  = (PdfObjRef)kid;
                PdfObject @object = objRef.GetReferencedObject();
                if (@object.IsDictionary())
                {
                    PdfName subtype = ((PdfDictionary)@object).GetAsName(PdfName.Subtype);
                    tagContent = subtype.ToString();
                }
            }
            @out.Write(EscapeXML(tagContent, true));
        }
示例#2
0
        private PdfMcr PrepareMcrForMovingToNewParent(PdfMcr mcrKid, PdfStructElem newParent)
        {
            PdfObject     mcrObject = mcrKid.GetPdfObject();
            PdfDictionary mcrPage   = mcrKid.GetPageObject();
            PdfDictionary mcrDict   = null;

            if (!mcrObject.IsNumber())
            {
                mcrDict = (PdfDictionary)mcrObject;
            }
            if (mcrDict == null || !mcrDict.ContainsKey(PdfName.Pg))
            {
                if (!EnsureElementPageEqualsKidPage(newParent, mcrPage))
                {
                    if (mcrDict == null)
                    {
                        mcrDict = new PdfDictionary();
                        mcrDict.Put(PdfName.Type, PdfName.MCR);
                        mcrDict.Put(PdfName.MCID, mcrKid.GetPdfObject());
                    }
                    // Explicitly using object indirect reference here in order to correctly process released objects.
                    mcrDict.Put(PdfName.Pg, mcrPage.GetIndirectReference());
                }
            }
            if (mcrDict != null)
            {
                if (PdfName.MCR.Equals(mcrDict.Get(PdfName.Type)))
                {
                    mcrKid = new PdfMcrDictionary(mcrDict, newParent);
                }
                else
                {
                    if (PdfName.OBJR.Equals(mcrDict.Get(PdfName.Type)))
                    {
                        mcrKid = new PdfObjRef(mcrDict, newParent);
                    }
                }
            }
            else
            {
                mcrKid = new PdfMcrNumber((PdfNumber)mcrObject, newParent);
            }
            return(mcrKid);
        }
示例#3
0
        private PdfMcr PrepareMcrForMovingToNewParent(PdfMcr mcrKid, PdfStructElem newParent)
        {
            PdfObject     mcrObject = mcrKid.GetPdfObject();
            PdfDictionary mcrPage   = mcrKid.GetPageObject();
            PdfDictionary mcrDict   = null;

            if (!mcrObject.IsNumber())
            {
                mcrDict = (PdfDictionary)mcrObject;
            }
            if (mcrDict == null || !mcrDict.ContainsKey(PdfName.Pg))
            {
                if (!EnsureElementPageEqualsKidPage(newParent, mcrPage))
                {
                    if (mcrDict == null)
                    {
                        mcrDict = new PdfDictionary();
                        mcrDict.Put(PdfName.Type, PdfName.MCR);
                        mcrDict.Put(PdfName.MCID, mcrKid.GetPdfObject());
                    }
                    mcrDict.Put(PdfName.Pg, mcrPage);
                }
            }
            if (mcrDict != null)
            {
                if (PdfName.MCR.Equals(mcrDict.Get(PdfName.Type)))
                {
                    mcrKid = new PdfMcrDictionary(mcrDict, newParent);
                }
                else
                {
                    if (PdfName.OBJR.Equals(mcrDict.Get(PdfName.Type)))
                    {
                        mcrKid = new PdfObjRef(mcrDict, newParent);
                    }
                }
            }
            else
            {
                mcrKid = new PdfMcrNumber((PdfNumber)mcrObject, newParent);
            }
            return(mcrKid);
        }