java rtf转doc_Java版Aspose.Words最新版用例解析!快速get文档格式处理新技能

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

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

5e241eb8fb9ef6530e5d5ad48e867a59.png

主要特点

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

具体更新内容

  • WORDSJava-2264 使用外部库自动移植OpenGL渲染。 新功能
  • WORDSNET-15697 提供更改受密码保护的VBA代码(更改字符串)的功能 新功能
  • WORDSNET-20043 公布公开的CompareLevel(粒度)选项 新功能
  • WORDSNET-20001 提供API以获取针对中文特定段落格式的设置Word 新功能
  • WORDSNET-19913 Range.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 :

///

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

///

///

/// The default value is .

///

publicDml3DEffectsRenderingMode Dml3DEffectsRenderingMode

{

get{returnmDml3DEffectsRenderingMode; }

set{ mDml3DEffectsRenderingMode = value; }

}

///

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

///

publicenumDml3DEffectsRenderingMode

{

///

/// 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.

///

Basic,

///

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

/// such as bevels, lighting and materials.

///

///

/// 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 mode if the rendering result is not acceptable.

/// Please see documentation for details.

///

Advanced

}

用例(.NET)

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

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

ad45ac171b34f1cb543e809ccb5ee41e.png

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

添加了以下属性:

///

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

///

publicenumGranularity

{

CharLevel,

WordLevel

}

///

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

/// Default value is .

///

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类中:

///

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

/// Default value is .

///

publicRelativeHorizontalPosition Table.HorizontalAnchor

///

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

/// Default value is .

///

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属性指定。

///

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

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

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

///

///

///

/// 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.

///

///

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

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

///

/// The default value is false.

///

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{    ///     /// Gets or sets a flag indicating whether data labels are displayed for the series.    ///     public bool HasDataLabels { get; set; }}  public class ChartDataLabelCollection{    ///     /// Adds new  at the specified index.    ///     [Obsolete("When ChartSeries.HasDataLabels is 'true', all data labels are available in this collection.")]    public ChartDataLabel Add(int index);      ///     /// Clears format of a  at the specified index.    ///     [Obsolete("Use the ChartDataLabel.ClearFormat method instead.")]    public void RemoveAt(int index);      ///     /// Clears format of all  in this collection.    ///     [Obsolete("Use the ClearFormat method instead.")]    public void Clear();      ///     /// Clears format of all  in this collection.    ///     public void ClearFormat();}  public class ChartDataLabel{    ///     /// Clears format of this data label. The properties are set to the default values defined in the parent data label collection.    ///     public void ClearFormat();      ///     /// Gets/sets a flag indicating whether this label is hidden.    /// The default value is false.    ///     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样式名称的直接转换:

46597aa11d450311e6b8b90decf78a08.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值