如何以编程方式阅读PDF书签
问题描述:
我使用PDF转换器访问PDF中的图形数据。一切工作正常,除了我没有得到一个书签的列表。是否有可以读取PDF书签的命令行应用程序或C#组件?我发现iText和SharpPDF库,我目前正在通过他们。
I'm using a PDF converter to access the graphical data within a PDF. Everything works fine, except that I don't get a list of the bookmarks. Is there a command-line app or a C# component that can read a PDF's bookmarks? I found the iText and SharpPDF libraries and I'm currently looking through them. Have you ever done such a thing?
答
尝试以下代码
PdfReader pdfReader = new PdfReader(filename);
IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfReader);
for(int i=0;i<bookmarks.Count;i++)
{
MessageBox.Show(bookmarks[i].Values.ToArray().GetValue(0).ToString());
if (bookmarks[i].Count > 3)
{
MessageBox.Show(bookmarks[i].ToList().Count.ToString());
}
}
注意:不要忘记添加iTextSharp DLL您的专案。
Note: Don't forget to add iTextSharp DLL to your project.