Implements

Constructors

  • Create an application instance. Instead of creating an instance in new mode, use create to create an instance.

    Parameters

    • options: AppOptions

      Create the application through the configuration information required by the application, which includes necessary initialization information. Like id, which is the unique identifier of the plugin.

    Returns PluginApp

    const app = await App.create({
    pluginInfo: {
    id: 'client_id',
    name: 'jsplugin_1',
    version: '',
    description: '',
    author: '',
    license: ''
    }
    });

Properties

options: AppOptions
pluginInfo: PluginInfoType

Methods

  • Close the current active document.

    Parameters

    • options: CloseOptions = ...

      Close options, the defalut value is:{promptToSave: true, showCancel: true}

    Returns Promise<boolean>

    If close the document successfully, return true, otherwise return false.

  • Creates a blank document.

    Parameters

    • width: number

      The width of the page in the blank document.

    • height: number

      The height of the page in the blank document.

    Returns Promise<null | DocType>

    The blank document.

  • Gets the top-most document which for displaying PDF file type.

    Returns Promise<null | DocType>

    Returns the document that is currently active.

  • Get the path of the current application.

    Returns Promise<string>

    The path of the current application.

  • Get the title of the current application.

    Returns Promise<string>

    The title of the current application.

  • Gets the document by specified index.

    Parameters

    • index: number

      The index of the document. This value can be iterated through from getDocsCount.

    Returns Promise<null | DocType>

    Get the document by specified index.

  • The number of documents currently open.

    Returns Promise<number>

    Returns the currently open document number.

  • Get the name of the current application.

    Returns Promise<string>

    Get the name of the application. It will be "Foxit PhantomPDF" or "Foxit Reader".

  • Get a tool by name.

    Parameters

    • toolName: string

      The name of the tool.

    Returns Promise<null | ToolType>

    Returns the tool instance.

  • Get the version of the current application.

    Returns Promise<string>

    Get the version of the application.

  • Get the task pane show status.

    Returns Promise<boolean>

  • Load the graphic object addon.

    Returns Promise<boolean>

  • Open a PDF document from a URL.

    Parameters

    • __namedParameters: {
          fileTransferCallbacks: FileTransferCallbacksType;
          headers?: Options;
          password?: string;
          url: string;
      }

    Returns Promise<void>

    await app.openFileFromUrl({
    url: 'https://www.example.com/test.pdf',
    password: '123456',
    headers: {
    'Authorization': 'Bearer 1234567890',
    'cookie': 'name=value; name2=value2'
    },
    fileTransferCallbacks: {
    onProgress: (clientData, progress) => {
    console.log(`onProgress: ${progress}`);
    },
    onResult: (clientData, result, message) => {
    console.log(`onResult: ${result}, ${message}`);
    }
    }
    });
  • Open a PDF document by OpenFromFileOptions.

    Parameters

    Returns Promise<null | DocType>

    await app.openFromFile({
    'fileSrc': './InsertText.pdf',
    'password': '',
    'makeVisible': true,
    'addToMRU': true,
    })
  • Registers a user-supplied event handler to document window.

    Parameters

    • docEventCallbacks: DocEventCallbacksType

      The callback set. Reader will call a corresponding callback when the doc event occurs

    Returns Promise<boolean>

    TRUE means successful, otherwise not.

  • Register the context menu.

    Parameters

    • name: string

      Appends the type name of the right-click menu. Like: "Page","Annot","Select"

    • menus: MenusType

      The menu items of the context menu.

    Returns Promise<boolean>

    If register the context menu successfully, return true, otherwise return false.

     const contextMenuAdditionJs = {
    menuItems: [
    {
    index: 0,
    icon: '',
    title: 'menu1',
    name: 'menu1',
    tooltip: 'menu1',
    describeText: 'menu1',
    isSeparator: false,
    executeProc: () => {
    console.log('Execute proc');
    },
    isEnable: true
    }
    ]}
    await app.registerForContextMenuAddition('Page', contextMenuAdditionJs);
  • register a page object selection handler.

    Parameters

    Returns Promise<null | LPVOIDType>

    Returns the page object selection handler object, which can be used to unregister the page object selection handler.

    const callbacks = {
    onPageObjectSelectionKeyDown: (clientData, doc, curSelectData, keyinfoData) => {
    console.log('onPageObjectSelectionKeyDown', clientData, doc, curSelectData, keyinfoData);
    }
    };
    const pageObjectSelectionHandler = await app.registerPageObjectSelectionHandler(callbacks);
  • Register the rectangle handler.

    Parameters

    • callbacks: ToolJsCallbacksType

      The callback set. Reader will call a corresponding callback when the rectangle is drawn.

    Returns Promise<null | LPVOIDType>

    Returns the rectangle handler object, which can be used to unregister the rectangle handler.

    const callbacks = {
    onToolLButtonDown: (clientData, pageview, flags, point) => {
    console.log('onToolLButtonDown', clientData, pageview, flags, point);
    },
    onToolLButtonUp: (clientData, pageview, flags, point) => {
    console.log('onToolLButtonUp', clientData, pageview, flags, point);
    }
    };
    const toolHandler = await app.registerRectangleHandler(callbacks);
  • register a selection handler.

    Parameters

    • callbacks: SelectionJsCallbacksType

      The callback set. Reader will call a corresponding callback when the selection is made.

    Returns Promise<null | LPVOIDType>

    Returns the selection handler object, which can be used to unregister the selection handler.

    const callbacks = {
    onToolLButtonDown: (clientData, pageview, flags, point) => {
    console.log('onToolLButtonDown', clientData, pageview, flags, point);
    },
    onToolLButtonUp: (clientData, pageview, flags, point) => {
    console.log('onToolLButtonUp', clientData, pageview, flags, point);
    }
    };
    const toolHandler = await app.registerSelectionHandler(callbacks);
  • The selectOpenFile method is used to open a file selection dialog, allowing the user to select one or more files.

    Parameters

    • filter: string

      A file filter string used to specify the visible file types.

    • multi: boolean = false

      Indicates whether multiple file selection is allowed.

    Returns Promise<string[]>

    Returns a promise that resolves to an array of strings, indicating the paths of the selected files.

  • Set the active document.It will be showed top-most.

    Parameters

    • doc: DocType

      The document that you want to set active.

    Returns Promise<boolean>

    If set the document active successfully, return true, otherwise return false.

  • Set the active document by index.

    Parameters

    • index: number

      The index of the document. This value can be iterated through from getDocsCount.

    Returns Promise<boolean>

    If set the document active successfully, return true, otherwise return false.

  • Set the active tool.

    Parameters

    • tool: ToolType

      The tool to be set as active.

    • persistent: boolean = false

      Whether to persist the tool. Default is false.

    Returns Promise<boolean>

    Returns true if the tool is set successfully, otherwise returns false.

  • Show or hide the task pane.

    Parameters

    • show: boolean = true

      Whether to show the task pane. Default is true.

    Returns Promise<void>

  • Unregister the page object selection event handler

    Parameters

    • selectionHandler: LPVOIDType

      The page object selection event handler, usually the object returned by registerPageObjectSelectionHandler

    Returns Promise<boolean>

    Returns the unregistration result

  • Unregister the rectangle handler.

    Parameters

    • toolHandler: LPVOIDType

      The rectangle handler to be unregistered, generally the object returned by registerRectangleHandler.

    Returns Promise<boolean>

    Returns true if the rectangle handler is unregistered successfully, otherwise returns false.

  • Unregister the selection event handler

    Parameters

    • selectionHandler: LPVOIDType

      The selection event handler, usually the object returned by registerSelectionHandlerJs

    Returns Promise<boolean>

    Returns the unregistration result

  • Create an application instance.

    Parameters

    • options: AppOptions

      Create the application through the configuration information required by the application, which includes necessary initialization information. Like id, which is the unique identifier of the plugin.

    Returns Promise<AppType>

    Return the application instance.

    const app = await App.create({
    pluginInfo: {
    id: 'client_id',
    name: 'jsplugin_1',
    version: '',
    description: '',
    author: '',
    license: ''
    }
    });