以PDF格式获取书签坐标

时间:2015-06-23 10:39:46

标签: c# itextsharp

我正致力于将签名图像放置在确切位置的PDF上。在PDF中,我添加了报告工具书签,以便我可以知道在哪里放置签名图像。问题是我不知道如何获得书签坐标。它可能是ITextsharp吗?

------>编辑 书签图片

enter image description here

- - - - >编辑

解决方案是:

        PdfReader pdfReader = new PdfReader(GlobalVars.PdfFile);
        IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfReader);
        string BookmarkID = "";
        for (int j = 0; j < bookmarks.Count; j++)
        {
            //MessageBox.Show(bookmarks[i].Values.ToArray().GetValue(0).ToString());
            string s = bookmarks[j].Values.ToArray().GetValue(0).ToString();
            if (bookmarks[j].Values.ToArray().GetValue(0).ToString() == "##PODPIS##")
            {
                BookmarkID = bookmarks[j].Values.ToArray().GetValue(1).ToString();
            }


        }

        var map = SimpleNamedDestination.GetNamedDestination(pdfReader, true);
        foreach (KeyValuePair<string, string> entry in map)
        {
            if (entry.Key.ToString() == BookmarkID)
            {
                string[] LocationArray = entry.Value.Split(null);
                GlobalVars.SignatuePageNumber = Convert.ToInt32(LocationArray[0]);
                GlobalVars.SignatureX = float.Parse(LocationArray[2], CultureInfo.InvariantCulture.NumberFormat);
                GlobalVars.SignatureY = float.Parse(LocationArray[3], CultureInfo.InvariantCulture.NumberFormat);
            }
        }

1 个答案:

答案 0 :(得分:0)

解决方案是:

        PdfReader pdfReader = new PdfReader(GlobalVars.PdfFile);
        IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfReader);
        string BookmarkID = "";
        for (int j = 0; j < bookmarks.Count; j++)
        {
            //MessageBox.Show(bookmarks[i].Values.ToArray().GetValue(0).ToString());
            string s = bookmarks[j].Values.ToArray().GetValue(0).ToString();
            if (bookmarks[j].Values.ToArray().GetValue(0).ToString() == "##PODPIS##")
            {
                BookmarkID = bookmarks[j].Values.ToArray().GetValue(1).ToString();
            }


        }

        var map = SimpleNamedDestination.GetNamedDestination(pdfReader, true);
        foreach (KeyValuePair<string, string> entry in map)
        {
            if (entry.Key.ToString() == BookmarkID)
            {
                string[] LocationArray = entry.Value.Split(null);
                GlobalVars.SignatuePageNumber = Convert.ToInt32(LocationArray[0]);
                GlobalVars.SignatureX = float.Parse(LocationArray[2], CultureInfo.InvariantCulture.NumberFormat);
                GlobalVars.SignatureY = float.Parse(LocationArray[3], CultureInfo.InvariantCulture.NumberFormat);
            }
        }