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:
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:
Returns:
-
Type
-
Promise.<void>
- Description:
Returns:
0|表示没有发现;1|表示识别成功;
-
Type
-
Promise.<number>
(async) deactivateAnnotation() → {Promise.<boolean>}
- Description:
Returns:
-
Type
-
Promise.<boolean>
(async) exportAnnotsToFDF() → {Promise.<void>}
- Description:
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:
Parameters:
| Name |
Type |
Description |
index |
number
|
页面索引,从0开始 |
Returns:
-
Type
-
Promise.<PDFPage>
(async) getPageCount() → {Promise.<number>}
- Description:
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:
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:
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:
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:
Returns:
-
Type
-
Promise.<void>
- Description:
Returns:
-
Type
-
Promise.<PDFForm>
(async) openBookmark(bookmark) → {Promise.<void>}
- Description:
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
|
大小 |
|