HTML JPG PDF XML DOCX
  Product Family
PDF

Thay Thế Chú Thích Văn Bản trong PDF qua .NET SDK

API để thay thế chú thích trong tài liệu PDF với Aspose.PDF Cloud .NET SDK.

Get Started

Cách Thay Thế Chú Thích Văn Bản trong tài liệu PDF bằng Cloud .NET SDK

Để thay thế chú thích văn bản trong tài liệu PDF, chúng ta sẽ sử dụng Aspose.PDF Cloud .NET SDK Cloud SDK này cho phép bạn dễ dàng xây dựng các ứng dụng tạo, chỉnh sửa & chuyển đổi PDF dựa trên đám mây bằng C#, ASP.NET hoặc các ngôn ngữ .NET khác cho các nền tảng đám mây khác nhau. Mở NuGet trình quản lý gói, tìm kiếm Aspose.PDF Cloud và cài đặt. Bạn cũng có thể sử dụng lệnh sau từ Bảng điều khiển Trình quản lý Gói.

Lệnh Bảng điều khiển Trình quản lý Gói


    PM> Install-Package Aspose.Pdf-Cloud
     

Các bước để thay thế chú thích sử dụng .NET SDK

Các nhà phát triển Aspose.PDF Cloud có thể dễ dàng tải & thay thế chú thích trong tài liệu PDF chỉ với vài dòng mã.

  1. Tải tài liệu lên đám mây.
  2. Lấy Chú Thích bằng cách sử dụng GetTextAnnotationAsync().
  3. Sửa đổi Nội dung và Biểu tượng Chú Thích.
  4. Lưu các Thay Đổi Trở Lại Đám Mây
  5. Tải tài liệu đã cập nhật xuống.
 

Mã mẫu này cho thấy cách thay thế Chú Thích Văn Bản trong tài liệu PDF qua C#


    using Aspose.Pdf.Cloud.Sdk.Model;
    using System.Runtime.Intrinsics.X86;

    namespace Annotations
    {
        public class ReplaceAnnotation
        {
            public static async Task<TextAnnotation> GetAnnotationAsync(AnnotationsHelper helper, string documentName, string annotationId, string remoteFolder)
            {
                // Get annotation by Id in the PDF document.
                TextAnnotation annotationResult = null;
                TextAnnotationResponse response = await helper.pdfApi.GetTextAnnotationAsync(documentName, annotationId, folder: remoteFolder);

                if (response == null)
                    Console.WriteLine("GetAnnotationAsync(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("GetAnnotationAsync(): Failed to request text annotation from the document.");
                else
                {
                    Console.WriteLine("GetAnnotationAsync(): annotation '{0}' with '{1}' contents successfully found in the document '{2}.", response.Annotation.Id, response.Annotation.Contents, documentName);
                    annotationResult = response.Annotation;
                }
                return annotationResult;
            }

            public static async Task ModifyAsync(AnnotationsHelper helper, string documentName, string outputName, string annotationId, string remoteFolder)
            {
                // Change annotation on the page in the PDF document.
                await helper.UploadFile(documentName);
                TextAnnotation annotation = await ReplaceAnnotation.GetAnnotationAsync(helper, documentName, annotationId, remoteFolder);

                annotation.Contents = helper.config.REPLACED_CONTENT;
                annotation.Icon = TextIcon.Star;

                TextAnnotationResponse response = await helper.pdfApi.PutTextAnnotationAsync(documentName, annotationId, annotation, folder: remoteFolder);
                if (response == null)
                    Console.WriteLine("ModifyAnnotation(): Unexpected error!");
                else if (response.Code < 200 || response.Code > 299)
                    Console.WriteLine("ModifyAnnotation(): Failed to request text annotation from the document.");
                else
                {
                    Console.WriteLine("ModifyAnnotation(): annotation '{0}' successfully modified in the document '{1}.", annotationId, documentName);
                    await helper.DownloadFile(documentName, outputName, "replaced_annotatiom_");
                }
            }
        }
    }