PDFDoc

PDFDoc

PDFDoc类

Constructor

new PDFDoc()

Examples
let embedView; // View实例
let pdfDoc = await embedView.previewFile({
  content: 'https://example.com/sample.pdf',
});
// or
// let pdfDoc = embedView.pdfDoc;
let embedView; // View实例
embedView.addListener('File_Opened', (pdfDoc) => {
  // pdfDoc
});

Methods

(async) activateAnnotation(options) → {Promise.<boolean>}

Description:
  • 激活指定的注释。
Parameters:
Name Type Description
options Object 激活注释的选项
Properties
Name Type Description
annotId number 注释ID
pageIndex number 页面索引,从0开始
Returns:
Type
Promise.<boolean>

(async) addAnnotationIcon(icon) → {Promise.<void>}

Description:
  • 添加annotation的图标,目前仅支持stamp类型。
Example
let embedView; // View实例
let icon = {
  annotType: 'stamp',
  category: 'Category',
  name: 'test',
  width: 150,
  height: 45,
  url: 'xxx://xxx.png',
  fileType: 'png',
};
await embedView.pdfDoc.addAnnotationIcon(icon)
Parameters:
Name Type Description
icon CustomIconConfig 图标配置对象
Returns:
Type
Promise.<void>

(async) addWatermark(watermark) → {Promise.<void>}

Description:
  • 添加视图层面的水印。没有修改源文档。
Example
let embedView; // View实例
embedView.pdfDoc.addWatermark([{
  type: 'text',
  content: 'Confidential',
  pageStart: 0,
  pageEnd: 2,
  isMultiline: true,
  rowSpace: 100,
  columnSpace: 100,
  watermarkSettings: {
    position: 'Center',
    offsetX: 50,
    offsetY: 50,
    scaleX: 1,
    scaleY: 1,
    rotation: 45,
    opacity: 70,
  },
  watermarkTextProperties: {
    font: 'Arial',
    fontSize: 24,
    color: '#FF0000',
    fontStyle: 'normal',
    lineSpace: 5,
    alignment: 'center',
  },
}]);
Parameters:
Name Type Description
watermark WatermarkConfig | Array.<WatermarkConfig> 水印配置对象或数组
Returns:
Type
Promise.<void>

(async) autoRecognitionForm() → {Promise.<number>}

Description:
  • 自动识别PDF文档的表单。
Returns:
0|表示没有发现;1|表示识别成功;
Type
Promise.<number>

(async) deactivateAnnotation() → {Promise.<boolean>}

Description:
  • 取消激活注释。
Returns:
Type
Promise.<boolean>

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

Description:
  • 导出PDF文档的注释到FDF格式。
Returns:
Type
Promise.<void>

(async) getBookmarks(bookmarkopt) → {Promise.<Array.<Bookmark>>}

Description:
  • 返回指定书签节点的子书签列表,如果未指定书签节点,则返回根书签列表。
Parameters:
Name Type Attributes Description
bookmark Bookmark <optional>
书签节点对象,来自`pdfDoc.getBookmarks()`返回的书签列表。如果未指定,则返回根书签列表。
Returns:
Type
Promise.<Array.<Bookmark>>

(async) getCurrentPageIndex() → {Promise.<number>}

Description:
  • 获取当前页面的索引。
Returns:
当前页面的索引
Type
Promise.<number>

(async) getPageByIndex(index) → {Promise.<PDFPage>}

Description:
  • 获取指定索引的PDF页面。
Parameters:
Name Type Description
index number 页面索引,从0开始
Returns:
Type
Promise.<PDFPage>

(async) getPageCount() → {Promise.<number>}

Description:
  • 获取PDF文档的页面计数。
Returns:
页面计数
Type
Promise.<number>

(async) getPageScale(pageIndex) → {Promise.<number>}

Description:
  • 获取指定页面的缩放比例。
Parameters:
Name Type Description
pageIndex number 页面索引,从0开始
Returns:
页面缩放比例
Type
Promise.<number>

(async) getStream(callback) → {Promise.<void>}

Description:
  • 获取PDF文档的流。
Example
let embedView; // View实例
let bufferArray = [];
embedView.pdfDoc.getStream(function ({arrayBuffer, offset, size}) {
  bufferArray.push(arrayBuffer);
}).then(function (size) {
  return new Blob(bufferArray, {type: 'application/pdf'});
});
Parameters:
Name Type Description
callback PDFDoc.GetStreamCallback 回调函数
Returns:
Type
Promise.<void>

(async) getUserName() → {Promise.<string>}

Description:
  • 获取全局用户名。
Returns:
用户名
Type
Promise.<string>

(async) goToPage(pageIndex, topopt, leftopt, isPDFPointopt) → {Promise.<void>}

Description:
  • 导航到指定页面。
Parameters:
Name Type Attributes Default Description
pageIndex number 页面索引,从0开始
top number <optional>
0 页面顶部位置
left number <optional>
0 页面左侧位置
isPDFPoint boolean <optional>
false 是否为PDF坐标点
Returns:
Type
Promise.<void>

(async) importAnnotsFromFDF(fdf) → {Promise.<void>}

Description:
  • 从FDF文件导入注释到PDF文档。
Parameters:
Name Type Description
fdf File | Blob | ArrayBuffer | TypedArray | DataView FDF文件
Returns:
Type
Promise.<void>

(async) initAnnotationIcons(icons) → {Promise.<void>}

Description:
  • 初始化annotation的图标,目前仅支持stamp类型。该函数设置后,默认的标准图章将被替换。
Example
let embedView; // View实例
let icons = [{
  annotType: 'stamp',
  category: 'Category',
  name: 'test',
  width: 150,
  height: 45,
  url: 'xxx://xxx.png',
  fileType: 'png',
}];
await embedView.pdfDoc.initAnnotationIcons(icons)
Parameters:
Name Type Description
icons Array.<CustomIconConfig> 图标配置数组
Returns:
Type
Promise.<void>

(async) loadPDFForm() → {Promise.<PDFForm>}

Description:
  • 获取PDFForm实例
Returns:
Type
Promise.<PDFForm>

(async) openBookmark(bookmark) → {Promise.<void>}

Description:
  • 导航到指定的PDF书签。
Parameters:
Name Type Description
bookmark Bookmark 书签节点对象,来自`pdfDoc.getBookmarks()`返回的书签列表。
Returns:
Type
Promise.<void>

(async) removeAnnotationIcon(type, category, name) → {Promise.<void>}

Description:
  • 移除自定义的annotation的图标,目前仅支持stamp类型。
Example
let embedView; // View实例
await embedView.pdfDoc.removeAnnotationIcon('stamp', 'Category', 'test')
Parameters:
Name Type Description
type string 图标类型,目前仅支持“stamp”。
category string 图标类别。
name string 图标名称,这是一个唯一的标识符。
Returns:
Type
Promise.<void>

(async) setUserName(userName) → {Promise.<void>}

Description:
  • 设置全局用户名。
Parameters:
Name Type Description
userName string 用户名
Returns:
Type
Promise.<void>

(async) zoomTo(scale) → {Promise.<void>}

Description:
  • 缩放到指定比例。
Parameters:
Name Type Description
scale number | 'fitWidth' | 'fitHeight' 缩放比例或适应宽度/高度。
Returns:
Type
Promise.<void>

Type Definitions

GetStreamCallback(data)

Parameters:
Name Type Description
data Object
Properties
Name Type Description
arrayBuffer ArrayBuffer PDF文档的流
offset number 偏移量
size number 大小