View

View

View类

Constructor

new View(params)

Example
let FoxitEmbed; // 通过script标签引入的全局变量
let embedView = new FoxitEmbed.View({
  clientId: 'client_id',
  divId: 'div_id',
});
Parameters:
Name Type Description
params Object
Properties
Name Type Attributes Description
clientId string 客户端ID。您可以从福昕开发者控制台获取客户端ID。
divId string 渲染的元素的ID。
locale string <optional>
语言环境。支持的语言环境有'zh-CN'、'en-US'。默认值为浏览器语言。

Members

pdfDoc :PDFDoc|undefined

Description:
  • PDFDoc实例
PDFDoc实例
Type:

Methods

GetReadAloud()

Description:
  • 朗读模块实例。
Deprecated:

addAnnotationIcon()

Description:
  • 添加annotation的图标,目前仅支持stamp类型。
Deprecated:

(async) addFontMaps(fontMaps) → {Promise.<void>}

Description:
  • 设置自定义字体,用于编辑表单字段。该函数仅在文档打开前设置有效。
    自定义字体需要配合 View#previewFile 方法的 `fontInfoPath` 参数使用。使用方法请参考:如何使用自定义字体
Example
let embedView; // View实例
embedView.addFontMaps([{
  nameMatches: [
      /(helvetica)|(helveticabold)|(helveticaoblique)/,
  ],
  name: "helvetica",
  glyphs: [
      {
          bold: 400,
          flags: FoxitEmbed.Constants.Font_Styles.FixedPitch,
          url: 'NotoSans-Bold.ttf.brotli',
          isBrotli: true,
      },
      {
          bold: -1,
          flags: FoxitEmbed.Constants.Font_Styles.FixedPitch,
          url: 'NotoSans-Regular.ttf'
      },
  ],
  charsets:[FoxitEmbed.Constants.Font_Charset.ANSI],
}])
Parameters:
Name Type Description
fontMaps Array.<FontMap> 字体映射数组
Returns:
Type
Promise.<void>

addListener(event, callback) → {function}

Description:
  • 添加事件监听
Example
let embedView; // View实例
embedView.addListener('Annotation_Clicked', (annotationId) => {
  console.log('Annotation_Clicked', annotationId);
});
Parameters:
Name Type Description
event string 事件名称。请参考 EventNames 中的值
callback function 事件回调函数
Returns:
用于移除事件监听的函数
Type
function

addWatermark()

Description:
  • 添加水印。
Deprecated:

(async) destroy() → {Promise.<void>}

Description:
  • 销毁当前的Viewer实例。在多次调用`new FoxitEmbed.View()`进行初始化实例的使用场景中,请确保在不再需要实例时调用此方法,以释放资源。
Returns:
Type
Promise.<void>

getAnnotationManager()

Description:
  • 获取注释管理器实例。
Deprecated:

getBookmarks()

Description:
  • 返回现有PDF书签的列表。
Deprecated:

getCurrentPage()

Description:
  • 获取当前页面的页面号。
Deprecated:

getPageZoom()

Description:
  • 将PDF页码作为输入,并返回该页面的缩放级别。
Deprecated:

getReadManager() → {ReadManager}

Description:
  • 获取朗读管理器实例。
Returns:
朗读管理器实例
Type
ReadManager

getSearchManager(pattern, flagsopt, startPageIndexopt, endPageIndexopt) → {SearchManager}

Description:
  • 获取搜索管理器实例。
Parameters:
Name Type Attributes Default Description
pattern string 被搜索的关键字
flags number <optional>
0 搜索标志。以下标志可以单独使用或组合使用。
0:没有特殊的搜索选项。
1:匹配大小写。
2:全词匹配。
startPageIndex number <optional>
0 开始搜索的页面索引
endPageIndex number <optional>
pageCount-1 结束搜索的页面索引
Returns:
搜索管理器实例
Type
SearchManager

getUserName()

Description:
  • 获取全局用户名。
Deprecated:

gotoLocation()

Description:
  • 导航到任何PDF页面。
Deprecated:

initAnnotationIcons()

Description:
  • 初始化annotation的图标,目前仅支持stamp类型。该函数设置后,默认的标准图章将被替换。
Deprecated:

openBookmark()

Description:
  • 导航到指定的PDF书签
Deprecated:

openSidebar(feature)

Description:
  • 展开指定侧边栏面板。
Parameters:
Name Type Description
feature string 功能值。可选值如下:
Bookmark:书签面板
Search:搜索面板
Comment:注释面板

(async) previewFile(params, optionsopt) → {Promise.<PDFDoc>}

Description:
  • 预览PDF文件
Example
let embedView; // View实例
let pdfDoc = await embedView.previewFile({
  content: 'https://example.com/sample.pdf',
});
Parameters:
Name Type Attributes Description
params Object 预览文件参数
Properties
Name Type Attributes Description
content View.PreviewFileContent PDF文件的URL或文件对象
metaData Object <optional>
PDF文件的元数据
Properties
Name Type Attributes Description
fileName string <optional>
PDF文件的名称
fontInfoPath string <optional>
字体信息csv文件的URL路径。如何需要使用 View#addFontMaps 方法添加自定义字体,则必须设置此参数。
使用方法请参考:如何使用自定义字体
options Object <optional>
配置项
Properties
Name Type Attributes Default Description
embedMode string <optional>
FULL_WINDOW 模式,可选值如下:
1. FULL_WINDOW:全屏窗口。PDF阅读器显示在浏览器窗口的全屏中,方便用户阅读和操作文档。
2. SIZED_CONTAINER:指定尺寸容器。PDF阅读器嵌入指定大小的容器中(需要指定宽度和高度)。
3. IN_LINE:内联显示。PDF阅读器嵌入在网页内容的中间。在此模式下,所有PDF页面将同时显示。您需要在<div>标记中指定嵌入查看器的宽度,查看器将根据PDF页面的宽度和页数自动调整大小和长度(指定宽度,而不是高度)。
4. LIGHT_BOX:弹出框。PDF阅读器在页面上弹出一个窗口,您可以关闭该窗口并返回上一页。
defaultViewMode string <optional>
CONTINUOUS 默认视图模式。可选值如下:
1. CONTINUOUS:连续页面。
2. FIT_WIDTH:适合宽度。
3. FIT_PAGE:适合页面。
4. SINGLE_PAGE:单页。
5. HORIZONTAL_PAGE:横向页面。
showToolControls boolean <optional>
true Deprecated: 请使用 View#setUIGroupVisible 方法代替。
showLeftHandPanel boolean <optional>
true Deprecated: 请使用 View#setUIGroupVisible 方法代替。
showDownloadPDF boolean <optional>
true Deprecated: 请使用 View#setUIElementsVisible 方法代替。
showPrintPDF boolean <optional>
true Deprecated: 请使用 View#setUIElementsVisible 方法代替。
theme Object <optional>
{} Deprecated: 请使用 View#setTheme 方法代替。
showIcon string <optional>
'' Deprecated: 请使用 View#setCustomLogo 方法代替。
Returns:
Type
Promise.<PDFDoc>

removeAnnotationIcon()

Description:
  • 移除自定义的annotation的图标,目前仅支持stamp类型。
Deprecated:
Description:
  • 用于在所有的嵌入模式中,以编程方式搜索PDF中的文本。
Deprecated:
Description:
  • 设置自定义Logo。
Parameters:
Name Type Description
logo Object Logo配置对象
Properties
Name Type Description
url string Logo的URL
Returns:
Type
void

setCustomProgress(progress) → {void}

Description:
  • 设置自定义进度条。
Parameters:
Name Type Description
progress Object 进度条配置对象
Properties
Name Type Attributes Description
url string 进度条的URL
text string <optional>
加载文案
Returns:
Type
void

setCustomToolbarButton(toolbarButtons) → {void}

Description:
  • 设置自定义工具栏按钮。
Example
let embedView; // View实例
embedView.setCustomToolbarButton([
  {
    position: 'right',
    type: 'button',
    icon: 'https://www.example.com/icon.svg',
    tooltip: 'tooltip',
    onClick: () => {
      console.log('on click');
    },
  },
]);
Parameters:
Name Type Description
toolbarButtons Array.<ToolbarButtonOptions> 自定义工具栏按钮配置数组
Returns:
Type
void

setTheme(theme)

Description:
  • 设置主题
Parameters:
Name Type Description
theme Object 主题配置对象
Properties
Name Type Attributes Default Description
primaryColor string <optional>
#F58220 主题色
secondaryColor string <optional>
#F4F4F4 次要颜色

setUIElementsVisible(elements, visible) → {void}

Description:
  • 设置UI功能是否可见。在使用此函数之前,请确保已调用过previewFile,否则部分功能的设置将被覆盖。
Example
let embedView; // View实例
embedView.setUIElementsVisible([FoxitEmbed.Constants.Features.UndoRedo], false);
Parameters:
Name Type Description
elements Array.<string> 功能值。请参考 Constants.Features 中的值
visible boolean 是否可见
Returns:
Type
void

setUIGroupVisible(group, visible) → {void}

Description:
  • 设置UI组是否可见。在使用此函数之前,请确保已调用过previewFile,否则部分功能的设置将被覆盖。
Example
let embedView; // View实例
embedView.setUIGroupVisible([FoxitEmbed.Constants.FeatureGroup.Toolbar], false);
Parameters:
Name Type Description
group Array.<string> 功能组值。请参考 Constants.FeatureGroup 中的值
visible boolean 是否可见
Returns:
Type
void

setUserName()

Description:
  • 设置全局用户名。
Deprecated:

(async) updatePreference(preference) → {Promise.<void>}

Description:
  • 用户偏好设置
Parameters:
Name Type Description
preference Object 偏好设置对象
Properties
Name Type Description
beMarkupWithSelectedText boolean 在添加文本标记注释后,是否使用所选文本作为标记内容
Returns:
Type
Promise.<void>

zoomTo()

Description:
  • 缩放当前的Viewer。该函数不能用于inline嵌入模式。
Deprecated:

Type Definitions

PreviewFileContent

Description:
  • PDF文件的URL或文件对象
PDF文件的URL或文件对象
Type:
  • string | File | Blob | ArrayBuffer | TypedArray | DataView