summaryrefslogtreecommitdiff
path: root/components/file-manager/creaetWaterMarks.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'components/file-manager/creaetWaterMarks.tsx')
-rw-r--r--components/file-manager/creaetWaterMarks.tsx71
1 files changed, 71 insertions, 0 deletions
diff --git a/components/file-manager/creaetWaterMarks.tsx b/components/file-manager/creaetWaterMarks.tsx
new file mode 100644
index 00000000..524b18ee
--- /dev/null
+++ b/components/file-manager/creaetWaterMarks.tsx
@@ -0,0 +1,71 @@
+export const createCustomWatermark: CreateCustomWatermark = ({
+ text,
+ fontSize,
+ color,
+ opacity,
+ rotation = -45,
+ fontFamily = "Helvetica",
+ }) => {
+ return (ctx, pageNumber, pageWidth, pageHeight) => {
+ if (!text) return;
+
+ const lines = text.split("\n"); // 줄바꿈 기준 멀치 처리
+
+ ctx.save();
+ ctx.translate(pageWidth / 2, pageHeight / 2);
+ ctx.rotate((rotation * Math.PI) / 180);
+ ctx.fillStyle = color;
+ ctx.textAlign = "center";
+ ctx.textBaseline = "middle";
+
+ const lineHeights = lines.map((s) => {
+ return fontSize;
+ });
+
+ const totalHeight =
+ lineHeights.reduce((sum, h) => sum + h, 0) - lineHeights[0]; // 첫 줄은 기준선 0
+
+ let yOffset = -totalHeight / 2;
+
+ lines.forEach((line, i) => {
+ ctx.font = `900 ${fontSize}px ${fontFamily}`;
+ ctx.fillText(line, 0, yOffset);
+ yOffset += lineHeights[i];
+ });
+
+ ctx.restore();
+ };
+ };
+
+
+ import { Core, WebViewerInstance } from "@pdftron/webviewer";
+
+export interface WaterMarkOption {
+ fontSize: number;
+ color: string;
+ opacity: number;
+ rotation: number;
+ fontFamily: string;
+ split: boolean;
+ shipNameCheck: boolean;
+ shipName: string;
+ ownerNameCheck: boolean;
+ ownerName: string;
+ classNameCheck: boolean;
+ className: string;
+ classList: string[];
+ customCheck: boolean;
+ text: string;
+}
+
+type CreateCustomWatermark = ({
+ text,
+ fontSize,
+ color,
+ opacity,
+ rotation,
+ fontFamily,
+}: Pick<
+ WaterMarkOption,
+ "text" | "fontSize" | "color" | "opacity" | "rotation" | "fontFamily"
+>) => Core.DocumentViewer.CustomWatermarkCallback; \ No newline at end of file