图章注释
图章注释(Stamp)用于在 PDF 页面上添加类似印章的标记,可使用 PDF 规范定义的标准图章,也可使用自定义的位图或图片作为图章内容。
标准图章
PDF 规范定义了一组标准图章图标,通过 setIconName: 设置对应名称即可使用:
| 图标名称 | 说明 |
|---|---|
@"Approved" | 已批准 |
@"AsIs" | 按原样 |
@"Confidential" | 机密 |
@"Departmental" | 部门内部 |
@"Draft" | 草稿 |
@"Experimental" | 试验性 |
@"Expired" | 已过期 |
@"Final" | 最终版 |
@"ForComment" | 供评审 |
@"ForPublicRelease" | 公开发布 |
@"NotApproved" | 未批准 |
@"NotForPublicRelease" | 非公开 |
@"Sold" | 已售 |
@"TopSecret" | 绝密 |
示例:添加标准图章
objc
#import <FoxitRDK/FSPDFObjC.h>
FSPDFPage *page = [doc getPage:0];
FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:600 right1:280 top1:660];
FSAnnot *annot = [page addAnnot:FSAnnotStamp rect:rect];
FSStamp *stamp = [[FSStamp alloc] initWithAnnot:annot];
[stamp setIconName:@"Approved"];
[stamp setBorderColor:0xFF009900];
[stamp setContent:@"已批准"];
[stamp resetAppearanceStream];
自定义位图图章
使用 setBitmap: 方法可将 FSBitmap 对象设置为图章内容,适用于需要自定义图片作为印章的场景。
objc
#import <FoxitRDK/FSPDFObjC.h>
FSPDFPage *page = [doc getPage:0];
FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:400 right1:300 top1:500];
FSAnnot *annot = [page addAnnot:FSAnnotStamp rect:rect];
FSStamp *stamp = [[FSStamp alloc] initWithAnnot:annot];
// 从 UIImage 创建 FSBitmap
UIImage *image = [UIImage imageNamed:@"my_stamp"];
FSBitmap *bitmap = [FSBitmap createFromUIImage:image];
[stamp setBitmap:bitmap];
[stamp resetAppearanceStream];
使用 Image 对象设置图章
setImage:frame:compress_type: 方法支持通过 SDK 的 FSImage 对象设置图章,可指定帧索引和压缩方式:
objc
#import <FoxitRDK/FSPDFObjC.h>
FSPDFPage *page = [doc getPage:0];
FSRectF *rect = [[FSRectF alloc] initWithLeft1:100 bottom1:400 right1:300 top1:500];
FSAnnot *annot = [page addAnnot:FSAnnotStamp rect:rect];
FSStamp *stamp = [[FSStamp alloc] initWithAnnot:annot];
FSImage *image = [[FSImage alloc] initWithPath:@"path/to/stamp_image.jpg"];
[stamp setImage:image frame:0 compress_type:0]; // 帧索引 0,默认压缩
[stamp resetAppearanceStream];
图章旋转
图章注释支持角度旋转:
objc
// 获取当前旋转角度
int rotation = [stamp getRotation];
// 设置绝对旋转角度(单位:度)
[stamp setRotation:45];
// 在当前角度基础上增量旋转
[stamp rotate:90];
[stamp resetAppearanceStream];
核心方法汇总
| 方法 | 说明 |
|---|---|
getIconName / setIconName: | 获取/设置标准图章图标名称 |
setBitmap: | 使用 FSBitmap 设置自定义图章 |
setImage:frame:compress_type: | 使用 FSImage 对象设置图章(支持帧索引和压缩参数) |
getRotation / setRotation: | 获取/设置旋转角度 |
rotate: | 增量旋转(在当前角度上叠加) |