【问题标题】:Open PDF exist Bookmark instead of Destination - C#打开 PDF 存在书签而不是目标 - C#
【发布时间】:2014-06-22 13:23:01
【问题描述】:

这是否可以在 C# 上以编程方式在特定文件上打开带有书签的 PDF 文件(如果有办法,我可以使用 ItextSharp)?

我关注了this 问题,它适用于目的地而不是书签。

对我有用的另一种选择是使用 Word 2007 配置目标,因此在使用 Acrobat 阅读器转换为 PDF 后,目标及其名称将保存。

感谢您的帮助!

编辑 1

这是我的代码:(单击按钮 1 将所有书签写入组合框)

private void button1_Click(object sender, EventArgs e)
    {
        reader = new PdfReader("C:\\Users\\itay\\Desktop\\V-Sperm Gold 3.49 User Guide_04_APR_11.pdf");
        book_mark = SimpleBookmark.GetBookmark(reader);
        foreach (Dictionary<string, object> bk in book_mark)
        {
            foreach (KeyValuePair<string, object> kvr in bk)
            {
                if (kvr.Key == "Kids" || kvr.Key == "kids")
                {
                    IList<Dictionary<string, object>> child =
                            (IList<Dictionary<string, object>>)kvr.Value;

                    recursive_search(child, tn);

                }

                else if (kvr.Key == "Title" || kvr.Key == "title")
                {
                    tn = new System.Windows.Forms.TreeNode(kvr.Value.ToString());
                    //comboBox1.Items.Add(tn.Text);
                }
                else if (kvr.Key == "Page" || kvr.Key == "page")
                {
                    //saves page number
                    tn.ToolTipText = Regex.Match(kvr.Value.ToString(), "[0-9]+").Value;
                }
            }
        }

    }

    public void recursive_search(IList<Dictionary<string, object>> ilist, TreeNode tnt)
    {
        foreach (Dictionary<string, object> bk in ilist)
        {
            foreach (KeyValuePair<string, object> kvr in bk)
            {
                if (kvr.Key == "Kids" || kvr.Key == "kids")
                {
                    IList<Dictionary<string, object>> child =
                                (IList<Dictionary<string, object>>)kvr.Value;
                    recursive_search(child, tn);

                }
                else if (kvr.Key == "Title" || kvr.Key == "title")
                {
                    tn = new System.Windows.Forms.TreeNode(kvr.Value.ToString());
                    comboBox1.Items.Add(tn.Text);
                }
                else if (kvr.Key == "Page" || kvr.Key == "page")
                {
                    tn.ToolTipText = Regex.Match(kvr.Value.ToString(), "[0-9]+").Value;
                    tnt.Nodes.Add(tn);

                }
            }
        }
    }

点击按钮 2 打开 PDF:

    private void button2_Click(object sender, EventArgs e)
    {
        Process myProcess = new Process();
        myProcess.StartInfo.FileName = "AcroRd32.exe";
        myProcess.StartInfo.Arguments = "pagemode=bookmarks&nameddest=" + comboBox1.Text + "\" \"" + "C:\\Users\\itay\\Desktop\\V-Sperm Gold 3.49 User Guide_04_APR_11.pdf" + "\"";
        myProcess.Start();
    }

【问题讨论】:

    标签: c# pdf itextsharp word-2007


    【解决方案1】:

    您似乎正在寻找一个特定的开放参数,但您找不到它,因为您正在寻找不存在的东西。

    请查阅 Adob​​e 网站上的官方文档:http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf

    无法定义可触发的书签。您会找到诸如nameddest(您已经知道)和page 之类的开放参数来跳转到PDF 中的特定位置,但是如果您想跳转到特定书签,则需要检查书签(例如使用SimpleBookmark类。如果你看到书签指向某个页面,你需要使用page参数,你可以将它与zoomviewviewrect参数结合使用,具体取决于为该页面定义的目的地。

    【讨论】:

      猜你喜欢
      • 2012-09-01
      • 2020-01-21
      • 2014-03-26
      • 1970-01-01
      • 2015-10-30
      • 2021-04-24
      • 1970-01-01
      • 2022-11-18
      • 2012-04-29
      相关资源
      最近更新 更多