对于开发者来说是个好消息!引入了全新的 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。