Aspose.Words for Java是功能豐富的Word處理API,允許開發(fā)人員在不使用Microsoft Word的情況下嵌入在自己的Java應(yīng)用程序中生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印文檔的功能。
很高興與大家分享Java平臺的Aspose.Words迎來了2020.4月更新,該版本具有.NET版同樣的7大新升級體驗,包括Java平臺現(xiàn)在支持OpenGL渲染,日志記錄系統(tǒng)已更新和改進(jìn),圖表數(shù)據(jù)標(biāo)簽和系列的擴(kuò)展API等等。本文將用示例為大家演示這些新功能,幫助你快速上手。
主要特點
-
Java平臺現(xiàn)在支持OpenGL渲染(使用外部庫)。
-
日志記錄系統(tǒng)已更新和改進(jìn)。
-
Sonarqube測試通過。
-
提供了更改亞洲段落間距和縮進(jìn)的功能。
-
為PDF渲染添加了圖像插值選項(新的公共屬性PdfSaveOptions.InterpolateImages)。
-
添加了新的模式3D形狀渲染。
-
圖表數(shù)據(jù)標(biāo)簽和系列的擴(kuò)展API。
增加了更改亞洲段落間距和縮進(jìn)的功能
添加了以下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)
請注意,設(shè)置單位的縮進(jìn)和間距將更新適當(dāng)?shù)墓部s進(jìn)或間距屬性。例如,設(shè)置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);
請注意:為了使“高級”模式正常工作,必須將系統(tǒng)中的比例設(shè)置為100%。下表顯示了兩種模式之間的差異:
添加了一個選項,允許客戶指定比較粒度
添加了以下屬性:
/// <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);
添加了用于設(shè)置浮動表定位的功能(HorizontalAnchor和VerticalAnchor)
用于以下屬性的設(shè)置器已添加到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設(shè)置器中僅允許使用以下值。對于任何其他值,將引發(fā)ArgumentException。
RelativeHorizontalPosition.Margin
RelativeHorizontalPosition.Page
RelativeHorizontalPosition.Column
注意,VerticalAnchor設(shè)置器中僅允許使用以下值。對于任何其他值,將引發(fā)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);
圖表數(shù)據(jù)標(biāo)簽和系列的API的更改
圖表數(shù)據(jù)標(biāo)簽API中的以下更改已實現(xiàn)(WORDSNET-19124):
-
屬性HasDataLabels已添加到ChartSeries類。
-
方法ClearFormat已添加到ChartDataLabelCollection類。
-
ChartDataLabelCollection類的Count屬性返回一系列系列的所有數(shù)據(jù)標(biāo)簽,而不僅僅是像以前版本的軟件那樣具有非默認(rèn)格式的數(shù)據(jù)標(biāo)簽。
-
Add,RemoveAt和Clear方法已標(biāo)記為過時。設(shè)置Series.HasDataLabels = true之后,該集合現(xiàn)在包含該系列的所有數(shù)據(jù)標(biāo)簽,并且無需向其添加標(biāo)簽。方法RemoveAt和Clear實際上將數(shù)據(jù)標(biāo)簽的格式重置為ChartDataLabelCollection對象的屬性中定義的默認(rèn)值。現(xiàn)在應(yīng)改為使用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標(biāo)準(zhǔn)文檔之間實現(xiàn)了多個PageBorderArt名稱的相互轉(zhuǎn)換
實驗表明,“ Tribal *” 邊框藝術(shù)樣式與ISO29500特定邊框藝術(shù)樣式之間存在相互對應(yīng)關(guān)系,范圍從 “ Triangle1 ”到“ Shapes2 ”。在此版本中,根據(jù)下表實現(xiàn)了所提到的BorderArt樣式名稱的直接轉(zhuǎn)換:
Aspose是目前國內(nèi)外非常火爆且功能強(qiáng)大的文件格式敏捷開發(fā)控件,但因為產(chǎn)品眾多、技術(shù)問題復(fù)雜等因素,也常常遭受開發(fā)人員吐槽。如果您也正在使用Aspose相關(guān)產(chǎn)品,點擊下方按鈕,來談?wù)凙spose的優(yōu)劣,您的感受對我們相當(dāng)寶貴哦~
標(biāo)簽:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn