如何使用c#获取pdf文件书签

时间:2012-03-22 20:24:43

标签: asp.net c#-4.0

如何使用c#从pdf文件中获取书签。

哪个是最好的图书馆。

1 个答案:

答案 0 :(得分:2)

我发现此代码使用iTextSharp从pdf文件中获取所有书签:

public void ExportBookmarksToXml(string SourcePdfPath, string xmlOutputPath, string Password = "")
    {
        PdfReader reader = new PdfReader(SourcePdfPath, new System.Text.ASCIIEncoding().GetBytes(Password));
       //Collection of bookmarks
        IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(reader);
        using (MemoryStream memoryStream = new MemoryStream())
        {
            SimpleBookmark.ExportToXML(bookmarks, memoryStream, "ISO8859-1", true);
            //MessageBox.Show(bookmarks[0].Values.ToString());
            File.WriteAllBytes(xmlOutputPath, memoryStream.ToArray());
        }
    }