近期更新了Aspose.Slides For .Net v19.6,其中很重要的是豐富了改進的圖像管理支持功能。其中,基於.NET的API中可用的內容也適用於Java,Android,經過基於Java和C ++的API。經過這種方式,用戶能夠輕鬆使用他們正在使用的API,而且可使用相同的功能。java
Aspose.Words For .Net是一種高級Word文檔處理API,用於執行各類文檔管理和操做任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。此外,API支持全部流行的Word處理文件格式,並容許將Word文檔導出或轉換爲固定佈局文件格式和最經常使用的圖像/多媒體格式。ide
接下來,將詳細講解一些很是有趣且重要的新功能以及API進行的一些改進。佈局
【下載Aspose.Words for .NET最新試用版】spa
處理PowerPoint演示文稿時,在演示文稿中處理圖像起着關鍵做用。有時須要在演示中添加大量圖像。MS PowerPoint包括blob等圖像。新版中爲IImageCollection接口和ImageCollection類添加了一個新方法,以支持將大圖像做爲流添加以將它們視爲BLOB。code
下面這個例子演示瞭如何包含大BLOB(圖像)並防止高內存消耗:orm
//文檔目錄的路徑。
string dataDir = RunExamples.GetDataDir_PresentationSaving();
string pathToLargeImage = dataDir +
"large_image.jpg"
;
//建立一個包含此圖像的新演示文稿
using (Presentation pres =
new
Presentation())
{
using (FileStream fileStream =
new
FileStream(pathToLargeImage, FileMode.Open))
{
//讓咱們將圖像添加到演示文稿中 - 咱們選擇KeepLocked行爲,由於咱們沒有
//有意訪問「largeImage.png」文件。
IPPImage img = pres.Images.AddImage(fileStream, LoadingStreamBehavior.KeepLocked);
pres.Slides[
0
].Shapes.AddPictureFrame(ShapeType.Rectangle,
0
,
0
,
300
,
200
, img);
//保存演示文稿 儘管輸出演示將是
//較大時,內存消耗將低於pres對象的整個生命週期
pres.Save(dataDir +
"presentationWithLargeImage.pptx"
, SaveFormat.Pptx);
}
}
|
相似的基於Java的示例:對象
//文檔目錄的路徑。
String
dataDir = Utils.getDataDir(AddBlobImageToPresentation.
class
);
//假設咱們想要包含在演示文稿中的大圖像文件
String
pathToLargeImage = dataDir +
"large_image.jpg"
;
//建立一個包含此圖像的新演示文稿
Presentation pres =
new
Presentation();
try
{
FileInputStream fip =
new
FileInputStream(pathToLargeImage);
try
{
//讓咱們將圖像添加到演示文稿中 - 咱們選擇KeepLocked行爲
//意圖訪問「largeImage.png」文件。
IPPImage img = pres.getImages().addImage(fip, LoadingStreamBehavior.KeepLocked);
pres.getSlides().get_Item(
0
).getShapes().addPictureFrame(ShapeType.Rectangle,
0
,
0
,
300
,
200
, img);
//保存演示文稿
// 較大時,pres對象的整個生命週期內的內存消耗將較低
pres.save(dataDir +
"presentationWithLargeImage.pptx"
, SaveFormat.Pptx);
}
finally
{
fip.close();
}
}
catch
(java.io.IOException e) {
e.printStackTrace();
}
finally
{
pres.dispose();
}
|
基於C ++的相似示例:接口
//假設咱們想要包含在演示文稿中的大圖像文件
System::
String
pathToLargeImage = u
"../templates/largeImage.jpg"
;
//建立一個包含此圖像的新演示文稿
auto pres = System::MakeObject();
auto fileStream = System::MakeObject(pathToLargeImage, System::IO::FileMode::Open);
//讓咱們將圖像添加到演示文稿中 - 咱們選擇KeepLocked行爲
//意圖訪問「largeImage.png」文件。
auto img = pres->get_Images()->AddImage(fileStream, LoadingStreamBehavior::KeepLocked);
pres->get_Slides()->idx_get(
0
)->get_Shapes()->AddPictureFrame(Aspose::Slides::ShapeType::Rectangle,
0
.0f,
0
.0f,
300
.0f,
200
.0f, img);
//保存演示文稿
// 較大時,pres對象的整個生命週期內的內存消耗將較低
pres->Save(u
"../out/presentationWithLargeImage.pptx"
, Aspose::Slides::Export::SaveFormat::Pptx);
|
在這個版本中,Aspose.Slides提供了表示幻燈片有效背景的支持,其中包含有效填充格式和有效效果格式的信息。爲此,添加了IBackgroundEffectiveData接口及其BackgroundEffectiveData類的實現。生命週期
CreateBackgroundEffective方法已添加到IBaseSlide接口和BaseSlide類中。此方法容許得到幻燈片背景的有效值。如下示例顯示如何獲取幻燈片的有效背景值。ip
//文檔目錄的路徑。
string dataDir = RunExamples.GetDataDir_Slides_Presentations_Background();
//實例化表示演示文稿文件的Presentation類
Presentation pres =
new
Presentation(dataDir +
"SamplePresentation.pptx"
);
IBackgroundEffectiveData effBackground = pres.Slides[
0
].CreateBackgroundEffective();
if
(effBackground.FillFormat.FillType == FillType.Solid)
Console.WriteLine(
"Fill color: "
+ effBackground.FillFormat.SolidFillColor);
else
Console.WriteLine(
"Fill type: "
+ effBackground.FillFormat.FillType);
|
相似的基於Java的示例:
//文檔目錄的路徑。
String
dataDir = Utils.getDataDir(GetBackgroundEffectiveValues.
class
);
Presentation pres =
new
Presentation(dataDir +
"SamplePresentation.pptx"
);
IBackgroundEffectiveData effBackground = pres.getSlides().get_Item(
0
).createBackgroundEffective();
if
(effBackground.getFillFormat().getFillType() == FillType.Solid)
System.out.println(
"Fill color: "
+ effBackground.getFillFormat().getSolidFillColor());
else
System.out.println(
"Fill type: "
+ effBackground.getFillFormat().getFillType());
|
基於C ++的相似示例:
const
String
templatePath = u
"../templates/SamplePresentation.pptx"
;
auto pres = System::MakeObject(templatePath);
System::SharedPtreffBackground = pres->get_Slides()->idx_get(
0
)->CreateBackgroundEffective();
if
(effBackground->get_FillFormat()->get_FillType() == Aspose::Slides::FillType::Solid)
{
System::Console::WriteLine(System::
String
(u
"Fill color: "
) + effBackground->get_FillFormat()->get_SolidFillColor());
}
else
{
System::Console::WriteLine(System::
String
(u
"Fill type: "
) + System::ObjectExt::ToString(effBackground->get_FillFormat()->get_FillType()));
}
|
使用時,Aspose.Slides有時須要保存大量的演示文件或將大型演示文件轉換爲PDF。在這種狀況下,API用戶可能經歷等待狀態直到保存或呈現過程完成的時間而且這種狀況有時使人討厭。爲了緩解這種狀況,在ISaveOptions接口和SaveOptions抽象類中添加了一個新的IProgressCallback接口。IProgressCallback接口表示用於以百分比保存進度更新的回調對象。
下面的示例演示了在導出到PDF時使用新功能:
//文檔目錄的路徑。
string dataDir = RunExamples.GetDataDir_Conversion();
using (Presentation presentation =
new
Presentation(dataDir +
"ConvertToPDF.pptx"
))
{
ISaveOptions saveOptions =
new
PdfOptions();
saveOptions.ProgressCallback =
new
ExportProgressHandler();
presentation.Save(dataDir +
"ConvertToPDF.pdf"
, SaveFormat.Pdf, saveOptions);
}
|
class
ExportProgressHandler : IProgressCallback
{
public
void
Reporting(double progressValue)
{
// Use progress percentage value here
int
progress = Convert.ToInt32(progressValue);
Console.WriteLine(progress +
"% file converted"
);
}
}
|
相似的基於Java的示例:
//文檔目錄的路徑。
String
dataDir = Utils.getDataDir(CovertToPDFWithProgressUpdate.
class
);
Presentation presentation =
new
Presentation(dataDir +
"ConvertToPDF.pptx"
);
try
{
ISaveOptions saveOptions =
new
PdfOptions();
saveOptions.setProgressCallback((IProgressCallback)
new
ExportProgressHandler());
presentation.save(dataDir +
"ConvertToPDF.pdf"
, SaveFormat.Pdf, saveOptions);
}
finally
{
presentation.dispose();
}
|
//文檔目錄的路徑。
class
ExportProgressHandler
implements
IProgressCallback {
public
void
reporting(double progressValue) {
//在此使用進度百分比值
}
}
|
基於C ++的相似示例:
const
String
templatePath = u「 ../ templates/ SamplePresentation.pptx 」 ;
const
String
outPath = u「 ../out/SamplePresentation_out.pptx 」 ;
auto presentation = System :: MakeObject(templatePath);
System :: SharedPtrsaveOptions = System :: MakeObject();
System :: SharedPtrcallBack = System :: MakeObject();
saveOptions-> set_ProgressCallback(callBack);
presentation-> Save(outPath,Aspose :: Slides :: Export :: SaveFormat :: Pdf,saveOptions);
|
class
ExportProgressHandler :
public
IProgressCallback
{
public
:
void
Reporting(double progressValue)
{
//...
}
};
|
此版本中包含許多其餘功能,加強功能和錯誤修復程序。更多更新細則可參考【Aspose.Slides For .Net v19.6更新說明】
*若有更多疑惑和資源需求可加入ASPOSE控件討論QQ羣(642018183),與大神們一塊兒交流討論!