Aspose.Words for .NET使用教程(六):差異和侷限

Aspose.Words無需Microsoft Word也可在任何平臺上滿足Word文檔的一切操作需求。本文將與大家分享Xamarin和.NET Standard 2.0 API的差異和侷限。

Xamarin平臺註釋


Xamarin DLL總是使用Xamarin.Android,Xamarin.iOS和Xamarin.Mac最新且穩定的版本構建。如果你在Xamarin應用程序中使用Aspose.Words的時候遇到問題,請確保安裝了最新的Xamarin版本。有時Aspose.Words使用最新Xamarin版本構建的Xamarin DLL並不適用於舊版本的Xamarin。

與.NET API相比,.NET Standard 2.0,Xamarin.Android,Xamarin.iOS和Xamarin.Mac API的侷限性


1.Document.Print方法在.NET Standard 2.0,Xamarin.Android,Xamarin.iOS和Xamarin.Mac API中不可用。

2.未提供保存到用戶瀏覽器功能,即Document.Save(HttpResponse,string,ContentDescription,SaveOptions)重載不可用。

3.由於目標操作系統(Android,MacOS,Linux等)中缺少Windows字體,文檔中使用的字體將替換爲可用字體,這可能導致文檔佈局不準確,將文檔呈現爲固定頁面格式(如圖像,PDF,XPS)等等。

公共API差異


1.在Aspose.Words for .NET Standard 2.0中,使用Xamarin.Android,Xamarin.iOS和Xamarin.Mac SkiaSharp.SKBitmap對象代替.NET API中的System.Drawing.Bitmap。受影響的API列表:

  • Aspose.Words.DocumentBuilder.InsertImage

  • Aspose.Words.DocumentBuilder.InsertOleObject

  • Aspose.Words.Drawing.ImageData.SetImage

  • Aspose.Words.Drawing.ImageData.ToImage

  • Aspose.Words.Fields.IBarcodeGenerator.GetBarcodeImage

  • Aspose.Words.Fields.IBarcodeGenerator.GetOldBarcodeImage

  • Aspose.Words.MailMerging.ImageFieldMergingArgs.Image

.NET

// Use System.Drawing.Bitmap.
using (System.Drawing.Bitmap image = new System.Drawing.Bitmap(gTestImagePath))
{
    builder.InsertImage(image);
}


.NET Standard 2.0, Xamarin.Android, Xamarin.iOS and Xamarin.Mac

// Insert image into the document from SkiaSharp.SKBitmap object.
using (SkiaSharp.SKBitmap bitmap = SkiaSharp.SKBitmap.Decode(gTestImagePath))
{
    builder.InsertImage(bitmap);
}


2.在Aspose.Words for .NET Standard 2.0中,使用Xamarin.Android,Xamarin.iOS和Xamarin.Mac SkiaSharp.SKCanvas對象代替.NET API中使用的System.Drawing.Graphics對象。受影響的API列表:

  • Aspose.Words.Document.RenderToSize

  • Aspose.Words.Document.RenderToScale

  • Aspose.Words.Rendering.NodeRendererBase.RenderToSize

  • Aspose.Words.Rendering.NodeRendererBase.RenderToScale

.NET

Document doc = new Document(gTestDocumentPath);
 
// Render the first page to System.Drawing.Graphics
using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(1000, 1000))
{
    using (System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bitmap))
    {
        // Apply required transformations to the graphics, rotation for example.
        gr.RotateTransform(45);
 
        doc.RenderToSize(0, gr, 0, 0, bitmap.Width, bitmap.Height);
    }
 
    // Save output to file.
    bitmap.Save(@"C:\Temp\out.png", System.Drawing.Imaging.ImageFormat.Png);
}


.NET Standard 2.0, Xamarin.Android, Xamarin.iOS and Xamarin.Mac

Document doc = new Document(gTestDocumentPath);
 
// Render the first page to SkiaSharp.SKCanvas
using (SkiaSharp.SKBitmap bitmap = new SkiaSharp.SKBitmap(1000, 1000))
{
    using (SkiaSharp.SKCanvas canvas = new SkiaSharp.SKCanvas(bitmap))
    {
        // Apply required transformations to the canvas, rotation for example.
        canvas.RotateDegrees(45);
 
        doc.RotateDegrees(0, canvas, 0, 0, bitmap.Width, bitmap.Height);
    }
 
    // Save output to file.
    using (SkiaSharp.SKFileWStream fs = new SkiaSharp.SKFileWStream(gOutPath+ "RenderToSize_Out.png"))
    {
        bitmap.Encode(fs, SkiaSharp.SKEncodedImageFormat.Png, 100);
    }
}


Xamarin.Android附加要求


1.要正常工作,Aspose.Words的Xamarin.Android API需要Encodings支持。在“Release”模式下運行Xamarin.Android應用程序時,需要添加其他支持的編碼。請注意,在“Debug”模式下,可以在沒有這些選項的情況下工作。

android-encodings

2.如果你想使用Metered許可證,則需要允許你的應用程序訪問Internet。

android_allow_internet_access

Xamarin.iOS附加要求


要正常工作Aspose.Words的Xamarin.iOS API需要Encodings支持。當你運行Xamarin.iOS應用程序時,需要添加其他支持的編碼。

ios_encodings

Xamarin.Mac附加要求


1.要正常工作,Aspose.Words的Xamarin.Mac API需要Encodings支持。當您運行Xamarin.Mac應用程序時,需要添加其他支持的編碼。

mac_encodings

爲你推薦:Aspose專題 - Aspose最新資源合集

下載Aspose.Words for .NET最新試用版


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章