對於開發者來說是個好消息!引入了全新的 GroupDocs.Annotation Cloud 19.5。我們致力於發展 GroupDocs.Annotation Cloud REST API,使其更加簡化和易於使用。考慮到這一點,我們對此版本進行了必要的更改。新的 API 更加優化,方法和選項更少。其內部架構經過改進,可實現快速可靠的處理,以構建文檔和圖像註釋工具,並支持基於文本和圖形的註釋操作。現在該 API 還包括使用雲存儲的方法。因此,您可以直接使用 GroupDocs.Annotation Cloud REST API 執行存儲操作,而不是使用單獨的 API。
請查看詳細的此版本的發行說明 以了解此版本中的所有新功能/增強功能。
重大變化
新的API版本
19.5版本引入API版本V2,V1將保持可用。
驗證
此版本中引入了 JWT(JSON Web Token)身份驗證,現在 OAuth2 和 URL 簽名身份驗證方法已過時。
註釋API
簡化的 API 方法可將基於文本和圖形的註釋應用於所有流行格式的文檔和圖像。
存儲API
文件API - 引入了上傳、下載、複製、移動、刪除文件的方法:輸入文檔和渲染結果,在雲存儲中
Folder API - 引入了在雲存儲中創建、複製、移動、刪除文件夾的方法
Storage API - 引入了獲取存儲信息和文件信息的方法
為文檔添加註釋
這裡我們將向您展示 GroupDocs.Annotation Cloud V2 API 版本的工作原理,它與 V1 有所不同。我們將按照以下步驟使用 GroupDocs.Annotation Cloud SDK for .NET 在 Word 文檔中添加註釋:
- 將源文檔上傳至存儲
- 在源文檔中添加註釋
我們需要將源文檔上傳到雲存儲,因為在本例中我們將處理來自云存儲的文檔。在該版本中,我們引入了用於文件存儲操作的 File API。我們將使用 Annotation V2 API 版本的 UploadFile 方法而不是 GroupDocs.Storage Cloud API 方法將文件上傳到存儲。
using System;
using System.IO;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// 上傳文件
class Upload_File
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new FileApi(configuration);
try
{
// 從本地/光盤打開 IOStream 中的文件。
var fileStream = File.Open("..\\..\\..\\Data\\Annotationdocs\\one-page.docx", FileMode.Open);
var request = new UploadFileRequest("Annotationdocs/one-page1.docx", fileStream, Common.MyStorage);
var response = apiInstance.UploadFile(request);
Console.WriteLine("Expected response type is FilesUploadResult: " + response.Uploaded.Count.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception while calling FileApi: " + e.Message);
}
}
}
}
在19.5版本中,導入註釋的PUT方法已更改為POST方法,如下示例代碼所示。
V1.1 示例
//TODO:在 https://dashboard.groupdocs.cloud 獲取您的 AppSID 和 AppKey(需要免費註冊)。
var configuration = new Configuration
{
AppSid = Sid,
AppKey = Key
};
var apiInstance = new AnnotationApi(configuration);
try
{
List<AnnotationInfo> annotations = new List<AnnotationInfo>();
AnnotationInfo annotation = new AnnotationInfo
{
AnnotationPosition = new Point(852, 154.31),
Replies = new[]
{
new AnnotationReplyInfo {Message = "reply text", RepliedOn = DateTime.Now, UserName = "Admin"},
new AnnotationReplyInfo
{
Message = "reply2 text",
RepliedOn = DateTime.Now,
UserName = "Commentator"
}
},
Box = new Rectangle((float)173.29, (float)154.31, (float)142.5, 9),
PageNumber = 0,
SvgPath =
"[{\"x\":173.2986,\"y\":687.5769},{\"x\":315.7985,\"y\":687.5769},{\"x\":173.2986,\"y\":678.5769},{\"x\":315.7985,\"y\":678.5769}]",
Type = AnnotationType.Text,
CreatorName = "Anonym A."
};
annotations.Add(annotation);
PutExportRequest request = new PutExportRequest()
{
Name ="Annotated.pdf",
Folder=null,
Password=null,
Body=annotations,
};
// 將註釋插入/導出到文檔。
var response = apiInstance.PutExport(request);
Debug.Print("Document Processsed and stream length: " + response.Length);
}
catch (Exception e)
{
Debug.Print("Exception when inserting Annotation to document: " + e.Message);
}
V2.0示例
using System;
using GroupDocs.Annotation.Cloud.Sdk.Api;
using GroupDocs.Annotation.Cloud.Sdk.Client;
using GroupDocs.Annotation.Cloud.Sdk.Model;
using GroupDocs.Annotation.Cloud.Sdk.Model.Requests;
namespace GroupDocs.Annotation.Cloud.Examples.CSharp
{
// 發布/添加註釋
class Add_Annotation
{
public static void Run()
{
var configuration = new Configuration(Common.MyAppSid, Common.MyAppKey);
var apiInstance = new AnnotateApi(configuration);
try
{
// 設置請求。
var request = new PostAnnotationsRequest()
{
filePath = "Annotationdocs\\ten-pages.docx",
annotations = new System.Collections.Generic.List<AnnotationInfo>() {
new AnnotationInfo
{
AnnotationPosition = new Point { X = 852, Y = 59.388262910798119 },
Box = new Rectangle { X = 375.89276123046875, Y = 59.388263702392578, Width = 88.7330551147461, Height = 37.7290153503418 },
PageNumber = 0,
PenColor = 1201033,
PenStyle = 0,
PenWidth = 1,
Type = AnnotationInfo.TypeEnum.Area,
CreatorName = "Anonym A."
}
}
};
apiInstance.PostAnnotations(request);
Console.WriteLine("Expected response type is void: Annotation added.");
}
catch (Exception e)
{
Console.WriteLine("Exception while calling Annotation AnnotateApi: " + e.Message);
}
}
}
}
分享您的反饋
您的反饋很重要!請隨時給我們評論分享您對新版本 GroupDocs.Annotation Cloud REST API 的想法。它幫助我們不斷改進和完善我們的 API。