Watermarker

Watermarker(string)

初始化一个新的实例Watermarker具有指定文档路径的类.

public Watermarker(string filePath)
范围 类型 描述
filePath String 从中加载文档的文件路径。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息: 载入文件.

例子

加载和保存任何支持格式的内容。

// 从文件中加载内容。
using (Watermarker watermarker = new Watermarker("D:\\input.pdf"))
{
    // 使用 Watermarker 类的方法来添加、搜索或删除水印。

    // 保存文档。
    watermarker.Save("D:\\output.pdf");
}

也可以看看


Watermarker(string, LoadOptions)

初始化一个新的实例Watermarker具有指定 文档路径和加载选项的类。

public Watermarker(string filePath, LoadOptions options)
范围 类型 描述
filePath String 从中加载文档的文件路径。
options LoadOptions 加载文档时要使用的其他选项。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息: 载入文件.

例子

使用密码加载加密的 PDF 文档。

PdfLoadOptions loadOptions = new PdfLoadOptions();
loadOptions.Password = "123";
using (Watermarker watermarker = new Watermarker(@"C:\Documents\test.pdf", loadOptions))
{
    // ...
}

也可以看看


Watermarker(string, WatermarkerSettings)

初始化一个新的实例Watermarker具有指定 文档路径和设置的类。

public Watermarker(string filePath, WatermarkerSettings settings)
范围 类型 描述
filePath String 从中加载文档的文件路径。
settings WatermarkerSettings 处理加载的文档时要使用的其他设置。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息: 载入文件.

例子

全局设置可搜索对象(对于之后将加载的所有文档)。

WatermarkerSettings settings = new WatermarkerSettings();
settings.SearchableObjects = new SearchableObjects
{
    WordProcessingSearchableObjects = WordProcessingSearchableObjects.Hyperlinks
                                    | WordProcessingSearchableObjects.Text,
    SpreadsheetSearchableObjects = SpreadsheetSearchableObjects.HeadersFooters,
    PresentationSearchableObjects = PresentationSearchableObjects.SlidesBackgrounds
                                  | PresentationSearchableObjects.Shapes,
    DiagramSearchableObjects = DiagramSearchableObjects.None,
    PdfSearchableObjects = PdfSearchableObjects.All
};

foreach (string file in Directory.GetFiles(@"D:\files"))
{
    using (Watermarker watermarker = new Watermarker(file, settings))
    {
        PossibleWatermarkCollection watermarks = watermarker.Search();

        // 处理找到的水印的代码在这里。
    }
}

也可以看看


Watermarker(string, LoadOptions, WatermarkerSettings)

初始化一个新的实例Watermarker具有指定 文档路径、加载选项和设置的类。

public Watermarker(string filePath, LoadOptions options, WatermarkerSettings settings)
范围 类型 描述
filePath String 从中加载文档的文件路径。
options LoadOptions 加载文档时要使用的其他选项。
settings WatermarkerSettings 处理加载的文档时要使用的其他设置。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息: 载入文件.

例子

在电子邮件正文/主题中查找特定文本片段。

WatermarkerSettings settings = new WatermarkerSettings();
settings.SearchableObjects = new SearchableObjects
{
    EmailSearchableObjects = EmailSearchableObjects.Subject
                           | EmailSearchableObjects.HtmlBody
                           | EmailSearchableObjects.PlainTextBody
};
EmailLoadOptions loadOptions = new EmailLoadOptions();
using (Watermarker watermarker = new Watermarker(@"D:\test.msg", loadOptions, settings))
{
    SearchCriteria criteria = new TextSearchCriteria("test", false);
    // 注意,仅当您将 TextSearchCriteria 实例传递给 Search 方法时才会执行搜索
    PossibleWatermarkCollection watermarks = watermarker.Search(criteria);
    // 删除找到的文本片段
    watermarks.Clear();
    // 保存更改
    watermarker.Save();
}

也可以看看


Watermarker(Stream)

初始化一个新的实例Watermarker具有指定流的类。

public Watermarker(Stream document)
范围 类型 描述
document Stream 从中加载文档的流。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息 载入文件.

例子

加载和保存任何支持格式的文档。

// 从流中加载内容。
using (FileStream inputStream = File.Open("D:\\input.pdf", FileMode.Open))
using (FileStream outputStream = File.Open("D:\\output.pdf", FileMode.Create))
using (Watermarker watermarker = new Watermarker(inputStream))
{
    // 使用 Watermarker 类的方法来添加、搜索或删除水印。

    // 保存更改。
    watermarker.Save(outputStream);
}

也可以看看


Watermarker(Stream, LoadOptions)

初始化一个新的实例Watermarker具有指定 stream 和加载选项的类。

public Watermarker(Stream document, LoadOptions options)
范围 类型 描述
document Stream 从中加载文档的流。
options LoadOptions 加载文档时要使用的其他选项。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息 载入文件.

例子

使用密码加载加密的 PDF 文档

PdfLoadOptions loadOptions = new PdfLoadOptions();
loadOptions.Password = "123";
using (FileStream fileStream = File.Open(@"C:\Documents\test.pdf", FileMode.Open))
using (Watermarker watermarker = new Watermarker(fileStream, loadOptions))
{
    // ...
}

也可以看看


Watermarker(Stream, WatermarkerSettings)

初始化一个新的实例Watermarker具有指定 stream 和 settings. 的类

public Watermarker(Stream document, WatermarkerSettings settings)
范围 类型 描述
document Stream 从中加载文档的流。
settings WatermarkerSettings 处理加载的文档时要使用的其他设置。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息 载入文件.

例子

全局设置可搜索对象(对于之后将加载的所有文档)。

WatermarkerSettings settings = new WatermarkerSettings();
settings.SearchableObjects = new SearchableObjects
{
    WordProcessingSearchableObjects = WordProcessingSearchableObjects.Hyperlinks
                                    | WordProcessingSearchableObjects.Text,
    SpreadsheetSearchableObjects = SpreadsheetSearchableObjects.HeadersFooters,
    PresentationSearchableObjects = PresentationSearchableObjects.SlidesBackgrounds
                                  | PresentationSearchableObjects.Shapes,
    DiagramSearchableObjects = DiagramSearchableObjects.None,
    PdfSearchableObjects = PdfSearchableObjects.All
};

foreach (string file in Directory.GetFiles(@"D:\files"))
{
    using (FileStream fileStream = File.Open(file, FileMode.Open))
    using (Watermarker watermarker = new Watermarker(fileStream, settings))
    {
        PossibleWatermarkCollection watermarks = watermarker.Search();

        // 处理找到的水印的代码在这里。
    }
}

也可以看看


Watermarker(Stream, LoadOptions, WatermarkerSettings)

初始化一个新的实例Watermarker具有指定流的类, 加载选项和设置。

public Watermarker(Stream document, LoadOptions options, WatermarkerSettings settings)
范围 类型 描述
document Stream 从中加载文档的流。
options LoadOptions 加载文档时要使用的其他选项。
settings WatermarkerSettings 处理加载的文档时要使用的其他设置。

例外

例外 (健康)状况
UnsupportedFileTypeException 不支持提供的文档类型。
InvalidPasswordException 提供的密码不正确。

评论

了解有关加载文档的更多信息 载入文件.

例子

在电子邮件正文/主题中查找特定文本片段。

WatermarkerSettings settings = new WatermarkerSettings();
settings.SearchableObjects = new SearchableObjects
{
    EmailSearchableObjects = EmailSearchableObjects.Subject
                           | EmailSearchableObjects.HtmlBody
                           | EmailSearchableObjects.PlainTextBody
};
EmailLoadOptions loadOptions = new EmailLoadOptions();
using (FileStream fileStream = File.Open(@"D:\test.msg", FileMode.Open))
using (Watermarker watermarker = new Watermarker(fileStream, loadOptions, settings))
{
    SearchCriteria criteria = new TextSearchCriteria("test", false);
    // 注意,仅当您将 TextSearchCriteria 实例传递给 Search 方法时才会执行搜索
    PossibleWatermarkCollection watermarks = watermarker.Search(criteria);
    // 删除找到的文本片段
    watermarks.Clear();
    // 保存更改
    watermarker.Save();
}

也可以看看