Skip to content

创建标记密文

标记密文有以下两个步骤:

  1. 创建密文注释: 在需要标记的区域创建密文注释。这一步骤只是标记要进行应用密文更改的区域,在应用密文更改前可以设置,移动或删除这些密文注释,且不会从文档中删除内容。

  2. 应用密文更改:标记好需要彻底删除内容的区域后,应用密文更改,密文注释所在区域的内容将被不可逆地删除。

通过这两个步骤,您可以创建密文注释并应用标记密文,彻底删除文档中的敏感数据。

创建密文注释

您可以通过 CPDFRedactAnnotation 类来创建密文注释。使用 quadrilateralPointsbounds方法设置应该被密文注释覆盖的区域。

此外, 在此阶段还可以对密文的外观进行自定义设置。需要注意,一旦密文注释被应用,其外观将无法更改,因为密文注释将在应用后变为不可编辑、不可修改的静态内容,而非可交互的密文注释。

以下是创建密文注释的示例代码:

swift
let url = URL(fileURLWithPath: "File Path")
let document = CPDFDocument(url: url)

let page = document?.page(at: 0)
let redact = CPDFRedactAnnotation(document: document)
redact?.bounds = CGRect(x: 0, y: 0, width: 50, height: 50)
redact?.setOverlayText("REDACTED")
redact?.setFont(UIFont.systemFont(ofSize: 12))
redact?.setFontColor(UIColor.red)
redact?.setAlignment(.left)
redact?.setInteriorColor(.black)
redact?.setBorderColor(.yellow)
page?.addAnnotation(redact)
objective-c
NSURL *url = [NSURL fileURLWithPath:pdfPath];
CPDFDocument *document = [[CPDFDocument alloc] initWithURL:url];
CPDFPage *page = [document pageAtIndex:0];

CPDFRedactAnnotation *redact = [[CPDFRedactAnnotation alloc] initWithDocument:document];
redact.bounds = CGRectMake(0, 0, 50, 50);
redact.overlayText = @"REDACTED";
redact.font = [UIFont systemFontOfSize:12];
redact.fontColor = [UIColor redColor];
redact.alignment = NSTextAlignmentLeft;
redact.interiorColor = [UIColor blackColor];
redact.borderColor = [UIColor yellowColor];
[page addAnnotation:redact];

应用密文更改

ComPDFKit SDK 确保如果文本、图像或矢量图形包含在密文注释所标记的区域中,则该部分的图像或路径数据将被彻底删除,且无法还原。

以下是应用密文更改的示例代码:

swift
redact?.applyRedaction()
objective-c
[redact applyRedaction];