@component-hook/pdf-canvas 0.1.6 → 0.2.0-alpha.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 +44 -3
- package/dist/react/pdf-canvas.es.d.ts +108 -0
- package/dist/react/pdf-canvas.es.js +22167 -0
- package/dist/react/pdf-canvas.umd.js +538 -0
- package/dist/vue/chunks/__vite-browser-external-DYxpcVy9.js +4 -0
- package/dist/{index.d.ts → vue/pdf-canvas.es.d.ts} +17 -19
- package/dist/{pdf-canvas.es.js → vue/pdf-canvas.es.js} +4910 -4810
- package/dist/vue/pdf-canvas.umd.js +509 -0
- package/package.json +19 -12
- package/dist/pdf-canvas.umd.js +0 -509
- /package/dist/{chunks → react/chunks}/__vite-browser-external-DYxpcVy9.js +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @component-hook/pdf-canvas
|
|
2
2
|
|
|
3
|
-
Rendering PDF documents onto a canvas with vue3 component ([DEMO](https://tzuyi0817.github.io/component-hook/#/component/pdf-canvas))
|
|
3
|
+
Rendering PDF documents onto a canvas with vue3 and react component ([DEMO](https://tzuyi0817.github.io/component-hook/#/component/pdf-canvas))
|
|
4
4
|
Implementation depository: [PDF-signature](https://github.com/tzuyi0817/PDF-signature)
|
|
5
5
|
|
|
6
6
|
<p>
|
|
@@ -32,12 +32,12 @@ $ yarn add @component-hook/pdf-canvas
|
|
|
32
32
|
$ pnpm install @component-hook/pdf-canvas
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
##
|
|
35
|
+
## Usage with Vue
|
|
36
36
|
|
|
37
37
|
```vue
|
|
38
38
|
<script setup lang="ts">
|
|
39
39
|
import { ref } from 'vue';
|
|
40
|
-
import PdfCanvas, { useFabric, type PDF } from '@component-hook/pdf-canvas';
|
|
40
|
+
import PdfCanvas, { useFabric, type PDF } from '@component-hook/pdf-canvas/vue';
|
|
41
41
|
|
|
42
42
|
const { loadFile } = useFabric();
|
|
43
43
|
const currentPdf = ref<PDF>();
|
|
@@ -82,6 +82,47 @@ async function uploadFile(event: Event) {
|
|
|
82
82
|
</template>
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
## Usage with React
|
|
86
|
+
|
|
87
|
+
```jsx
|
|
88
|
+
import { useState, type ChangeEvent } from 'react';
|
|
89
|
+
import PdfCanvas, { useFabric, type PDF } from '@component-hook/pdf-canvas/react';
|
|
90
|
+
|
|
91
|
+
export function DrawPdf() {
|
|
92
|
+
const { loadFile } = useFabric();
|
|
93
|
+
const [currentPdf, setCurrentPdf] = useState<PDF>();
|
|
94
|
+
|
|
95
|
+
const uploadFile = async (event: ChangeEvent<HTMLInputElement>) => {
|
|
96
|
+
const target = event.target;
|
|
97
|
+
const { files } = target;
|
|
98
|
+
|
|
99
|
+
if (!files || files.length === 0) return;
|
|
100
|
+
|
|
101
|
+
const file = files[0];
|
|
102
|
+
const content = await loadFile(file);
|
|
103
|
+
|
|
104
|
+
setCurrentPdf(content);
|
|
105
|
+
target.value = '';
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<div>
|
|
110
|
+
{currentPdf ? <PdfCanvas file={currentPdf} /> : <p>Please select a PDF file or image.</p>}
|
|
111
|
+
|
|
112
|
+
<button>
|
|
113
|
+
<input
|
|
114
|
+
type="file"
|
|
115
|
+
accept="application/pdf, .jpg, .png"
|
|
116
|
+
onChange={uploadFile}
|
|
117
|
+
/>
|
|
118
|
+
select file
|
|
119
|
+
</button>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
|
|
85
126
|
## Attributes
|
|
86
127
|
|
|
87
128
|
| Name | Required | Type | Description | Default |
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Canvas } from 'fabric';
|
|
2
|
+
import { FabricObject } from 'fabric';
|
|
3
|
+
import { FabricObjectProps } from 'fabric';
|
|
4
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
5
|
+
import { ImageProps } from 'fabric';
|
|
6
|
+
import { ObjectEvents } from 'fabric';
|
|
7
|
+
import { Point } from 'fabric';
|
|
8
|
+
import { RefAttributes } from 'react';
|
|
9
|
+
import { SerializedObjectProps } from 'fabric';
|
|
10
|
+
import { TEvent } from 'fabric';
|
|
11
|
+
import { TextProps } from 'fabric';
|
|
12
|
+
import { TOptions } from 'fabric';
|
|
13
|
+
|
|
14
|
+
export declare interface CloseSvgOptions {
|
|
15
|
+
stroke: string;
|
|
16
|
+
hoverStroke: string;
|
|
17
|
+
src: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export declare interface ComponentProps {
|
|
21
|
+
file: PDF;
|
|
22
|
+
page?: number;
|
|
23
|
+
canvasId?: string;
|
|
24
|
+
fileZoom?: number;
|
|
25
|
+
fileScale?: number;
|
|
26
|
+
canvasScale?: number;
|
|
27
|
+
canvasClass?: string;
|
|
28
|
+
isDrop?: boolean;
|
|
29
|
+
password?: string;
|
|
30
|
+
dropTextOptions?: TOptions<TextProps>;
|
|
31
|
+
dropImageOptions?: TOptions<ImageProps>;
|
|
32
|
+
closeSvgOptions?: CloseSvgOptions;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export declare interface CreateCloseFabricArgs {
|
|
36
|
+
canvas: Canvas;
|
|
37
|
+
target: FabricObject;
|
|
38
|
+
stroke?: string;
|
|
39
|
+
uuid?: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export declare interface PDF {
|
|
43
|
+
PDFId: string;
|
|
44
|
+
name: string;
|
|
45
|
+
updateDate: number;
|
|
46
|
+
PDFBase64: string;
|
|
47
|
+
pages: number;
|
|
48
|
+
canvas?: string[];
|
|
49
|
+
trashDate?: number;
|
|
50
|
+
isUpdate?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
declare const PdfCanvas: ForwardRefExoticComponent<ComponentProps & RefAttributes<PdfCanvasHandle>>;
|
|
54
|
+
export default PdfCanvas;
|
|
55
|
+
|
|
56
|
+
export declare interface PdfCanvasHandle {
|
|
57
|
+
addImage: (src: string, options?: TOptions<ImageProps>) => void;
|
|
58
|
+
addText: (text: string, options?: TOptions<TextProps>) => void;
|
|
59
|
+
clearActive: () => void;
|
|
60
|
+
deleteCanvas: () => void;
|
|
61
|
+
canvasRef: React.RefObject<HTMLCanvasElement>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export declare interface RenderImageArgs {
|
|
65
|
+
url: string;
|
|
66
|
+
scale?: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export declare type SelectedEvent = Partial<TEvent> & {
|
|
70
|
+
target: FabricObject<Partial<FabricObjectProps>, SerializedObjectProps, ObjectEvents>;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export declare interface SpecifyPageArgs {
|
|
74
|
+
page: number;
|
|
75
|
+
PDFBase64: string;
|
|
76
|
+
scale: number;
|
|
77
|
+
password?: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export declare type SupportFileType = 'application/pdf' | 'image/png' | 'image/jpeg';
|
|
81
|
+
|
|
82
|
+
export declare interface TCornerPoint {
|
|
83
|
+
tl: Point;
|
|
84
|
+
tr: Point;
|
|
85
|
+
bl: Point;
|
|
86
|
+
br: Point;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export declare function useFabric(id?: string): {
|
|
90
|
+
createCanvas: () => Canvas | undefined;
|
|
91
|
+
loadFile: (file: File, password?: string) => Promise<{
|
|
92
|
+
pages: number;
|
|
93
|
+
PDFId: string;
|
|
94
|
+
name: string;
|
|
95
|
+
updateDate: number;
|
|
96
|
+
PDFBase64: string;
|
|
97
|
+
} | undefined>;
|
|
98
|
+
specifyPage: ({ page, PDFBase64, scale, password }: SpecifyPageArgs) => Promise<void>;
|
|
99
|
+
renderImage: ({ url, scale }: RenderImageArgs) => Promise<void>;
|
|
100
|
+
addFabric: (src: string, options?: TOptions<ImageProps>) => Promise<void>;
|
|
101
|
+
addTextFabric: (text: string, options?: TOptions<TextProps>) => void;
|
|
102
|
+
clearActive: () => void;
|
|
103
|
+
deleteCanvas: () => void;
|
|
104
|
+
scaleFabric: (scale: number, isCreate?: boolean) => void;
|
|
105
|
+
setCloseSvgOptions: (options?: CloseSvgOptions) => void;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export { }
|