近期我们更新了Aspose.Slides For .Net v19.6,其中很重要的是丰富了改进的图像管理支持功能。其中,基于.NET的API中可用的内容也适用于Java,Android,通过基于Java和C ++的API。通过这种方式,用户可以轻松使用他们正在使用的API,并且可以使用相同的功能。
Aspose.Words For .Net是一种高级Word文档处理API,用于执行各种文档管理和操作任务。API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word。此外,API支持所有流行的Word处理文件格式,并允许将Word文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
接下来,将详细讲解一些非常有趣且重要的新功能以及API进行的一些改进。
在演示文稿中添加图像为BLOB
处理PowerPoint演示文稿时,在演示文稿中处理图像起着关键作用。有时需要在演示中添加大量图像。MS PowerPoint包括blob等图像。新版中为IImageCollection接口和ImageCollection类添加了一个新方法,以支持将大图像作为流添加以将它们视为BLOB。
下面这个例子演示了如何包含大BLOB(图像)并防止高内存消耗:
//文档目录的路径。 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类中。此方法允许获得幻灯片背景的有效值。以下示例显示如何获取幻灯片的有效背景值。
//文档目录的路径。 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),与大神们一起交流讨论!
本文暂时没有评论,来添加一个吧(●'◡'●)