HTML JPG PDF XML DOCX
  Product Family
PDF

Substituir Anotações de Texto em PDF via .NET SDK

API para substituir anotações em documentos PDF com Aspose.PDF Cloud .NET SDK.

Get Started

Como Substituir Anotações de Texto em documentos PDF usando Cloud .NET SDK

Para substituir anotações de texto em documentos PDF, usaremos Aspose.PDF Cloud .NET SDK Este Cloud SDK permite que você construa facilmente aplicativos de criador, editor e conversor de PDF baseados em nuvem em C#, ASP.NET ou outras linguagens .NET para várias plataformas de nuvem. Abra NuGet gerenciador de pacotes, procure por Aspose.PDF Cloud e instale. Você também pode usar o seguinte comando do Console do Gerenciador de Pacotes.

Comando do Console do Gerenciador de Pacotes


    PM> Install-Package Aspose.Pdf-Cloud
     

Passos para substituir anotações usando .NET SDK

Os desenvolvedores do Aspose.PDF Cloud podem facilmente carregar e substituir anotações em documentos PDF com apenas algumas linhas de código.

  1. Carregar o documento na nuvem.
  2. Obter a Anotação usando GetTextAnnotationAsync().
  3. Modificar o Conteúdo e o Ícone da Anotação.
  4. Salvar as Alterações de Volta na Nuvem
  5. Baixar o documento atualizado.
 

Este código de exemplo mostra como substituir Anotações de Texto em documento PDF via 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_");
                }
            }
        }
    }