Home > Blockchain >  How can tell the difference between the link and the footnote using C# ITextSharp?
How can tell the difference between the link and the footnote using C# ITextSharp?

Time:09-17

I have a simple PDF file that has the Link and the Footnote on a page. When I run the annotation check using iTextSharp, both of the links return the sub type as Link. Is there a way to tell the difference between those two items?

I did examine through an intellisence the structure of an annotation dictionary and notice the annotation object dictionary for the Footnote has once extra item, which is named "F", and that item has a value of 4. That item is NOT present at all in the annotation dictionary for the Link. Can I use the 'F' item/parameter as a way to tell the difference between the Link and the Footnote?

Please let me know if there are additional questions

Thank you very much in advance

Here is the PDF file

Here is our code

    public string AnyPDFCheckComments(string inFileName, string strUsername, string strFilename)
    {
            string strCommentType = string.Empty;
            string strWidgetFound = string.Empty;
            string strPageNumber = string.Empty;
            string message = string.Empty;
            string strComments = string.Empty;
            string strCommentsFound = string.Empty;
            int intCommentCount = 0;

            PdfReader reader = new PdfReader(inFileName);

            for (int i = 1; i <= reader.NumberOfPages;   i)
            {
                strPageNumber = i.ToString();

                PdfDictionary pagedic = reader.GetPageN(i);

                PdfArray annotarray = (PdfArray)PdfReader.GetPdfObject(pagedic.Get(PdfName.ANNOTS));

                if (annotarray == null || annotarray.Size == 0)
                {
                    continue;
                }

                // Finding out the links
                foreach (object annot in annotarray.ArrayList)
                {
                    PdfDictionary annotationDic = null;
                    if (annot is PdfIndirectReference)
                    {
                        annotationDic = (PdfDictionary)PdfReader.GetPdfObject((PdfIndirectReference)annot);
                    }
                    else
                    {
                        annotationDic = (PdfDictionary) annot;
                    }

                    PdfName subType = (PdfName)annotationDic.Get(PdfName.SUBTYPE);
                    if ((subType.Equals(PdfName.TEXT)) && (strCommentsVariables.IndexOf("text") != -1))
                    {
                        strCommentType = "text";
                        //break;
                    }
                    else if ((subType.Equals(PdfName.LINK)) && (strCommentsVariables.IndexOf("Link") != -1))
                    {
                        strCommentType = "Link";
                        //break;
                    }

                    if ((strCommentType != ""))
                    {
                        strCommentsFound = "Yes";
                        intCommentCount =   intCommentCount;
                        strComments = strComments   "<BR>"   "A comment type of '"   "<b>"   strCommentType   "</b>"   "' has been found on page no: "   "<b>"   strPageNumber   "</b>";
                        if (intCommentCount == 5)
                        {
                            break;
                        }
                        else
                        {
                            strCommentType = string.Empty;
                        }
                    }
                }
            }

            return strComments;
    }

CodePudding user response:

This code worked for us

var footnoteIdentifier = annotationDic.Get(PdfName.F);
if (footnoteIdentifier != null)
{
    continue;
}
  • Related