Apply

Apply(Redaction)

对文档应用密文。

public RedactorChangeLog Apply(Redaction redaction)
范围 类型 描述
redaction Redaction 的实例Redaction申请

返回值

本例中的成功或失败以及错误消息

例子

以下示例演示了对文档应用单个密文。

using (Redactor redactor = new Redactor(@"D:\\test.docx"))
{
   RedactorChangeLog result = redactor.Apply(new RegexRedaction(LookupStrings.SSNRegexPattern, new ReplacementOptions("[ssn]")));
   if (result.Status != RedactionStatus.Failed)
   {
      redactor.Save();
   };
}

也可以看看


Apply(Redaction[])

对文档应用一组修订。

public RedactorChangeLog Apply(Redaction[] redactions)
范围 类型 描述
redactions Redaction[] 要应用的一系列编辑

返回值

本例中的成功或失败以及错误消息

例子

以下示例演示了对文档应用密文列表。

using (Redactor redactor = new Redactor(@"D:\\test.docx"))
{
   var redactionList = new Redaction[] 
   {
      new ExactPhraseRedaction(LookupStrings.ClientName, new ReplacementOptions("[client]")),
      new ExactPhraseRedaction(LookupStrings.ClientAddress, new ReplacementOptions(System.Drawing.Color.Red)),
      new RegexRedaction(LookupStrings.SSNRegexPattern, new ReplacementOptions("[ssn]")),
      new RegexRedaction(LookupStrings.BankCardRegexPattern, new ReplacementOptions(System.Drawing.Color.Blue)),
      // ... 其他编辑
      new DeleteAnnotationRedaction("(?im:(use|show|describe))"),
      new EraseMetadataRedaction(MetadataFilter.Author),
      new MetadataSearchRedaction(LookupStrings.CompanyName, "--company--") 
   }; 
   RedactorChangeLog result = redactor.Apply(redactionList);
   // false,如果至少一个编辑失败
   if (result.Status != RedactionStatus.Failed)
   {
      redactor.Save();
   };
}

也可以看看


Apply(RedactionPolicy)

将编辑策略应用于文档。

public RedactorChangeLog Apply(RedactionPolicy policy)
范围 类型 描述
policy RedactionPolicy 编辑政策

返回值

本例中的成功或失败以及错误消息

例子

以下示例演示如何将编辑策略应用于给定入站文件夹中的所有文件,并保存到出站文件夹之一 - 用于成功更新的文件和失败的文件。

RedactionPolicy policy = RedactionPolicy.Load("RedactionPolicy.xml");
foreach (var fileEntry in Directory.GetFileNames("C:\\Inbound")) 
{
     using (Redactor redactor = new Redactor(Path.Combine("C:\\Inbound\\", fileEntry)))
     {
    	     RedactorChangeLog result = redactor.Apply(policy);
    	     String resultFolder = result.Status != RedactionStatus.Failed ? "C:\\Outbound\\Done\\" : "C:\\Outbound\\Failed\\";
    	     using (Stream fileStream = File.Open(Path.Combine(resultFolder, fileEntry), FileMode.Open, FileAccess.ReadWrite))
   	     {
               redactor.Save(fileStream, new RasterizationOptions() { Enabled = false });
   	     }        
     }
}   

也可以看看