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;