81 lines
2.0 KiB
TypeScript
81 lines
2.0 KiB
TypeScript
import type { PlimiPlugin } from "../../core/plugins/plugin-types";
|
|
import { runPdfWatermark } from "./run";
|
|
import { COLOR_PRESETS, MAX_WATERMARK_CHARS } from "./watermark";
|
|
import PdfWorker from "./worker?worker";
|
|
|
|
export interface PdfWatermarkOptions {
|
|
text: string;
|
|
orientation: "horizontal" | "vertical" | "diagonal";
|
|
opacity: number;
|
|
color: string;
|
|
}
|
|
|
|
export const pdfWatermarkPlugin: PlimiPlugin<PdfWatermarkOptions> = {
|
|
manifest: {
|
|
id: "pdf-watermark",
|
|
name: "PDF Watermark",
|
|
description:
|
|
"Stamp custom text over every page of a PDF, entirely in your browser. The text auto-sizes to fit each page.",
|
|
category: "pdf",
|
|
version: "1.0.0",
|
|
tags: ["pdf", "watermark", "stamp", "text"],
|
|
input: {
|
|
type: "files",
|
|
accept: ["application/pdf"],
|
|
multiple: false,
|
|
},
|
|
output: { type: "files" },
|
|
offlineReady: true,
|
|
},
|
|
|
|
optionsSchema: {
|
|
fields: [
|
|
{
|
|
type: "text",
|
|
key: "text",
|
|
label: `Watermark Text (max ${MAX_WATERMARK_CHARS} chars)`,
|
|
defaultValue: "CONFIDENTIAL",
|
|
placeholder: "e.g. CONFIDENTIAL",
|
|
},
|
|
{
|
|
type: "select",
|
|
key: "orientation",
|
|
label: "Orientation",
|
|
defaultValue: "diagonal",
|
|
options: [
|
|
{ label: "Diagonal", value: "diagonal" },
|
|
{ label: "Horizontal", value: "horizontal" },
|
|
{ label: "Vertical", value: "vertical" },
|
|
],
|
|
},
|
|
{
|
|
type: "slider",
|
|
key: "opacity",
|
|
label: "Opacity (%)",
|
|
defaultValue: 30,
|
|
min: 5,
|
|
max: 100,
|
|
step: 5,
|
|
},
|
|
{
|
|
type: "select",
|
|
key: "color",
|
|
label: "Color",
|
|
defaultValue: "light-grey",
|
|
options: Object.entries(COLOR_PRESETS).map(([value, { label }]) => ({
|
|
label,
|
|
value,
|
|
})),
|
|
},
|
|
],
|
|
},
|
|
|
|
capabilities: {
|
|
cancelable: true,
|
|
worker: true,
|
|
},
|
|
|
|
run: runPdfWatermark,
|
|
worker: () => new PdfWorker(),
|
|
};
|