簡體   English   中英

如何檢查pdf頁面上是否有書簽?

[英]How to check if a pdf page has a bookmark?

我正在嘗試檢查pdf文件中的頁面是否具有書簽以及該書簽中的內容,我正在使用“ iTextSharp.text.pdf”來閱讀和操作pdf,但是我找不到一種方法檢查頁面上是否有書簽。

請幫忙,謝謝!

我嘗試獲取書簽,但是它獲取了我的所有收藏夾,我不知道如何獲取特定頁面的書簽,我使用了以下代碼:

public void Bookmarks(string pdfSourceFile)
    {
        PdfReader reader = new PdfReader(pdfSourceFile, new System.Text.ASCIIEncoding().GetBytes(""));
        IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(reader);
        foreach (IDictionary<String, Object> bmProperty in bookmarks)
        {

            foreach (var fileProperty in bmProperty.Keys)
            {

                if (fileProperty == "File")
                {
                    // need the edit the value of Key-"File". Will it be possible to alter the value using pdfwriter
                }
            }
        }

您可以從每個書簽字典中的Page鍵提取每個書簽的頁面。

例如:

public bool isBookmarked(string pdfSourceFile, int pageNumber)
{
    var reader = new PdfReader(pdfSourceFile, new System.Text.ASCIIEncoding().GetBytes(""));
    var bookmarks = SimpleBookmark.GetBookmark(reader);
    foreach (var bookmark in bookmarks)
        if (Int32.Parse(bookmark["Page"].ToString().Split(' ')[0]) == pageNumber)
            return true;

    return false;
}
IList<Dictionary<string, object>> bookmarks = SimpleBookmark.GetBookmark(pdfReader);
foreach (Dictionary<string, object> bk in bookmarks)
{
string bjj = bk.Values.ToArray().GetValue(0).ToString();

用這個。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM