@kne/react-pdf-sign 1.0.6 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +287 -48
- package/dist/index.js +3668 -511
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +3502 -512
- package/dist/index.modern.js.map +1 -1
- package/dist/locale/en-US.js +2 -1
- package/dist/locale/en-US.js.map +1 -1
- package/dist/locale/en-US.modern.js +2 -1
- package/dist/locale/en-US.modern.js.map +1 -1
- package/dist/locale/zh-CN.js +2 -1
- package/dist/locale/zh-CN.js.map +1 -1
- package/dist/locale/zh-CN.modern.js +2 -1
- package/dist/locale/zh-CN.modern.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ npm i --save @kne/react-pdf-sign
|
|
|
16
16
|
|
|
17
17
|
### 概述
|
|
18
18
|
|
|
19
|
-
这是一个功能强大的 React PDF 签名组件库,专为需要在 PDF
|
|
19
|
+
这是一个功能强大的 React PDF 签名组件库,专为需要在 PDF 文档上添加电子签名的应用场景而设计。该组件库提供了灵活的签名解决方案,支持单签名位置和多签名位置两种模式,满足不同业务需求。
|
|
20
20
|
|
|
21
21
|
## 核心特性
|
|
22
22
|
|
|
@@ -24,9 +24,13 @@ npm i --save @kne/react-pdf-sign
|
|
|
24
24
|
|
|
25
25
|
**灵活的定位控制** - 签名区域可以在 PDF 页面上自由拖拽、缩放和精确定位,支持保持比例缩放,确保签名的视觉效果。
|
|
26
26
|
|
|
27
|
+
**多位置签名支持** - 支持在 PDF 文档的多个页面或同一页面的不同位置添加签名,通过 `PDFSignMulti` 组件实现批量签名管理,可动态添加、删除签名位置。
|
|
28
|
+
|
|
27
29
|
**完整的 PDF 操作** - 基于 pdf-lib 和 react-pdf,支持多页 PDF 文档的浏览、签名定位和最终签名文件的生成。
|
|
28
30
|
|
|
29
|
-
**组件化设计** - 提供多个独立组件(PDFSign、PDFViewer、LocationLayer、useSignature),开发者可以根据需求灵活组合使用。支持默认签名位置设置和位置变化回调,便于集成到现有业务流程。
|
|
31
|
+
**组件化设计** - 提供多个独立组件(PDFSign、PDFSignMulti、PDFViewer、LocationLayer、useSignature),开发者可以根据需求灵活组合使用。支持默认签名位置设置和位置变化回调,便于集成到现有业务流程。
|
|
32
|
+
|
|
33
|
+
**智能位置计算** - 内置 `computedPDFSignLocation` 和 `getInitLocation` 工具函数,自动处理显示坐标与 PDF 原始坐标的转换,简化开发复杂度。
|
|
30
34
|
|
|
31
35
|
**国际化支持** - 内置中英文语言包,支持多语言切换,适合国际化应用。
|
|
32
36
|
|
|
@@ -34,13 +38,13 @@ npm i --save @kne/react-pdf-sign
|
|
|
34
38
|
|
|
35
39
|
## 使用场景
|
|
36
40
|
|
|
37
|
-
- 合同签署系统
|
|
38
|
-
- 文档审批流程
|
|
39
|
-
- 电子表单签名
|
|
40
|
-
- 证书颁发系统
|
|
41
|
-
- 法律文件签署
|
|
41
|
+
- 合同签署系统 - 支持多方签名位置预定义
|
|
42
|
+
- 文档审批流程 - 单个或多个审批人签名
|
|
43
|
+
- 电子表单签名 - 固定位置的表单签名
|
|
44
|
+
- 证书颁发系统 - 多签名证书生成
|
|
45
|
+
- 法律文件签署 - 多方见证签名
|
|
42
46
|
|
|
43
|
-
该组件库简化了 PDF
|
|
47
|
+
该组件库简化了 PDF 签名的复杂实现,开发者只需要几行代码就能集成完整的签名功能,大大提升了开发效率。新增的多位置签名功能和智能坐标计算让复杂场景的实现变得简单快捷。
|
|
44
48
|
|
|
45
49
|
### 示例
|
|
46
50
|
|
|
@@ -117,18 +121,210 @@ render(<BaseExample />);
|
|
|
117
121
|
|
|
118
122
|
```
|
|
119
123
|
|
|
124
|
+
- 多位置PDF签名
|
|
125
|
+
- 演示在同一PDF文档中添加多个签名位置的完整流程:1. 上传PDF文档;2. 在编辑模式下点击'添加签名位置'按钮为不同页面添加签名区域;3. 切换至非编辑模式进行签名;4. 完成所有签名后点击'生成签名PDF'导出已签名的文档
|
|
126
|
+
- _ReactPdfSign(@kne/current-lib_react-pdf-sign)[import * as _ReactPdfSign from "@kne/react-pdf-sign"],antd(antd),(@kne/current-lib_react-pdf-sign/dist/index.css)
|
|
127
|
+
|
|
128
|
+
```jsx
|
|
129
|
+
const { PDFSignMulti, useSignature } = _ReactPdfSign;
|
|
130
|
+
const { useState, useRef } = React;
|
|
131
|
+
const { Flex, Button, Switch, App } = antd;
|
|
132
|
+
|
|
133
|
+
const BaseExample = () => {
|
|
134
|
+
const [pdfFile, setPdfFile] = useState(null);
|
|
135
|
+
const [isEdit, setIsEdit] = useState(true);
|
|
136
|
+
const ref = useRef(null);
|
|
137
|
+
const signatureModal = useSignature();
|
|
138
|
+
const { message } = App.useApp();
|
|
139
|
+
return (
|
|
140
|
+
<Flex vertical gap={12}>
|
|
141
|
+
<Flex gap={8} align="center">
|
|
142
|
+
<Button>
|
|
143
|
+
<input
|
|
144
|
+
type="file"
|
|
145
|
+
accept="application/pdf"
|
|
146
|
+
onChange={e => {
|
|
147
|
+
const file = e.target.files[0];
|
|
148
|
+
setPdfFile(URL.createObjectURL(file));
|
|
149
|
+
}}
|
|
150
|
+
/>
|
|
151
|
+
</Button>
|
|
152
|
+
{pdfFile && (
|
|
153
|
+
<Flex gap={8}>
|
|
154
|
+
<div>编辑模式:</div>
|
|
155
|
+
<Switch value={isEdit} onChange={setIsEdit} />
|
|
156
|
+
</Flex>
|
|
157
|
+
)}
|
|
158
|
+
{pdfFile && isEdit && (
|
|
159
|
+
<Button
|
|
160
|
+
onClick={() => {
|
|
161
|
+
ref.current.addSignLocation();
|
|
162
|
+
}}>
|
|
163
|
+
添加签名位置
|
|
164
|
+
</Button>
|
|
165
|
+
)}
|
|
166
|
+
{pdfFile && !isEdit && (
|
|
167
|
+
<Button
|
|
168
|
+
onClick={async () => {
|
|
169
|
+
try {
|
|
170
|
+
const blob = await ref.current.sign();
|
|
171
|
+
const link = document.createElement('a');
|
|
172
|
+
const url = URL.createObjectURL(blob);
|
|
173
|
+
link.href = url;
|
|
174
|
+
link.download = 'signed-document.pdf';
|
|
175
|
+
link.click();
|
|
176
|
+
URL.revokeObjectURL(url);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
message.error(e.message);
|
|
179
|
+
}
|
|
180
|
+
}}>
|
|
181
|
+
生成签名PDF
|
|
182
|
+
</Button>
|
|
183
|
+
)}
|
|
184
|
+
</Flex>
|
|
185
|
+
{pdfFile ? (
|
|
186
|
+
<PDFSignMulti
|
|
187
|
+
url={pdfFile}
|
|
188
|
+
ref={ref}
|
|
189
|
+
isEdit={isEdit}
|
|
190
|
+
onSign={({ size, callback }) => {
|
|
191
|
+
signatureModal({
|
|
192
|
+
mask: (
|
|
193
|
+
<Flex justify="flex-end" align="flex-end" style={{ height: '100%', width: '100%', padding: '10px', boxSizing: 'border-box' }}>
|
|
194
|
+
签字日期: {new Date().toLocaleDateString()}
|
|
195
|
+
</Flex>
|
|
196
|
+
),
|
|
197
|
+
width: size.width,
|
|
198
|
+
height: size.height,
|
|
199
|
+
onSuccess: file => {
|
|
200
|
+
callback(URL.createObjectURL(file));
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}}
|
|
204
|
+
/>
|
|
205
|
+
) : null}
|
|
206
|
+
</Flex>
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
render(<BaseExample />);
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
|
|
120
214
|
- 签名定位层
|
|
121
215
|
- 展示独立的签名定位组件,支持拖拽和缩放调整签名位置
|
|
122
|
-
- _ReactPdfSign(@kne/current-lib_react-pdf-sign)[import * as _ReactPdfSign from "@kne/react-pdf-sign"],(@kne/current-lib_react-pdf-sign/dist/index.css)
|
|
216
|
+
- _ReactPdfSign(@kne/current-lib_react-pdf-sign)[import * as _ReactPdfSign from "@kne/react-pdf-sign"],antd(antd),(@kne/current-lib_react-pdf-sign/dist/index.css)
|
|
123
217
|
|
|
124
218
|
```jsx
|
|
125
|
-
const { LocationLayer } = _ReactPdfSign;
|
|
219
|
+
const { LocationLayer, LocationGroup } = _ReactPdfSign;
|
|
220
|
+
const { Flex, Button, Switch, App } = antd;
|
|
221
|
+
const { useState } = React;
|
|
222
|
+
|
|
223
|
+
const defaultList = [
|
|
224
|
+
{
|
|
225
|
+
size: {
|
|
226
|
+
width: 200,
|
|
227
|
+
height: 80,
|
|
228
|
+
x: 325,
|
|
229
|
+
y: 78
|
|
230
|
+
},
|
|
231
|
+
scaleX: 1,
|
|
232
|
+
scaleY: 1,
|
|
233
|
+
x: 325,
|
|
234
|
+
y: 78
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
size: {
|
|
238
|
+
width: 200,
|
|
239
|
+
height: 80,
|
|
240
|
+
x: 44,
|
|
241
|
+
y: 78
|
|
242
|
+
},
|
|
243
|
+
scaleX: 1,
|
|
244
|
+
scaleY: 1,
|
|
245
|
+
x: 44,
|
|
246
|
+
y: 78
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
size: {
|
|
250
|
+
width: 200,
|
|
251
|
+
height: 80,
|
|
252
|
+
x: 126,
|
|
253
|
+
y: 206
|
|
254
|
+
},
|
|
255
|
+
scaleX: 1,
|
|
256
|
+
scaleY: 1,
|
|
257
|
+
x: 126,
|
|
258
|
+
y: 206
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
size: {
|
|
262
|
+
width: 200,
|
|
263
|
+
height: 195,
|
|
264
|
+
x: 129,
|
|
265
|
+
y: 308
|
|
266
|
+
},
|
|
267
|
+
scaleX: 1,
|
|
268
|
+
scaleY: 2.44,
|
|
269
|
+
x: 129,
|
|
270
|
+
y: 308
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
size: {
|
|
274
|
+
width: 135,
|
|
275
|
+
height: 217,
|
|
276
|
+
x: 355,
|
|
277
|
+
y: 182
|
|
278
|
+
},
|
|
279
|
+
scaleX: 0.67,
|
|
280
|
+
scaleY: 2.71,
|
|
281
|
+
x: 355,
|
|
282
|
+
y: 182
|
|
283
|
+
}
|
|
284
|
+
];
|
|
126
285
|
|
|
127
286
|
const BaseExample = () => {
|
|
287
|
+
const [value, setValue] = useState(defaultList);
|
|
288
|
+
const [isEdit, setIsEdit] = useState(true);
|
|
289
|
+
const { modal } = App.useApp();
|
|
128
290
|
return (
|
|
129
|
-
<
|
|
130
|
-
<LocationLayer stageWidth={
|
|
131
|
-
|
|
291
|
+
<Flex vertical gap={10}>
|
|
292
|
+
<LocationLayer stageWidth={600} stageHeight={400} />
|
|
293
|
+
<Flex vertical gap={4}>
|
|
294
|
+
<Flex gap={8} align="center">
|
|
295
|
+
<Button
|
|
296
|
+
onClick={() => {
|
|
297
|
+
setValue(value => {
|
|
298
|
+
return [...value, {}];
|
|
299
|
+
});
|
|
300
|
+
}}>
|
|
301
|
+
添加
|
|
302
|
+
</Button>
|
|
303
|
+
<Flex gap={4}>
|
|
304
|
+
<div>编辑模式:</div>
|
|
305
|
+
<Switch value={isEdit} onChange={setIsEdit} />
|
|
306
|
+
</Flex>
|
|
307
|
+
</Flex>
|
|
308
|
+
<LocationGroup
|
|
309
|
+
stageWidth={600}
|
|
310
|
+
stageHeight={600}
|
|
311
|
+
value={value}
|
|
312
|
+
onChange={setValue}
|
|
313
|
+
isEdit={isEdit}
|
|
314
|
+
placeholder={isEdit ? '签名区域' : '点击获取点击区域'}
|
|
315
|
+
onClick={output => {
|
|
316
|
+
modal.info({
|
|
317
|
+
title: '非编辑模式获取签名点击区域',
|
|
318
|
+
content: (
|
|
319
|
+
<div style={{ maxHeight: 400, overflow: 'auto' }}>
|
|
320
|
+
<pre style={{ 'white-space': 'break-spaces' }}>{JSON.stringify(output, null, 2)}</pre>
|
|
321
|
+
</div>
|
|
322
|
+
)
|
|
323
|
+
});
|
|
324
|
+
}}
|
|
325
|
+
/>
|
|
326
|
+
</Flex>
|
|
327
|
+
</Flex>
|
|
132
328
|
);
|
|
133
329
|
};
|
|
134
330
|
|
|
@@ -301,19 +497,19 @@ render(<BaseExample />);
|
|
|
301
497
|
|
|
302
498
|
### PDFSign
|
|
303
499
|
|
|
304
|
-
主要的 PDF 签名组件,集成了 PDF
|
|
500
|
+
主要的 PDF 签名组件,集成了 PDF 查看器和签名定位功能,适用于单签名场景。
|
|
305
501
|
|
|
306
|
-
| 属性
|
|
307
|
-
|
|
308
|
-
| url
|
|
309
|
-
| signature
|
|
310
|
-
| width
|
|
311
|
-
| height
|
|
312
|
-
| padding
|
|
313
|
-
| placeholder
|
|
314
|
-
| filename
|
|
315
|
-
| defaultLocation | object | -
|
|
316
|
-
| onChange
|
|
502
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
503
|
+
|-----------------|----------|-----------------------|----------------|
|
|
504
|
+
| url | string | - | PDF 文件的 URL 地址 |
|
|
505
|
+
| signature | string | - | 签名图片的 URL 地址 |
|
|
506
|
+
| width | number | 200 | 签名区域的宽度 |
|
|
507
|
+
| height | number | 80 | 签名区域的高度 |
|
|
508
|
+
| padding | number | 8 | 签名区域变换器的内边距 |
|
|
509
|
+
| placeholder | string | - | 签名区域的占位文本 |
|
|
510
|
+
| filename | string | 'signed-document.pdf' | 生成签名PDF的文件名 |
|
|
511
|
+
| defaultLocation | object | - | 默认签名位置信息 |
|
|
512
|
+
| onChange | function | - | 签名位置变化回调函数 |
|
|
317
513
|
|
|
318
514
|
#### 实例方法
|
|
319
515
|
|
|
@@ -324,6 +520,33 @@ render(<BaseExample />);
|
|
|
324
520
|
| getPdfSignature | - | object | 获取 PDF 签名信息 |
|
|
325
521
|
| sign | - | Promise<File> | 生成签名后的 PDF 文件 |
|
|
326
522
|
|
|
523
|
+
### PDFSignMulti
|
|
524
|
+
|
|
525
|
+
多位置 PDF 签名组件,支持在同一 PDF 文档中添加多个签名位置,适用于需要多方签名或多页面签名的场景。
|
|
526
|
+
|
|
527
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
528
|
+
|----------------------|----------|-----------------------|----------------|
|
|
529
|
+
| url | string | - | PDF 文件的 URL 地址 |
|
|
530
|
+
| width | number | 200 | 签名区域的宽度 |
|
|
531
|
+
| height | number | 80 | 签名区域的高度 |
|
|
532
|
+
| padding | number | 8 | 签名区域变换器的内边距 |
|
|
533
|
+
| placeholder | string | - | 签名区域的占位文本 |
|
|
534
|
+
| filename | string | 'signed-document.pdf' | 生成签名PDF的文件名 |
|
|
535
|
+
| defaultSignatureList | array | - | 默认签名位置列表 |
|
|
536
|
+
| isEdit | boolean | - | 是否处于编辑模式 |
|
|
537
|
+
| onSign | function | - | 点击签名区域时的回调函数 |
|
|
538
|
+
| onChange | function | - | 签名位置列表变化回调函数 |
|
|
539
|
+
|
|
540
|
+
#### 实例方法
|
|
541
|
+
|
|
542
|
+
| 方法名 | 参数 | 返回值 | 说明 |
|
|
543
|
+
|---------------------|--------------|---------------|---------------|
|
|
544
|
+
| getSignatureList | - | array | 获取当前签名位置列表 |
|
|
545
|
+
| setSignatureList | value: array | - | 设置签名位置列表 |
|
|
546
|
+
| getPdfSignatureList | - | array | 获取 PDF 签名信息列表 |
|
|
547
|
+
| sign | - | Promise<File> | 生成签名后的 PDF 文件 |
|
|
548
|
+
| addSignLocation | - | - | 添加一个新的签名位置 |
|
|
549
|
+
|
|
327
550
|
### PDFViewer
|
|
328
551
|
|
|
329
552
|
PDF 文档查看器组件,提供 PDF 页面浏览功能。
|
|
@@ -351,17 +574,31 @@ PDF 文档查看器组件,提供 PDF 页面浏览功能。
|
|
|
351
574
|
|
|
352
575
|
签名定位层组件,用于在 PDF 上定位和调整签名区域。
|
|
353
576
|
|
|
354
|
-
| 属性 | 类型 | 默认值
|
|
355
|
-
|
|
356
|
-
| stageWidth | number | -
|
|
357
|
-
| stageHeight | number | -
|
|
358
|
-
| width | number | 200
|
|
359
|
-
| height | number |
|
|
360
|
-
| padding | number | 8
|
|
361
|
-
| placeholder | string |
|
|
362
|
-
| signature | string | -
|
|
363
|
-
| value | object | -
|
|
364
|
-
| onChange | function | -
|
|
577
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
578
|
+
|-------------|----------|-----|----------|
|
|
579
|
+
| stageWidth | number | - | 画布宽度(必需) |
|
|
580
|
+
| stageHeight | number | - | 画布高度(必需) |
|
|
581
|
+
| width | number | 200 | 签名区域宽度 |
|
|
582
|
+
| height | number | 80 | 签名区域高度 |
|
|
583
|
+
| padding | number | 8 | 变换器内边距 |
|
|
584
|
+
| placeholder | string | - | 占位文本 |
|
|
585
|
+
| signature | string | - | 签名图片 URL |
|
|
586
|
+
| value | object | - | 受控的位置值 |
|
|
587
|
+
| onChange | function | - | 位置变化回调 |
|
|
588
|
+
|
|
589
|
+
### LocationGroup
|
|
590
|
+
|
|
591
|
+
签名位置组组件,用于管理多个签名位置。
|
|
592
|
+
|
|
593
|
+
| 属性 | 类型 | 默认值 | 说明 |
|
|
594
|
+
|-------------|----------|------|------------|
|
|
595
|
+
| stageWidth | number | - | 画布宽度(必需) |
|
|
596
|
+
| stageHeight | number | - | 画布高度(必需) |
|
|
597
|
+
| isEdit | boolean | true | 是否处于编辑模式 |
|
|
598
|
+
| currentPage | number | - | 当前页码 |
|
|
599
|
+
| value | array | - | 受控的位置值数组 |
|
|
600
|
+
| onChange | function | - | 位置列表变化回调 |
|
|
601
|
+
| onClick | function | - | 点击签名区域时的回调 |
|
|
365
602
|
|
|
366
603
|
### useSignature
|
|
367
604
|
|
|
@@ -369,18 +606,20 @@ PDF 文档查看器组件,提供 PDF 页面浏览功能。
|
|
|
369
606
|
|
|
370
607
|
#### 返回的函数参数
|
|
371
608
|
|
|
372
|
-
| 参数 | 类型
|
|
373
|
-
|
|
374
|
-
| filename | string
|
|
375
|
-
| width | number
|
|
376
|
-
| height | number
|
|
609
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
610
|
+
|------------|-----------|-----------------|------------|
|
|
611
|
+
| filename | string | 'signature.png' | 签名文件名 |
|
|
612
|
+
| width | number | 200 | 签名画板宽度 |
|
|
613
|
+
| height | number | 80 | 签名画板高度 |
|
|
377
614
|
| mask | ReactNode | - | 签名画板叠加内容 |
|
|
378
|
-
| onSuccess | function
|
|
379
|
-
| modalProps | object
|
|
615
|
+
| onSuccess | function | - | 签名完成回调 |
|
|
616
|
+
| modalProps | object | - | Modal 组件属性 |
|
|
617
|
+
|
|
618
|
+
### signPdfFile
|
|
619
|
+
|
|
620
|
+
签名文件生成工具函数,支持单个签名。
|
|
380
621
|
|
|
381
|
-
|
|
622
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
623
|
+
|--------------|--------|-----|------------|
|
|
624
|
+
| pdfSignature | object | - | PDF 签名配置对象 |
|
|
382
625
|
|
|
383
|
-
| 参数 | 类型 | 默认值 | 说明 |
|
|
384
|
-
|--------|--------|-----|----------|
|
|
385
|
-
| width | number | 200 | 默认签名画板宽度 |
|
|
386
|
-
| height | number | 80 | 默认签名画板高度 |
|