近期更新了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),与大神们一块儿交流讨论!