1. 首页
  2. Foxit PDF SDK(Web版)
  3. 如何添加Stamp及stamp自定义

如何添加Stamp及stamp自定义

WebPDF SDK提供了丰富的stamp功能,用户可以通过接口添加stamp,配置自定义的stamp等。

1.添加单个stamp annotation到页面中
var pdfViewer = await pdfui.getPDFViewer();
var pdfDoc = pdfViewer.getCurrentPDFDoc();
var page = await pdfDoc.getPageByIndex(0);
var annotJson = {
 type: 'stamp',
 rect: {left:50,right:100,top:400,bottom:350},
 iconInfo: {
 annotType:PDFViewCtrl.PDF.annots.constant.Annot_Type.stamp,
 category:"category",
 name:"customStampName",
 fileType:"png",
 url:'http://localhost:8750/test.png' // stamp图片url及图片类型配置
 }
};
 
await page.addAnnot(annotJson);


2.添加自定义图标到stamp列表
var pdfViewer = await pdfui.getPDFViewer();
pdfViewer.addAnnotationIcon({
 fileType:"png",
 url:"http://localhost:8750/test.png",// or "blob:http://xxxxx"
 annotType:'stamp',
 category:'catagory',
 name:'customStampName',
 width:100,
 height:45,
});

效果如图:

3.完全自定义stamp列表
var initIcons = {
 MyCategory1: {
 StampName1: {
 fileType: "png",
 url: "http://localhost:8750/test.png"
 }
 }
 };
pdfui.getPDFViewer().then(function(pdfViewer) {
 pdfViewer.initAnnotationIcons({ stamp: initIcons });
});

该操作会完全去除默认的stamp列表,依据新配置构建新stamp列表,效果如图:

以上为常用的三个操作,其他接口的介绍可以参考developerguide中的介绍,链接:https://webviewer-demo.foxitsoftware.cn/docs/developer-guide/main/features/stamp.html#default-stamp-list

更新于 2021年1月25日

这篇文章有用吗?

相关文章