Java版Aspose.Words 最新版v20.4用例解析!快速get文档格式处理新技能

Aspose.Words for Java的最新版v20.4引入了OpenGL渲染支持,更新了日志系统,增强了图表数据标签和系列API。新增特性包括亚洲段落间距和缩进的调整,PDF图像插值选项,3D形状渲染模式等。此版本旨在提升文档处理的效率和质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Aspose.Words for Java是功能丰富的Word处理API,允许开发人员在不使用Microsoft Word的情况下嵌入在自己的Java应用程序中生成,修改,转换,呈现和打印文档的功能。

很高兴与大家分享Java平台的Aspose.Words迎来了2020.4月更新,该版本具有.NET版同样的7大新升级体验,包括日志记录系统已更新和改进,图表数据标签和系列的扩展API等等。接下来,我们一起来聊聊新版本的新功能。(点击下载

主要特点

  • Java平台现在支持OpenGL渲染(使用外部库)。
  • 日志记录系统已更新和改进。
  • Sonarqube测试通过。
  • 提供了更改亚洲段落间距和缩进的功能。
  • 为PDF渲染添加了图像插值选项(新的公共属性PdfSaveOptions.InterpolateImages)。
  • 添加了新的模式3D形状渲染。
  • 图表数据标签和系列的扩展API。

具体更新内容

key概述类别
WORDSJava-2264使用外部库自动移植OpenGL渲染。新功能
WORDSNET-15697提供更改受密码保护的VBA代码(更改字符串)的功能新功能
WORDSNET-20043公布公开的CompareLevel(粒度)选项新功能
WORDSNET-20001提供API以获取针对中文特定段落格式的设置Word新功能
WORDSNET-19913Range.Replace替换新功能
WORDSNET-19996添加用于PDF渲染的图像插值选项新功能
WORDSNET-19873添加功能以设置/获取浮动表的位置(HorizontalAnchor和VerticalAnchor)新功能
WORDSNET-20080支持带有复合重音符号的OTF(CFF)字体子集新功能
WORDSNET-20146实施ISO 29500特定BorderArt样式的渲染新功能
WORDSNET-19747添加功能以设置/获取段落属性“定义文档网格时对齐网格”新功能
WORDSNET-10548锚固件靠近紧紧包裹的浮子时,浮子位置不正确增强功能
WORDSNET-20042检查RTF格式是否支持在块/单元/行级别放置注释增强功能

增加了更改亚洲段落间距和缩进的功能

添加了以下ParagraphFormat属性:

///

/// Gets or sets the left indent value (in characters) for the specified paragraphs.

///

publicintParagraphFormat.CharacterUnitLeftIndent {get;set; }

 

///

/// Gets or sets the right indent value (in characters) for the specified paragraphs.

///

publicintParagraphFormat.CharacterUnitRightIndent {get;set; }

 

///

/// Gets or sets the value (in characters) for the first-line or hanging indent.

///

Use positive values to set the first-line indent, and negative values to set the hanging indent.

 

///

publicintParagraphFormat.CharacterUnitFirstLineIndent {get;set; }

 

///

/// Gets or sets the amount of spacing (in gridlines) before the paragraphs.

///

publicintParagraphFormat.LineUnitBefore {get;set; }

 

///

/// Gets or sets the amount of spacing (in gridlines) after the paragraphs.

///

publicintParagraphFormat.LineUnitAfter {get;set; }

用例(.NET)

请注意,设置单位的缩进和间距将更新适当的公共缩进或间距属性。例如,设置ParagraphFormat.CharacterUnitLeftIndent将更新ParagraphFormat.LeftIndent。

Document doc = new Document()
ParagraphFormat format = doc.FirstSection.Body.FirstParagraph.ParagraphFormat;
  
format.CharacterUnitLeftIndent = 10;       // ParagraphFormat.LeftIndent will be updated
  
format.CharacterUnitRightIndent = 10;      // ParagraphFormat.RightIndent will be updated
  
format.CharacterUnitFirstLineIndent = 20;  // ParagraphFormat.FirstLineIndent will be updated
  
format.LineUnitBefore = 5;                 // ParagraphFormat.SpaceBefore will be updated
  
format.LineUnitAfter= 10;                  // ParagraphFormat.SpaceAfter will be updated

添加了新模式的3D形状渲染

添加了新的公共属性SaveOptions.Dml3DEffectsRenderingMode :

/// <summary>

/// Gets or sets a value determining how 3D effects are rendered.

/// </summary>

/// <remarks>

/// The default value is <see cref="Saving.Dml3DEffectsRenderingMode.Basic"/>.

/// </remarks>

publicDml3DEffectsRenderingMode Dml3DEffectsRenderingMode

{

    get{returnmDml3DEffectsRenderingMode; }

    set{ mDml3DEffectsRenderingMode = value; }

}

 

/// <summary>

/// Specifies how 3D shape effects are rendered.

/// </summary>

publicenumDml3DEffectsRenderingMode

{

    /// <summary>

    /// A lightweight and stable rendering, based on the internal engine,

    /// but advanced effects such as lighting, materials and other additional effects

    /// are not displayed when using this mode.

    /// Please see documentation for details.

    /// </summary>

    Basic,

  

    /// <summary>

    /// Rendering of an extended list of special effects including advanced 3D effects

    /// such as bevels, lighting and materials.

    /// </summary>

    /// <remarks>

    /// The current implementation uses OpenGL.

    /// Please make sure that OpenGL library version 1.1 or higher is installed on your system before use.

    /// This mode is still under development, and some things may not be supported, so it's recommended to use

    /// the <see cref="Basic"/> mode if the rendering result is not acceptable.

    /// Please see documentation for details.

    /// </remarks>

    Advanced

}

用例(.NET)

Document doc = new Document(docPath);
SaveOptions saveOptions = new PdfSaveOptions();
saveOptions.Dml3DEffectsRenderingMode = Dml3DEffectsRenderingMode.Advanced;
doc.Save(pdfPath, saveOptions);

请注意:为了使“高级”模式正常工作,必须将系统中的比例设置为100%。下表显示了两种模式之间的差异:

Java版Aspose.Words v20.4用例解析!快速get文档格式处理新技能

添加了一个选项,允许客户指定比较粒度

添加了以下属性:

/// <summary>

/// Specifies the granularity of changes to track when comparing two documents.

/// </summary>

publicenumGranularity

{

    CharLevel,

    WordLevel

}

  

/// <summary>

/// Specifies whether changes are tracked by character or by word.

/// Default value is <see cref="Granularity.WordLevel"/>.

/// </summary>

Granularity CompareOptions.Granularity {get;set; }

用例(.NET)

DocumentBuilder builderA = new DocumentBuilder(new Document());
DocumentBuilder builderB = new DocumentBuilder(new Document());
  
builderA.Writeln("This is A simple word");
builderB.Writeln("This is B simple words");
  
CompareOptions co = new CompareOptions();
co.Granularity = Granularity.CharLevel;
  
builderA.Document.Compare(builderB.Document, "author", DateTime.Now, co);

添加了用于设置浮动表定位的功能(HorizontalAnchor和VerticalAnchor)

用于以下属性的设置器已添加到Table类中:

/// <summary>

/// Gets or sets the base object from which the horizontal positioning of floating table should be calculated.

/// Default value is <see cref="RelativeHorizontalPosition.Column"/>.

/// </summary>

publicRelativeHorizontalPosition Table.HorizontalAnchor

  

/// <summary>

/// Gets or sets the base object from which the vertical positioning of floating table should be calculated.

/// Default value is <see cref="RelativeVerticalPosition.Margin"/>.

/// </summary>

publicRelativeVerticalPosition Table.VerticalAnchor

注意,HorizontalAnchor设置器中仅允许使用以下值。对于任何其他值,将引发ArgumentException。

RelativeHorizontalPosition.Margin

RelativeHorizontalPosition.Page

RelativeHorizontalPosition.Column

注意,VerticalAnchor设置器中仅允许使用以下值。对于任何其他值,将引发ArgumentException。

RelativeVerticalPosition.Margin

RelativeVerticalPosition.Page

RelativeVerticalPosition.Paragraph

用例(.NET)

Document doc = new Documnet(file_with_table);
Table table = doc.FirstSection.Body.Tables[0];
  
table.HorizontalAnchor = RelativeHorizontalPosition.Column;
table.VerticalAnchor = RelativeVerticalPosition.Page;

为PDF渲染添加了图像插值选项

为PDF渲染添加了图像插值选项,可以通过PdfSaveOptions.InterpolateImages属性指定。

/// <summary>

/// A flag indicating whether image interpolation shall be performed by a conforming reader.

/// When <c>false</c> is specified, the flag is not written to the output document and

/// the default behaviour of reader is used instead.

/// </summary>

/// <remarks>

/// <para>

/// When the resolution of a source image is significantly lower than that of the output device,

/// each source sample covers many device pixels. As a result, images can appear jaggy or blocky.

/// These visual artifacts can be reduced by applying an image interpolation algorithm during rendering.

/// Instead of painting all pixels covered by a source sample with the same color, image interpolation

/// attempts to produce a smooth transition between adjacent sample values.

/// </para>

/// <para>

/// A conforming Reader may choose to not implement this feature of PDF,

/// or may use any specific implementation of interpolation that it wishes.

/// </para>

/// <para>The default value is <c>false</c>.</para>

/// </remarks>

publicboolInterpolateImages

用例(.NET)

Document doc = new Document(docPath);
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.InterpolateImages = true;
doc.Save(pdfPath, saveOptions);

图表数据标签和系列的API的更改

图表数据标签API中的以下更改已实现(WORDSNET-19124):

  • 属性HasDataLabels已添加到ChartSeries类。
  • 方法ClearFormat已添加到ChartDataLabelCollection类。
  • ChartDataLabelCollection类的Count属性返回一系列系列的所有数据标签,而不仅仅是像以前版本的软件那样具有非默认格式的数据标签。
  • Add,RemoveAt和Clear方法已标记为过时。设置Series.HasDataLabels = true之后,该集合现在包含该系列的所有数据标签,并且无需向其添加标签。方法RemoveAt和Clear实际上将数据标签的格式重置为ChartDataLabelCollection对象的属性中定义的默认值。现在应改为使用ChartDataLabel.ClearFormat和ChartDataLabelCollection.ClearFormat方法。
  • 方法ClearFormat已添加到ChartDataLabel类。
  • 属性IsHidden已添加到ChartDataLabel类。
public class ChartSeries
{
    /// <summary>
    /// Gets or sets a flag indicating whether data labels are displayed for the series.
    /// </summary>
    public bool HasDataLabels { get; set; }
}
  
public class ChartDataLabelCollection
{
    /// <summary>
    /// Adds new <see cref="ChartDataLabel"/> at the specified index.
    /// </summary>
    [Obsolete("When ChartSeries.HasDataLabels is 'true', all data labels are available in this collection.")]
    public ChartDataLabel Add(int index);
  
    /// <summary>
    /// Clears format of a <see cref="ChartDataLabel"/> at the specified index.
    /// </summary>
    [Obsolete("Use the ChartDataLabel.ClearFormat method instead.")]
    public void RemoveAt(int index);
  
    /// <summary>
    /// Clears format of all <see cref="ChartDataLabel"/> in this collection.
    /// </summary>
    [Obsolete("Use the ClearFormat method instead.")]
    public void Clear();
  
    /// <summary>
    /// Clears format of all <see cref="ChartDataLabel"/> in this collection.
    /// </summary>
    public void ClearFormat();
}
  
public class ChartDataLabel
{
    /// <summary>
    /// Clears format of this data label. The properties are set to the default values defined in the parent data label collection.
    /// </summary>
    public void ClearFormat();
  
    /// <summary>
    /// Gets/sets a flag indicating whether this label is hidden.
    /// The default value is <b>false</b>.
    /// </summary>
    public bool IsHidden { get; set; }
}

用例(.NET)

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
  
Shape shape = builder.InsertChart(ChartType.Line, 432, 252);
Chart chart = shape.Chart;
  
// Delete default generated series.
chart.Series.Clear();
  
ChartSeries series1 = chart.Series.Add("Series 1", 
    new string[] { "Category 1", "Category 2", "Category 3" }, 
    new double[] { 1, 5, 4 });
  
series1.HasDataLabels = true;
series1.DataLabels.ShowValue = true;
series1.DataLabels[1].ShowCategoryName = true;
series1.DataLabels[1].ShowValue = true;
series1.DataLabels[2].IsHidden = true;
  
doc.Save(dir + "DataLabels.docx");

在ECMA376和ISO29500标准文档之间实现了多个PageBorderArt名称的相互转换

实验表明,“ Tribal *” 边框艺术样式与ISO29500特定边框艺术样式之间存在相互对应关系,范围从 “ Triangle1 ”到“ Shapes2 ”。在此版本中,根据下表实现了所提到的BorderArt样式名称的直接转换:

Java版Aspose.Words v20.4用例解析!快速get文档格式处理新技能

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值