react-pdf-highlighter-plus 1.0.0
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/LICENSE +22 -0
- package/README.md +411 -0
- package/dist/esm/components/AreaHighlight.d.ts +82 -0
- package/dist/esm/components/AreaHighlight.js +109 -0
- package/dist/esm/components/AreaHighlight.js.map +1 -0
- package/dist/esm/components/DrawingCanvas.d.ts +48 -0
- package/dist/esm/components/DrawingCanvas.js +277 -0
- package/dist/esm/components/DrawingCanvas.js.map +1 -0
- package/dist/esm/components/DrawingHighlight.d.ts +70 -0
- package/dist/esm/components/DrawingHighlight.js +164 -0
- package/dist/esm/components/DrawingHighlight.js.map +1 -0
- package/dist/esm/components/FreetextHighlight.d.ts +112 -0
- package/dist/esm/components/FreetextHighlight.js +193 -0
- package/dist/esm/components/FreetextHighlight.js.map +1 -0
- package/dist/esm/components/HighlightLayer.d.ts +49 -0
- package/dist/esm/components/HighlightLayer.js +37 -0
- package/dist/esm/components/HighlightLayer.js.map +1 -0
- package/dist/esm/components/ImageHighlight.d.ts +63 -0
- package/dist/esm/components/ImageHighlight.js +65 -0
- package/dist/esm/components/ImageHighlight.js.map +1 -0
- package/dist/esm/components/MonitoredHighlightContainer.d.ts +37 -0
- package/dist/esm/components/MonitoredHighlightContainer.js +42 -0
- package/dist/esm/components/MonitoredHighlightContainer.js.map +1 -0
- package/dist/esm/components/MouseMonitor.d.ts +34 -0
- package/dist/esm/components/MouseMonitor.js +30 -0
- package/dist/esm/components/MouseMonitor.js.map +1 -0
- package/dist/esm/components/MouseSelection.d.ts +66 -0
- package/dist/esm/components/MouseSelection.js +122 -0
- package/dist/esm/components/MouseSelection.js.map +1 -0
- package/dist/esm/components/PdfHighlighter.d.ts +184 -0
- package/dist/esm/components/PdfHighlighter.js +410 -0
- package/dist/esm/components/PdfHighlighter.js.map +1 -0
- package/dist/esm/components/PdfLoader.d.ts +55 -0
- package/dist/esm/components/PdfLoader.js +57 -0
- package/dist/esm/components/PdfLoader.js.map +1 -0
- package/dist/esm/components/ShapeCanvas.d.ts +51 -0
- package/dist/esm/components/ShapeCanvas.js +205 -0
- package/dist/esm/components/ShapeCanvas.js.map +1 -0
- package/dist/esm/components/ShapeHighlight.d.ts +107 -0
- package/dist/esm/components/ShapeHighlight.js +140 -0
- package/dist/esm/components/ShapeHighlight.js.map +1 -0
- package/dist/esm/components/SignaturePad.d.ts +40 -0
- package/dist/esm/components/SignaturePad.js +138 -0
- package/dist/esm/components/SignaturePad.js.map +1 -0
- package/dist/esm/components/TextHighlight.d.ts +93 -0
- package/dist/esm/components/TextHighlight.js +115 -0
- package/dist/esm/components/TextHighlight.js.map +1 -0
- package/dist/esm/components/TipContainer.d.ts +27 -0
- package/dist/esm/components/TipContainer.js +58 -0
- package/dist/esm/components/TipContainer.js.map +1 -0
- package/dist/esm/contexts/HighlightContext.d.ts +44 -0
- package/dist/esm/contexts/HighlightContext.js +16 -0
- package/dist/esm/contexts/HighlightContext.js.map +1 -0
- package/dist/esm/contexts/PdfHighlighterContext.d.ts +89 -0
- package/dist/esm/contexts/PdfHighlighterContext.js +16 -0
- package/dist/esm/contexts/PdfHighlighterContext.js.map +1 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +19 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/coordinates.d.ts +16 -0
- package/dist/esm/lib/coordinates.js +69 -0
- package/dist/esm/lib/coordinates.js.map +1 -0
- package/dist/esm/lib/export-pdf.d.ts +81 -0
- package/dist/esm/lib/export-pdf.js +511 -0
- package/dist/esm/lib/export-pdf.js.map +1 -0
- package/dist/esm/lib/get-bounding-rect.d.ts +3 -0
- package/dist/esm/lib/get-bounding-rect.js +35 -0
- package/dist/esm/lib/get-bounding-rect.js.map +1 -0
- package/dist/esm/lib/get-client-rects.d.ts +3 -0
- package/dist/esm/lib/get-client-rects.js +43 -0
- package/dist/esm/lib/get-client-rects.js.map +1 -0
- package/dist/esm/lib/group-highlights-by-page.d.ts +6 -0
- package/dist/esm/lib/group-highlights-by-page.js +23 -0
- package/dist/esm/lib/group-highlights-by-page.js.map +1 -0
- package/dist/esm/lib/optimize-client-rects.d.ts +3 -0
- package/dist/esm/lib/optimize-client-rects.js +65 -0
- package/dist/esm/lib/optimize-client-rects.js.map +1 -0
- package/dist/esm/lib/pdfjs-dom.d.ts +9 -0
- package/dist/esm/lib/pdfjs-dom.js +55 -0
- package/dist/esm/lib/pdfjs-dom.js.map +1 -0
- package/dist/esm/lib/screenshot.d.ts +4 -0
- package/dist/esm/lib/screenshot.js +24 -0
- package/dist/esm/lib/screenshot.js.map +1 -0
- package/dist/esm/style/AreaHighlight.css +134 -0
- package/dist/esm/style/DrawingCanvas.css +62 -0
- package/dist/esm/style/DrawingHighlight.css +184 -0
- package/dist/esm/style/FreetextHighlight.css +249 -0
- package/dist/esm/style/ImageHighlight.css +97 -0
- package/dist/esm/style/MouseSelection.css +15 -0
- package/dist/esm/style/PdfHighlighter.css +77 -0
- package/dist/esm/style/ShapeCanvas.css +47 -0
- package/dist/esm/style/ShapeHighlight.css +182 -0
- package/dist/esm/style/SignaturePad.css +83 -0
- package/dist/esm/style/TextHighlight.css +199 -0
- package/dist/esm/style/pdf_viewer.css +41 -0
- package/dist/esm/types.d.ts +213 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +91 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PdfHighlighter, PdfHighlighterProps } from "./components/PdfHighlighter";
|
|
2
|
+
import { TextHighlight, TextHighlightProps, TextHighlightStyle } from "./components/TextHighlight";
|
|
3
|
+
import { MonitoredHighlightContainer, MonitoredHighlightContainerProps } from "./components/MonitoredHighlightContainer";
|
|
4
|
+
import { AreaHighlight, AreaHighlightProps, AreaHighlightStyle } from "./components/AreaHighlight";
|
|
5
|
+
import { FreetextHighlight, FreetextHighlightProps, FreetextStyle } from "./components/FreetextHighlight";
|
|
6
|
+
import { ImageHighlight, ImageHighlightProps } from "./components/ImageHighlight";
|
|
7
|
+
import { SignaturePad, SignaturePadProps } from "./components/SignaturePad";
|
|
8
|
+
import { DrawingCanvas, DrawingCanvasProps } from "./components/DrawingCanvas";
|
|
9
|
+
import { DrawingHighlight, DrawingHighlightProps } from "./components/DrawingHighlight";
|
|
10
|
+
import { ShapeCanvas, ShapeCanvasProps } from "./components/ShapeCanvas";
|
|
11
|
+
import { ShapeHighlight, ShapeHighlightProps, ShapeStyle } from "./components/ShapeHighlight";
|
|
12
|
+
import { PdfLoader, PdfLoaderProps } from "./components/PdfLoader";
|
|
13
|
+
import { HighlightContainerUtils, useHighlightContainerContext } from "./contexts/HighlightContext";
|
|
14
|
+
import { viewportPositionToScaled, scaledPositionToViewport } from "./lib/coordinates";
|
|
15
|
+
import { exportPdf, ExportPdfOptions, ExportableHighlight } from "./lib/export-pdf";
|
|
16
|
+
import { PdfHighlighterUtils, usePdfHighlighterContext } from "./contexts/PdfHighlighterContext";
|
|
17
|
+
export { PdfHighlighter, PdfLoader, TextHighlight, MonitoredHighlightContainer, AreaHighlight, FreetextHighlight, ImageHighlight, SignaturePad, DrawingCanvas, DrawingHighlight, ShapeCanvas, ShapeHighlight, useHighlightContainerContext, viewportPositionToScaled, scaledPositionToViewport, usePdfHighlighterContext, exportPdf, };
|
|
18
|
+
export type { HighlightContainerUtils, PdfHighlighterUtils, PdfHighlighterProps, TextHighlightProps, TextHighlightStyle, MonitoredHighlightContainerProps, AreaHighlightProps, AreaHighlightStyle, FreetextHighlightProps, FreetextStyle, ImageHighlightProps, SignaturePadProps, DrawingCanvasProps, DrawingHighlightProps, ShapeCanvasProps, ShapeHighlightProps, ShapeStyle, PdfLoaderProps, ExportPdfOptions, ExportableHighlight, };
|
|
19
|
+
export * from "./types";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PdfHighlighter, } from "./components/PdfHighlighter";
|
|
2
|
+
import { TextHighlight, } from "./components/TextHighlight";
|
|
3
|
+
import { MonitoredHighlightContainer, } from "./components/MonitoredHighlightContainer";
|
|
4
|
+
import { AreaHighlight, } from "./components/AreaHighlight";
|
|
5
|
+
import { FreetextHighlight, } from "./components/FreetextHighlight";
|
|
6
|
+
import { ImageHighlight, } from "./components/ImageHighlight";
|
|
7
|
+
import { SignaturePad, } from "./components/SignaturePad";
|
|
8
|
+
import { DrawingCanvas, } from "./components/DrawingCanvas";
|
|
9
|
+
import { DrawingHighlight, } from "./components/DrawingHighlight";
|
|
10
|
+
import { ShapeCanvas, } from "./components/ShapeCanvas";
|
|
11
|
+
import { ShapeHighlight, } from "./components/ShapeHighlight";
|
|
12
|
+
import { PdfLoader } from "./components/PdfLoader";
|
|
13
|
+
import { useHighlightContainerContext, } from "./contexts/HighlightContext";
|
|
14
|
+
import { viewportPositionToScaled, scaledPositionToViewport, } from "./lib/coordinates";
|
|
15
|
+
import { exportPdf, } from "./lib/export-pdf";
|
|
16
|
+
import { usePdfHighlighterContext, } from "./contexts/PdfHighlighterContext";
|
|
17
|
+
export { PdfHighlighter, PdfLoader, TextHighlight, MonitoredHighlightContainer, AreaHighlight, FreetextHighlight, ImageHighlight, SignaturePad, DrawingCanvas, DrawingHighlight, ShapeCanvas, ShapeHighlight, useHighlightContainerContext, viewportPositionToScaled, scaledPositionToViewport, usePdfHighlighterContext, exportPdf, };
|
|
18
|
+
export * from "./types";
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAEf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,aAAa,GAGd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,2BAA2B,GAE5B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EACL,aAAa,GAGd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,GAGlB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,cAAc,GAEf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,YAAY,GAEb,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,GAEd,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,gBAAgB,GAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,WAAW,GAEZ,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,cAAc,GAGf,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,SAAS,EAAkB,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAEL,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,SAAS,GAGV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAEL,wBAAwB,GACzB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EACL,cAAc,EACd,SAAS,EACT,aAAa,EACb,2BAA2B,EAC3B,aAAa,EACb,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,4BAA4B,EAC5B,wBAAwB,EACxB,wBAAwB,EACxB,wBAAwB,EACxB,SAAS,GACV,CAAC;AAwBF,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PDFViewer } from "pdfjs-dist/types/web/pdf_viewer";
|
|
2
|
+
import type { LTWHP, ViewportPosition, Scaled, ScaledPosition } from "../types";
|
|
3
|
+
import { PageViewport } from "pdfjs-dist";
|
|
4
|
+
interface WIDTH_HEIGHT {
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
/** @category Utilities */
|
|
9
|
+
export declare const viewportToScaled: (rect: LTWHP, { width, height }: WIDTH_HEIGHT) => Scaled;
|
|
10
|
+
/** @category Utilities */
|
|
11
|
+
export declare const viewportPositionToScaled: ({ boundingRect, rects }: ViewportPosition, viewer: PDFViewer) => ScaledPosition;
|
|
12
|
+
/** @category Utilities */
|
|
13
|
+
export declare const scaledToViewport: (scaled: Scaled, viewport: PageViewport, usePdfCoordinates?: boolean) => LTWHP;
|
|
14
|
+
/** @category Utilities */
|
|
15
|
+
export declare const scaledPositionToViewport: ({ boundingRect, rects, usePdfCoordinates }: ScaledPosition, viewer: PDFViewer) => ViewportPosition;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** @category Utilities */
|
|
2
|
+
export const viewportToScaled = (rect, { width, height }) => {
|
|
3
|
+
return {
|
|
4
|
+
x1: rect.left,
|
|
5
|
+
y1: rect.top,
|
|
6
|
+
x2: rect.left + rect.width,
|
|
7
|
+
y2: rect.top + rect.height,
|
|
8
|
+
width,
|
|
9
|
+
height,
|
|
10
|
+
pageNumber: rect.pageNumber,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/** @category Utilities */
|
|
14
|
+
export const viewportPositionToScaled = ({ boundingRect, rects }, viewer) => {
|
|
15
|
+
const pageNumber = boundingRect.pageNumber;
|
|
16
|
+
const viewport = viewer.getPageView(pageNumber - 1).viewport; // Account for 1 indexing of PDF documents
|
|
17
|
+
const scale = (obj) => viewportToScaled(obj, viewport);
|
|
18
|
+
return {
|
|
19
|
+
boundingRect: scale(boundingRect),
|
|
20
|
+
rects: (rects || []).map(scale),
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
const pdfToViewport = (pdf, viewport) => {
|
|
24
|
+
const [x1, y1, x2, y2] = viewport.convertToViewportRectangle([
|
|
25
|
+
pdf.x1,
|
|
26
|
+
pdf.y1,
|
|
27
|
+
pdf.x2,
|
|
28
|
+
pdf.y2,
|
|
29
|
+
]);
|
|
30
|
+
return {
|
|
31
|
+
left: Math.min(x1, x2),
|
|
32
|
+
top: Math.min(y1, y2),
|
|
33
|
+
width: Math.abs(x2 - x1),
|
|
34
|
+
height: Math.abs(y1 - y2),
|
|
35
|
+
pageNumber: pdf.pageNumber,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
/** @category Utilities */
|
|
39
|
+
export const scaledToViewport = (scaled, viewport, usePdfCoordinates = false) => {
|
|
40
|
+
const { width, height } = viewport;
|
|
41
|
+
if (usePdfCoordinates) {
|
|
42
|
+
return pdfToViewport(scaled, viewport);
|
|
43
|
+
}
|
|
44
|
+
if (scaled.x1 === undefined) {
|
|
45
|
+
throw new Error("You are using old position format, please update");
|
|
46
|
+
}
|
|
47
|
+
const x1 = (width * scaled.x1) / scaled.width;
|
|
48
|
+
const y1 = (height * scaled.y1) / scaled.height;
|
|
49
|
+
const x2 = (width * scaled.x2) / scaled.width;
|
|
50
|
+
const y2 = (height * scaled.y2) / scaled.height;
|
|
51
|
+
return {
|
|
52
|
+
left: x1,
|
|
53
|
+
top: y1,
|
|
54
|
+
width: x2 - x1,
|
|
55
|
+
height: y2 - y1,
|
|
56
|
+
pageNumber: scaled.pageNumber,
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/** @category Utilities */
|
|
60
|
+
export const scaledPositionToViewport = ({ boundingRect, rects, usePdfCoordinates }, viewer) => {
|
|
61
|
+
const pageNumber = boundingRect.pageNumber;
|
|
62
|
+
const viewport = viewer.getPageView(pageNumber - 1).viewport; // Account for 1 indexing of PDF documents
|
|
63
|
+
const scale = (obj) => scaledToViewport(obj, viewport, usePdfCoordinates);
|
|
64
|
+
return {
|
|
65
|
+
boundingRect: scale(boundingRect),
|
|
66
|
+
rects: (rects || []).map(scale),
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=coordinates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinates.js","sourceRoot":"","sources":["../../../src/lib/coordinates.ts"],"names":[],"mappings":"AASA,0BAA0B;AAC1B,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,IAAW,EACX,EAAE,KAAK,EAAE,MAAM,EAAgB,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MAAM,wBAAwB,GAAG,CACtC,EAAE,YAAY,EAAE,KAAK,EAAE,iBAAiB,EAAkB,EAC1D,MAAiB,EACC,EAAE;IACpB,MAAM,UAAU,GAAG,YAAY,CAAC,UAAU,CAAC;IAC3C,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,0CAA0C;IACxG,MAAM,KAAK,GAAG,CAAC,GAAW,EAAE,EAAE,CAC5B,gBAAgB,CAAC,GAAG,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IAErD,OAAO;QACL,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC;QACjC,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;KAChC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { ScaledPosition, ShapeData } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the PDF export function.
|
|
4
|
+
*
|
|
5
|
+
* @category Type
|
|
6
|
+
*/
|
|
7
|
+
export interface ExportPdfOptions {
|
|
8
|
+
/** Default color for text highlights. Default: "rgba(255, 226, 143, 0.5)" */
|
|
9
|
+
textHighlightColor?: string;
|
|
10
|
+
/** Default color for area highlights. Default: "rgba(255, 226, 143, 0.5)" */
|
|
11
|
+
areaHighlightColor?: string;
|
|
12
|
+
/** Default text color for freetext. Default: "#333333" */
|
|
13
|
+
defaultFreetextColor?: string;
|
|
14
|
+
/** Default background for freetext. Default: "#ffffc8" */
|
|
15
|
+
defaultFreetextBgColor?: string;
|
|
16
|
+
/** Default font size for freetext. Default: 14 */
|
|
17
|
+
defaultFreetextFontSize?: number;
|
|
18
|
+
/** Progress callback for large PDFs */
|
|
19
|
+
onProgress?: (current: number, total: number) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A highlight that can be exported to PDF.
|
|
23
|
+
*
|
|
24
|
+
* @category Type
|
|
25
|
+
*/
|
|
26
|
+
export interface ExportableHighlight {
|
|
27
|
+
id: string;
|
|
28
|
+
type?: "text" | "area" | "freetext" | "image" | "drawing" | "shape";
|
|
29
|
+
content?: {
|
|
30
|
+
text?: string;
|
|
31
|
+
image?: string;
|
|
32
|
+
shape?: ShapeData;
|
|
33
|
+
};
|
|
34
|
+
position: ScaledPosition;
|
|
35
|
+
/** Per-highlight color override (for text/area highlights) */
|
|
36
|
+
highlightColor?: string;
|
|
37
|
+
/** Style mode for text highlights: "highlight" (default), "underline", or "strikethrough" */
|
|
38
|
+
highlightStyle?: "highlight" | "underline" | "strikethrough";
|
|
39
|
+
/** Text color for freetext highlights */
|
|
40
|
+
color?: string;
|
|
41
|
+
/** Background color for freetext highlights */
|
|
42
|
+
backgroundColor?: string;
|
|
43
|
+
/** Font size for freetext highlights */
|
|
44
|
+
fontSize?: string;
|
|
45
|
+
/** Font family for freetext highlights (not used in export, Helvetica is always used) */
|
|
46
|
+
fontFamily?: string;
|
|
47
|
+
/** Shape type for shape highlights */
|
|
48
|
+
shapeType?: "rectangle" | "circle" | "arrow";
|
|
49
|
+
/** Stroke color for shape highlights */
|
|
50
|
+
strokeColor?: string;
|
|
51
|
+
/** Stroke width for shape highlights */
|
|
52
|
+
strokeWidth?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Export a PDF with annotations embedded.
|
|
56
|
+
*
|
|
57
|
+
* @param pdfSource - The source PDF as a URL string, Uint8Array, or ArrayBuffer
|
|
58
|
+
* @param highlights - Array of highlights to embed in the PDF
|
|
59
|
+
* @param options - Export options for customizing colors and behavior
|
|
60
|
+
* @returns Promise<Uint8Array> - The modified PDF as bytes
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const pdfBytes = await exportPdf(pdfUrl, highlights, {
|
|
65
|
+
* textHighlightColor: "rgba(255, 255, 0, 0.4)",
|
|
66
|
+
* onProgress: (current, total) => console.log(`${current}/${total} pages`)
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Download the file
|
|
70
|
+
* const blob = new Blob([pdfBytes], { type: "application/pdf" });
|
|
71
|
+
* const url = URL.createObjectURL(blob);
|
|
72
|
+
* const a = document.createElement("a");
|
|
73
|
+
* a.href = url;
|
|
74
|
+
* a.download = "annotated.pdf";
|
|
75
|
+
* a.click();
|
|
76
|
+
* URL.revokeObjectURL(url);
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @category Function
|
|
80
|
+
*/
|
|
81
|
+
export declare function exportPdf(pdfSource: string | Uint8Array | ArrayBuffer, highlights: ExportableHighlight[], options?: ExportPdfOptions): Promise<Uint8Array>;
|