HTML JPG PDF XML DOCX
  Product Family
PDF

Reemplazar anotaciones de texto en PDF a través de .NET SDK

API para reemplazar anotaciones en documentos PDF con Aspose.PDF Cloud .NET SDK.

Get Started

Cómo reemplazar anotaciones de texto en documentos PDF usando Cloud .NET SDK

Para reemplazar anotaciones de texto en documentos PDF, usaremos Aspose.PDF Cloud .NET SDK Este Cloud SDK te permite crear fácilmente aplicaciones basadas en la nube para crear, editar y convertir PDF en C#, ASP.NET u otros lenguajes .NET para varias plataformas en la nube. Abre NuGet el administrador de paquetes, busca Aspose.PDF Cloud e instala. También puedes usar el siguiente comando desde la Consola del Administrador de Paquetes.

Comando de la Consola del Administrador de Paquetes


    PM> Install-Package Aspose.Pdf-Cloud
     

Pasos para reemplazar anotaciones usando .NET SDK

Los desarrolladores de Aspose.PDF Cloud pueden cargar y reemplazar fácilmente anotaciones en documentos PDF con solo unas pocas líneas de código.

  1. Sube el documento a la nube.
  2. Obtén la anotación usando GetTextAnnotationAsync().
  3. Modifica el contenido de la anotación y el icono.
  4. Guarda los cambios de nuevo en la nube.
  5. Descarga el documento actualizado.
 

Este código de muestra muestra cómo reemplazar anotaciones de texto en un documento PDF a través de 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_");
                }
            }
        }
    }