Skip to content

Commit 8822886

Browse files
authored
[QuickSignPDF] Allow editing annotations until it is signed and downloaded. Also add Text annotation. (#29)
* [QuickSignPDF] Allow editing annotations until it is signed and downloaded. Also add Text annotation.
1 parent 09204cc commit 8822886

File tree

5 files changed

+662
-148
lines changed

5 files changed

+662
-148
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This is the project that will include a collection of simple tools around the sa
1414
- [Split PDF](https://humantools.io/split-pdf) - This tool helps you to quickly split a large PDF file pages into a lot of single-file PDF files.
1515
- [Photos Slideshow](https://humantools.io/split-pdf) - This tool helps you to quickly turn your photos into a video slideshow.
1616
- [Images to PDF](https://humantools.io/images-to-pdf) - This tool helps you to quickly merge bunch of images into one PDF file.
17+
- [Quick Sign](https://humantools.io/quick-sign-pdf) - Quickly sign and add text to PDF files.
1718

1819
# Deploying New Version
1920

Diff for: package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
"@human-tools/use-sortable": "^0.0.5",
99
"@tailwindcss/forms": "^0.2.1",
1010
"exif-auto-rotate": "^0.2.0",
11+
"fabric": "^5.2.4",
12+
"fabricjs-react": "1.0.8",
1113
"file-saver": "^2.0.5",
1214
"jszip": "^3.6.0",
1315
"pdf-lib": "^1.16.0",
1416
"pdfjs-dist": "^2.6.347",
1517
"react": "^17.0.1",
1618
"react-dom": "^17.0.1",
1719
"react-dropzone": "^11.3.1",
18-
"react-hooks-svgdrawing": "^2.1.2",
1920
"react-router-dom": "^5.2.0",
2021
"react-scripts": "4.0.2",
2122
"react-spinners": "^0.10.6",
@@ -54,6 +55,7 @@
5455
"@testing-library/jest-dom": "^5.11.9",
5556
"@testing-library/react": "^11.2.5",
5657
"@testing-library/user-event": "^12.7.1",
58+
"@types/fabric": "^4.5.14",
5759
"@types/file-saver": "^2.0.1",
5860
"@types/jest": "^26.0.20",
5961
"@types/node": "^12.20.1",
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
FabricJSCanvas,
3+
FabricJSEditor,
4+
useFabricJSEditor,
5+
} from 'fabricjs-react';
16
import { GlobalWorkerOptions } from 'pdfjs-dist';
27
import { PDFDocumentProxy } from 'pdfjs-dist/types/display/api';
38
import { PageViewport } from 'pdfjs-dist/types/display/display_utils';
@@ -9,8 +14,6 @@ import {
914
useRef,
1015
useState,
1116
} from 'react';
12-
import { useSvgDrawing } from 'react-hooks-svgdrawing';
13-
import { DrawingOption, SvgDrawing } from 'svg-drawing';
1417
import workerContent from '../pdfjs.worker.min.json';
1518

1619
const workerBlob = new Blob([workerContent], { type: 'text/javascript' });
@@ -23,37 +26,14 @@ interface Props {
2326
scale?: number;
2427
}
2528

26-
export interface UseSvgDrawing {
27-
instance: SvgDrawing | null;
28-
clear: () => void;
29-
undo: () => void;
30-
changePenColor: (penColor: DrawingOption['penColor']) => void;
31-
changePenWidth: (penwidth: DrawingOption['penWidth']) => void;
32-
changeFill: (penColor: DrawingOption['fill']) => void;
33-
changeClose: (penwidth: DrawingOption['close']) => void;
34-
changeDelay: (penColor: DrawingOption['delay']) => void;
35-
changeCurve: (penwidth: DrawingOption['curve']) => void;
36-
getSvgXML: () => string | null;
37-
download: (ext: 'svg' | 'png' | 'jpg') => void;
38-
}
39-
40-
const DrawablePagePreview = forwardRef<UseSvgDrawing, Props>(function (
29+
const FabricPagePreview = forwardRef<FabricJSEditor, Props>(function (
4130
{ pdf, pageNumber, scale }: Props,
4231
ref
4332
): JSX.Element {
4433
const canvasRef = useRef<HTMLCanvasElement>(null);
4534
const [viewport, setViewport] = useState<PageViewport>();
46-
// const drawingDivRef = useRef<HTMLDivElement>(null);
47-
const [renderRef, draw] = useSvgDrawing({
48-
penWidth: 2, // pen width
49-
penColor: '#000', // pen color
50-
close: false, // Use close command for path. Default is false.
51-
curve: true, // Use curve command for path. Default is true.
52-
delay: 60, // Set how many ms to draw points every.
53-
fill: 'none', // Set fill attribute for path. default is `none`
54-
});
55-
56-
useImperativeHandle(ref, () => draw);
35+
const { editor, onReady } = useFabricJSEditor();
36+
useImperativeHandle(ref, () => editor!);
5737

5838
const load = useCallback(async () => {
5939
const page = await pdf.getPage(pageNumber);
@@ -86,16 +66,18 @@ const DrawablePagePreview = forwardRef<UseSvgDrawing, Props>(function (
8666
height={viewport?.height}
8767
></canvas>
8868
{/* Drawing Canvas */}
89-
<div
90-
className="absolute top-0 right-0 left-0 bottom-0"
91-
ref={renderRef}
92-
style={{
93-
width: viewport?.width,
94-
height: viewport?.height,
95-
}}
96-
></div>
69+
{viewport && (
70+
<FabricJSCanvas
71+
className="absolute top-0 right-0 left-0 bottom-0"
72+
onReady={(canvas) => {
73+
canvas.width = viewport!.width;
74+
canvas.height = viewport!.height;
75+
onReady(canvas);
76+
}}
77+
/>
78+
)}
9779
</div>
9880
);
9981
});
10082

101-
export default DrawablePagePreview;
83+
export default FabricPagePreview;

0 commit comments

Comments
 (0)