Java版Aspose.Words最新版用例解析!快速get文檔格式處理新技能

Aspose.Words for Java是功能豐富的Word處理API,允許開發人員在不使用Microsoft Word的情況下嵌入在自己的Java應用程序中生成,修改,轉換,呈現和打印文檔的功能。

很高興與大家分享Java平臺的Aspose.Words迎來了2020.4月更新,該版本具有.NET版同樣的7大新升級體驗,包括日誌記錄系統已更新和改進,圖表數據標籤和系列的擴展API等等。接下來,我們一起來聊聊新版本的新功能。(點擊文末“瞭解更多”下載最新版)


Java版Aspose.Words最新版用例解析!快速get文檔格式處理新技能


主要特點

  • 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。

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

添加了新模式的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)

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

請注意:為了使“高級”模式正常工作,必須將系統中的比例設置為100%。下表顯示了兩種模式之間的差異:

Java版Aspose.Words最新版用例解析!快速get文檔格式處理新技能

添加了一個選項,允許客戶指定比較粒度

添加了以下屬性:

///

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

<code>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);/<code>

添加了用於設置浮動表定位的功能(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)

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

為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)

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

圖表數據標籤和系列的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類。
<code>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; }
}/<code>

用例(.NET)

<code>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");/<code> 

在ECMA376和ISO29500標準文檔之間實現了多個PageBorderArt名稱的相互轉換

實驗表明,“ Tribal *” 邊框藝術樣式與ISO29500特定邊框藝術樣式之間存在相互對應關係,範圍從 “ Triangle1 ”到“ Shapes2 ”。在此版本中,根據下表實現了所提到的BorderArt樣式名稱的直接轉換:

Java版Aspose.Words最新版用例解析!快速get文檔格式處理新技能

如果您有任何疑問或需求,請隨時加入Aspose技術交流群(642018183),我們很高興為您提供查詢和諮詢。


分享到:


相關文章: