Skip to content

PDF 行为 (PDF Action)

PDF Action 代表 PDF 操作类的基类。福昕 PDF SDK 提供了 APIs 用来创建一系列行为,并获取行为句柄,比如 embedded goto action, JavaScript action, named actionlaunch action 等。

c++
#include "include/common/fs_common.h"
#include "include/pdf/actions/fs_action.h"
#include "include/pdf/annots/fs_annot.h"
#include "include/pdf/objects/fs_pdfobject.h"

using namespace foxit;
using namespace foxit::common;
using namespace pdf;
using namespace annots;

// Assuming PDFPage page has been loaded and parsed.
// Assuming the annnots in the page have been loaded.
...

// Add link annotation
annots::Link link(page.AddAnnot(Annot::e_Link, RectF(350,350,380,400)));
link.SetHighlightingMode(Annot::e_HighlightingToggle);
// Add action for link annotation
using foxit::pdf::actions::Action;
using foxit::pdf::actions::URIAction;
URIAction action = (URIAction)Action::Create(page.GetDocument(), Action::e_TypeURI);
action.SetTrackPositionFlag(true);
action.SetURI("www.foxit.com");
link.SetAction(action);
// Appearance should be reset.
link.ResetAppearanceStream();
C
#include "include/fs_basictypes_c.h"
#include "include/fs_common_c.h"
#include "include/fs_action_c.h"
#include "include/fs_annot_c.h"
#include "include/fs_pdfobject_c.h"

// Assuming FS_PDFPAGE_HANDLE page has been loaded and parsed.
// Assuming the annnots in the page have been loaded.
...

// Add link annotation
FS_LINKANNOT_HANDLE link;
FSRectF rectf;
rectf.left = 350;
rectf.bottom = 350;
rectf.right = 380;
rectf.top = 400;
FSDK_PDFPage_AddAnnot(page, e_FSLink, recf, &link);
FSDK_Link_SetHighlightingMode(link, e_FSHighlightingToggle);
// Add action for link annotation
FS_PDFDOC_HANDLE doc;
FSDK_PDFPage_GetDocument(page, &doc);
FS_ACTION_HANDLE action;
FSDK_Action_Create(doc, e_FSTypeURI, &action);
FS_URIACTION_HANDLE uriaction;
FSDK_URIAction_Create(action, &uriaction);
FSDK_URIAction_SetTrackPositionFlag(uriaction, true);
FSDK_URIAction_SetURI(uriaction, "www.foxit.com");
FSDK_Link_SetAction(link, uriaction);

// Appearance should be reset.
FS_BOOL result;
FSDK_Annot_ResetAppearanceStream(link, &result);
FSDK_Action_Release(uriaction);
FSDK_Link_Release(link);
FSDK_Annot_Release(annot);
FSDK_PDFDoc_Release (doc);
java
import com.foxit.sdk.pdf.actions.Action;
import com.foxit.sdk.pdf.actions.URIAction;
import com.foxit.sdk.pdf.annots.Link;
...

// Assuming PDFPage page has been loaded and parsed.
// Assuming the annnots in the page have been loaded.

// Add link annotation
Link link = new Link(page.addAnnot(Annot.e_Link, new RectF(350, 350, 380, 400)));
link.setHighlightingMode(Annot.e_HighlightingToggle);

// Add action for link annotation
Action action = Action.create(page.getDocument(), Action.e_TypeURI);
URIAction uriAction = new URIAction(action);
uriAction.setTrackPositionFlag(true);
uriAction.setURI("www.foxit.com");
link.setAction(uriAction);
// Appearance should be reset.
link.resetAppearanceStream();
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Assuming PDFPage page has been loaded and parsed.
# Assuming the annnots in the page have been loaded.
...

# Add link annotation
link = Link(page.AddAnnot(Annot.e_Link, RectF(350,350,380,400)))
link.SetHighlightingMode(Annot.e_HighlightingToggle)
# Add action for link annotation

action = URIAction(Action.Create(page.GetDocument(), Action.e_TypeURI))
action.SetTrackPositionFlag(True)
action.SetURI("www.foxit.com")
link.SetAction(action)
# Appearance should be reset.
link.ResetAppearanceStream()
objc
#include "FSPDFObjC.h"
...

// Add link annotation
FSRectF* annot_rect = [[FSRectF alloc] initWithLeft1:350 bottom1:350 right1:380 top1:400];
FSLink* link = [[FSLink alloc] initWithAnnot:[page addAnnot:FSAnnotLink rect:annot_rect]];
[link setHighlightingMode:FSAnnotHighlightingToggle];

// Add action for link annotation
FSPDFDoc* doc = [page getDocument];
FSURIAction* action = [[FSURIAction alloc] initWithAction:[FSAction create:doc action_type:FSActionTypeURI]];
[action setTrackPositionFlag:YES];
[action setURI:@"www.foxit.com"];
[link setAction:action];
// Appearance should be reset.
[link resetAppearanceStream];
...
js
const FSDK = require("@foxitsoftware/foxit-pdf-sdk-node");

...
// Assuming PDFPage page has been loaded and parsed.
// Assuming the annnots in the page have been loaded.
...

// Add link annotation.
let link = new FSDK.Link(page.AddAnnot(FSDK.Annot.e_Link, new FSDK.RectF(350,350,380,400)));
// This flag is used for printing annotations.
link.SetFlags(4);
link.SetHighlightingMode(FSDK.Annot.e_HighlightingPush);

// Add action for link annotation.
let action = new FSDK.URIAction(FSDK.Action.Create(page.GetDocument(), FSDK.Action.e_TypeURI));
action.SetTrackPositionFlag(true);
action.SetURI("www.foxit.com");
link.SetAction(action);
// Appearance should be reset.
link.ResetAppearanceStream();
csharp
using foxit.common;
using foxit.pdf;
using foxit;
using foxit.pdf.annots;
using foxit.common.fxcrt;
using foxit.pdf.annots;
using foxit.pdf.actions;

// Add link annotation
Link link = null;
Annot annot = null;
using (annot = page.AddAnnot(Annot.Type.e_Link, new RectF(350, 350, 380, 400)))
using (link = new Link(annot))
using (PDFDoc doc = page.GetDocument())
{
    foxit.pdf.actions.Action action = null;
    link.SetHighlightingMode(Annot.HighlightingMode.e_HighlightingToggle);

    // Add action for link annotation
    URIAction uriaction = null;
    using (action = foxit.pdf.actions.Action.Create(doc, foxit.pdf.actions.Action.Type.e_TypeGoto))
    using (uriaction = new URIAction(action))
    {
        uriaction.SetTrackPositionFlag(true);
        uriaction.SetURI("www.foxit.com");
        link.SetAction(uriaction);

        // Appearance should be reset.
        link.ResetAppearanceStream();
    }
}
c++
#include "include/common/fs_common.h"
#include "include/pdf/actions/fs_action.h"
#include "include/pdf/annots/fs_annot.h"
#include "include/pdf/fs_pdfdoc.h"
#include "include/pdf/objects/fs_pdfobject.h"
#include "include/pdf/fs_pdfpage.h"

using namespace foxit;
using namespace foxit::common;
using namespace pdf;
using namespace annots;

// Assuming the PDFDoc doc has been loaded.
// Assuming PDFPage page has been loaded and parsed.

// Add link annotation
annots::Link link(page.AddAnnot(Annot::e_Link, RectF(350,350,380,400)));
link.SetHighlightingMode(Annot::e_HighlightingToggle);

GotoAction action = Action::Create(page.GetDocument(), Action::e_TypeGoto);
Destination newDest = Destination::CreateXYZ(page.GetDocument(), 0,0,0,0);
action.SetDestination(newDest);
C
#include "include/fs_basictypes_c.h"
#include "include/fs_common_c.h"
#include "include/fs_action_c.h"
#include "include/fs_annot_c.h"
#include "include/fs_pdfdoc_c.h"
#include "include/fs_pdfobject_c.h"
#include "include/fs_pdfpage_c.h"

// Assuming the FS_PDFDOC_HANDLE doc has been loaded.
// Assuming FS_PDFPAGE_HANDLE page has been loaded and parsed.

// Add link annotation
FS_LINKANNOT_HANDLE link;
FSRectF rectf;
rectf.left = 350;
rectf.bottom = 350;
rectf.right = 380;
rectf.top = 400;
FSDK_PDFPage_AddAnnot(page, e_FSLink, recf, &link);
FSDK_Link_SetHighlightingMode(link, e_FSHighlightingToggle);

FS_GOTOACTION_HANDLE gotoaction;
FS_PDFDOC_HANDLE doc;
FSDK_PDFPage_GetDocument(page, &doc);
FS_ACTION_HANDLE action;
FSDK_Action_Create(doc, e_FSTypeGoto, &action);
FSDK_GotoAction_Create(gotoaction, &action);
FS_DESTINATION_HANDLE newDest;
FSDK_Destination_CreateXYZ(doc, 0, 0, 0, 0, &newDest);
FSDK_GotoAction_SetDestination(gotoaction, newDest);
java
import com.foxit.sdk.common.fxcrt.RectF;
import com.foxit.sdk.pdf.actions.Action;
import com.foxit.sdk.pdf.actions.GotoAction;
import com.foxit.sdk.pdf.annots.Link;
...

// Assuming PDFPage page has been loaded and parsed.
// Assuming the annnots in the page have been loaded.

Link link = new Link(page.addAnnot(Annot.e_Link, new RectF(350, 350, 380, 400)));
link.setHighlightingMode(Annot.e_HighlightingToggle);

// Add action for link annotation
Action action = Action.create(page.getDocument(), Action.e_TypeGoto);
GotoAction gotoAction = new GotoAction(action);
Destination dest = Destination.createFitPage(doc, 0);
gotoAction.setDestination(dest);
...
py
import sys
import site

if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False

if _PYTHON2_:
    # replace with the python2 lib path
    site.addsitedir(‘../../../’)
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *

...
# Assuming the PDFDoc doc has been loaded.
# Assuming PDFPage page has been loaded and parsed.

# Add link annotation
link = Link(page.AddAnnot(Annot.e_Link, RectF(350,350,380,400)))
link.SetHighlightingMode(Annot.e_HighlightingToggle)

action = Action.Create(page.GetDocument(), Action.e_TypeGoto)
newDest = Destination.CreateXYZ(page.GetDocument(), 0,0,0,0)
action.SetDestination(newDest)
objc
#include "FSPDFObjC.h"
...

// Assuming FSPDFPage page has been loaded.
...

// Add link annotation
FSRectF* annot_rect = [[FSRectF alloc] initWithLeft1:350 bottom1:350 right1:380 top1:400];
FSLink* link = [[FSLink alloc] initWithAnnot:[page addAnnot:FSAnnotLink rect:annot_rect]];
[link setHighlightingMode:FSAnnotHighlightingToggle];

// Add action for link annotation
FSPDFDoc* doc = [page getDocument];
FSGotoAction* action = [[FSGotoAction alloc] initWithAction:[FSAction create:doc action_type: FSActionTypeGoto]];
action.destination = [FSDestination createFitPage:doc page_index:0];
// Appearance should be reset.
[link resetAppearanceStream];
...
js
const FSDK = require("@foxitsoftware/foxit-pdf-sdk-node");

...
// Assuming the PDFDoc doc has been loaded.
// Assuming PDFPage page has been loaded and parsed.

// Add link annotation
let link = new FSDK.Link(page.AddAnnot(FSDK.Annot.e_Link, new FSDK.RectF(350,350,380,400)));
link.SetHighlightingMode(FSDK.Annot.e_HighlightingToggle);

let action = FSDK.Action.Create(page.GetDocument(), Action.e_TypeGoto);
let newDest = Destination.CreateXYZ(page.GetDocument(), 0,0,0,0);
action.SetDestination(newDest);
csharp
using foxit.common;
using foxit.pdf;
using foxit;
using foxit.pdf.annots;
using foxit.common.fxcrt;
using foxit.pdf.annots;
using foxit.pdf.actions;

using foxit.common;
using foxit.pdf;
using foxit;
using foxit.pdf.annots;
using foxit.common.fxcrt;
using foxit.pdf.annots;
using foxit.pdf.actions;

Link link = null;
Annot annot = null;
using (annot = page.AddAnnot(Annot.Type.e_Link, new RectF(350, 350, 380, 400)))
using (link = new Link(annot))
using (PDFDoc doc = page.GetDocument())
{
    foxit.pdf.actions.Action action = null;
    link.SetHighlightingMode(Annot.HighlightingMode.e_HighlightingToggle);

    // Add action for link annotation
    GotoAction gotoaction = null;
    using (action = foxit.pdf.actions.Action.Create(doc, foxit.pdf.actions.Action.Type.e_TypeGoto))
    using (gotoaction = new GotoAction(action))
    {
        Destination dest = Destination.CreateXYZ(doc, 0, 0, 0, 0);
        gotoaction.SetDestination(dest);
        link.SetAction(gotoaction);
        // Appearance should be reset.
        link.ResetAppearanceStream();
    }
}