翻譯|產品更新|編輯:李顯亮|2019-07-03 10:58:25.643|閱讀 223 次
概述:近期我們更新了Aspose.Slides For .Net v19.6,其中很重要的是豐富了改進的圖像管理支持功能。其中,基于.NET的API中可用的內容也適用于Java,Android,通過基于Java和C ++的API。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
近期我們更新了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進行的一些改進。
【下載Aspose.Words for .NET最新試用版】
處理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),與大神們一起交流討論!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: