【Foxit PDF SDK】如何获取PDF注释的操作?

PDF 文档中,某些类型的注释可能包含激活注释时应执行的操作或响应于该注释的特定触发事件应执行的额外操作。

哪些类型的注释可能具有操作或附加操作呢?

·         链接注释可能有操作

·         小窗口工具注释有操作和附加操作

·         屏幕注释可以有操作和附加操作

如何获取PDF注释的操作?

关于注释操作, ++ 示例代码如下:

Cint annot_count = pdf_page.GetAnnotCount();
for (int i = 0; i<annot_count; i++) {
    Annot annot = pdf_page.GetAnnot(i);
    Action action;
    switch (annot.GetType()) {
        case Annot::e_Link: {
            Link link_annot(annot);
            action = link_annot.GetAction();
            break;
        }
        case Annot::e_Screen: {
            Screen screen_annot(annot);
            action = screen_annot.GetAction();
            break;
        }
        case Annot::e_Widget: {
            Widget widget_annot(annot);
            action = widget_annot.GetAction();
            break;
        }
        default:
            continue;
    }
    // Please check if Action object is empty before using it.
    // If Action object is empty, that means current annotation doesn't have action.
    if (action.IsEmpty()) continue;
    …
}

关于额外操作, C++ 示例代码如下:

 

int annot_count = pdf_page.GetAnnotCount();
for (int i = 0; i<annot_count; i++) {
    Annot annot = pdf_page.GetAnnot(i);
    Annot::Type annot_type = annot.GetType();
    if (annot_type != Annot::e_Screen && annot_type != Annot::e_Widget)
        continue;
    AdditionalAction annot_aa(annot);
    // Here, use "AdditionalAction::e_TriggerAnnotMouseButtonPressed" as example.
    // For more available trigger values, please refer to API reference.
    AdditionalAction::TriggerEvent trigger = AdditionalAction::e_TriggerAnnotMouseButtonPressed;
    Action action = annot_aa.GetAction(trigger);
    // Please check if Action object is empty before using it.
    // If Action object is empty, that means current annotation doesn't have additional action for specific trigger event.
    if (action.IsEmpty()) continue;
    …
}