PDF 生成模板编辑器
开源可视化 PDF 生成引擎,支持自定义模板,并提供面向开发者的 API,灵活构建文档生成流程。
使用 updateWatermark() 根据索引更新已有水印。先获取原水印,再通过 copyWatermark() 只修改需要变更的属性。
import { copyWatermark } from "@compdfkit_pdf_sdk/react_native";
const watermark = await pdfReaderRef.current?._pdfDocument.getWatermark(0);
if (watermark) {
const success = await pdfReaderRef.current?._pdfDocument.updateWatermark(
watermark.index,
copyWatermark(watermark, {
textContent: "Updated Confidential",
textColor: "#0066FF",
fontSize: 36,
opacity: 0.75,
})
);
console.log("Update watermark result:", success);
}更新图片水印时,只有在需要替换图片内容时才传入新的 imagePath。如果 imagePath 为空,SDK 会保留原图片,只更新其他属性。
const watermark = await pdfReaderRef.current?._pdfDocument.getWatermark(0);
if (watermark?.type === "image") {
await pdfReaderRef.current?._pdfDocument.updateWatermark(
watermark.index,
copyWatermark(watermark, {
opacity: 0.65,
scale: 0.5,
rotation: 30,
})
);
}