HTML
JPG
PDF
XML
DOCX
PDF
如何使用 Cloud .NET SDK 从 PDF 文档中获取页面注释
为了从 PDF 文档中获取页面注释,我们将使用 Aspose.PDF Cloud .NET SDK 这个 Cloud SDK 允许您在 C#、ASP.NET 或其他 .NET 语言中为各种云平台轻松构建基于云的 PDF 创建、编辑和转换应用程序。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 并安装。您也可以使用包管理器控制台中的以下命令。
包管理器控制台命令
PM> Install-Package Aspose.Pdf-Cloud
使用 .NET SDK 获取注释的步骤
Aspose.PDF Cloud 开发人员可以轻松地在几行代码中加载并获取 PDF 文档中的注释。
- 上传文档。
- 从指定页面检索所有注释。
- 记录每个注释的详细信息。
- 返回第一个文本注释的 ID(用于进一步操作,如编辑或删除)。
此示例代码展示了如何通过 C# 从 PDF 文档中获取页面注释
using Aspose.Pdf.Cloud.Sdk.Model;
namespace Annotations
{
public class GetAnnotations
{
public static async Task<string> RequestAnnotationsOnPageAsync(AnnotationsHelper helper, string documentName, int pageNumber, string remoteFolder)
{
// Get annotations from the page in the PDF document.
await helper.UploadFile(documentName);
string annotationResult = string.Empty;
AnnotationsInfoResponse response = await helper.pdfApi.GetPageAnnotationsAsync(documentName, pageNumber, folder: remoteFolder);
if (response == null)
Console.WriteLine("RequestAnnotationsOnPageAsync(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("RequestAnnotationsOnPageAsync(): Failed to request annotations from the document.");
else
{
foreach (AnnotationInfo annotation in response.Annotations.List)
{
Console.WriteLine("RequestAnnotationsOnPageAsync(): annotation '{0}' with '{1}' contents get from the '{2}' page of the document '{3}.", [annotation.Id, annotation.Contents, pageNumber, documentName]);
if (string.IsNullOrEmpty(annotationResult) &&
annotation.AnnotationType == AnnotationType.Text)
{
annotationResult = annotation.Id;
}
}
}
return annotationResult;
}
}
}