.NET版文档管理利器Aspose.Words v20.5发布!用例解析5大新功能!

五一小长假刚过,大家又进入了忙碌的工作中,.NET版Aspose.Words也为大家带来了5月的新版本!Aspose.Words for .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。

主要特点如下:

  • 提供显示/隐藏语法和拼写错误的功能。
  • 引入了可在文档内部使用水印的新帮助程序类。
  • 添加了为OOXML文档设置压缩级别的功能。

>>你可以点击这里下载Aspose.Words for .NET v20.5测试体验

.NET版文档管理利器Aspose.Words v20.5发布!用例解析5大新功能!

具体更新内容

key 概述 类别
WORDSNET-10403 向“仅隐藏本文档中的拼写错误”添加功能 新功能
WORDSNET-4879 添加辅助方法以将水印插入标头 新功能
WORDSNET-10404 将功能添加到“仅隐藏本文档中的语法错误” 新功能
WORDSNET-20094 添加和选项以删除重复样式到Document.Cleanup功能 新功能
WORDSNET-20169 Aspose.Words为DOCX写入错误的字节 新功能

公共API更改

①添加了新的公共属性OoxmlSaveOptions.CompressionLevel,指定压缩级别“SuperFast”以保存文档

/// <summary>

/// Specifies the compression level used to save document.

/// </summary>

publicCompressionLevel CompressionLevel

用例:说明如何指定压缩级别“ SuperFast”(由Microsoft Word使用)以保存文档。

Document doc = new Document("in.docx");
OoxmlSaveOptions so = new OoxmlSaveOptions(SaveFormat.Docx);
so.CompressionLevel = CompressionLevel.SuperFast;
doc.Save("out.docx", so);

②添加了新的公共方法FontInfo.GetEmbeddedFontAsOpenType(),将Embedded OpenType格式的嵌入字体转换为OpenType

/// <summary>

/// Gets an embedded font file in OpenType format. Fonts in Embedded OpenType format are converted to OpenType.

/// </summary>

/// <param name="style">Specifies the font style to retrieve.</param>

/// <returns>Returns <c>null</c> if the specified font is not embedded.</returns>

publicbyte[] GetEmbeddedFontAsOpenType(EmbeddedFontStyle style)

③引入了可在文档内部使用水印的新帮助程序类

新属性“水印”已添加到Document类。

/// <summary>

/// Provides access to the document watermark.

/// </summary>

publicWatermark Watermark {get; }

新的Watermark类允许从文档中添加/删除水印。可以从文本或图像创建水印。

/// <summary>

/// Represents class to work with document watermark.

/// </summary>

publicsealedclassWatermark

{

    /// <summary>

    /// Adds Text watermark into the document.

    /// </summary>

    /// <param name="text">Text that displays as a watermark.</param>

    /// <remarks>

    /// The text length should be in the range from 1 to 200 inclusive.

    /// The text cannot be null or consist only of whitespaces.

    /// </remarks>

    /// <exception cref="ArgumentOutOfRangeException">

    /// Throws when the text length is out of range or the text consists only of whitespaces.

    /// </exception>

    /// <exception cref="ArgumentNullException">

    /// Throws when the text is null.

    /// </exception>

    publicvoidSetText(stringtext)

  

    /// <summary>

    /// Adds Text watermark into the document.

    /// </summary>

    /// <param name="text">Text that displays as a watermark.</param>

    /// <param name="options">Defines additional options for the text watermark.</param>

    /// <remarks>

    /// The text length should be in the range from 1 to 200 inclusive.

    /// The text cannot be null or consist only of whitespaces.

    /// </remarks>

    /// <exception cref="ArgumentOutOfRangeException">

    /// Throws when the text length is out of range or the text consists only of whitespaces.

    /// </exception>

    /// <exception cref="ArgumentNullException">

    /// Throws when the text is null.

    /// </exception>

    /// <remarks>If options is null, the watermark will be set with default properties.</remarks>

    publicvoidSetText(stringtext, TextWatermarkOptions options)

  

    /// <summary>

    /// Adds Image watermark into the document.

    /// </summary>

    /// <param name="image">Image that displays as a watermark.</param>

    /// <exception cref="ArgumentNullException">

    /// Throws when the image is null.

    /// </exception>

    publicvoidSetImage(Image image)

  

    /// <summary>

    /// Adds Image watermark into the document.

    /// </summary>

    /// <param name="image">Image that displays as a watermark.</param>

    /// <param name="options">Defines additional options for the image watermark.</param>

    /// <exception cref="ArgumentNullException">

    /// Throws when the image is null.

    /// </exception>

    /// <remarks>If options is null, the watermark will be set with default properties.</remarks>

    publicvoidSetImage(Image image, ImageWatermarkOptions options)

  

    /// <summary>

    /// Removes watermark.

    /// </summary>

    publicvoidRemove()

  

    /// <summary>

    /// Returns watermark type.

    /// </summary>

    publicWatermarkType Type {get; }

}

提供了新的枚举,以确定文档内的水印类型。

/// <summary>

/// Specifies the watermark type.

/// </summary>

publicenumWatermarkType

{

    /// <summary>

    /// Indicates that the text will be used as a watermark.

    /// <p>Such a watermark corresponds to a WordArt object.</p>

    /// </summary>

    Text,

  

    /// <summary>

    /// Indicates that the image will be used as a watermark.

    /// <p>Such a watermark corresponds to a shape with image.</p>

    /// </summary>

    Image,

  

    /// <summary>

    /// Indicates watermark is no set.

    /// </summary>

    None

}

提供了新的枚举,可将文本水印设置为对角或水平布局。

/// <summary>

/// Defines layout of the watermark relative to the watermark center.

/// </summary>

publicenumWatermarkLayout

{

    /// <summary>

    /// Horizontal watermark layout. Corresponds to 0 degrees of rotation.

    /// </summary>

    Horizontal = 0,

  

    /// <summary>

    /// Diagonal watermark layout. Corresponds to 315 degrees of rotation.

    /// </summary>

    Diagonal = 315

}

对于图像水印:

/// <summary>

/// Contains options that can be specified when adding a watermark with image.

/// </summary>

publicclassImageWatermarkOptions

{

    /// <summary>

    /// Gets or sets the scale factor expressed as a fraction of the image. The default value is 0 - auto.

    /// </summary>

    /// <remarks>

    /// <p>Valid values range from 0 to 65.5 inclusive.</p>

    /// <p>Auto scale means that the watermark will be scaled to its max width and max height relative to

    /// the page margins.</p>

    /// </remarks>

    /// <exception cref="ArgumentOutOfRangeException">

    /// Throws when argument was out of the range of valid values.

    /// </exception>

    publicdoubleScale {get;set; }

  

    /// <summary>

    /// Gets or sets a boolean value which is responsible for washout effect of the watermark.

    /// The default value is <code>true</code>.

    /// </summary>

    publicboolIsWashout {get;set; }

}

用例1:添加带有特定选项的文本水印

Document doc = new Document(pathFile);
  
TextWatermarkOptions options = new TextWatermarkOptions()
{
    FontFamily = "Arial",
    FontSize = 36,
    Color = Color.Black,
    Layout = WatermarkLayout.Horizontal,
    IsSemitrasparent = false
};
  
doc.Watermark.SetText("Test", options);

用例2:使用特定选项添加图像水印

Document doc = new Document(pathFile);
  
ImageWatermarkOptions options = new ImageWatermarkOptions()
{
    Scale = 5,
    IsWashout = false
};
  
doc.Watermark.SetImage(Image.FromFile(filePath), options);

用例3:从文档中删除水印

Document doc = new Document(pathFile);
if (doc.Watermark.Type == WatermarkType.Text)
    doc.Watermark.Remove();

④添加了新的公共属性Document.ShowGrammaticalErrors,显示语法错误

/// <summary>

/// Specifies whether to display grammar errors in this document.

/// </summary>

publicboolShowGrammaticalErrors

用例:说明如何显示语法错误

Document doc = new Document("in.doc");
doc.ShowGrammaticalErrors = true;
doc.Save("out.doc");

⑤添加了新的公共属性Document.ShowSpellingErrors,显示拼写错误

用例:说明如何显示拼写错误

Document doc = new Document("in.doc");
doc.ShowSpellingErrors = true;
doc.Save("out.doc");

如果您有任何疑问或需求,请随时加入Aspose技术交流群(642018183),我们很高兴为您提供查询和咨询。