HTML JPG PDF XML DOCX
  Product Family
PDF

通过 Go SDK 替换 PDF 中的文本注释

使用 Aspose.PDF Cloud Go SDK 替换 PDF 文档注释的 API

Get Started

如何使用 Cloud Go SDK 替换 PDF 文档中的文本注释

为了替换 PDF 文档中的注释,我们将使用 Aspose.PDF Cloud Go SDK 这个 Cloud SDK 帮助 Go 程序员使用 Go 编程语言通过 Aspose.PDF REST API 开发基于云的 PDF 创建、注释、编辑和转换应用程序。在包管理器控制台中使用以下命令。

包管理器控制台命令


     
    go get -u github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25
     
     

使用 Go 替换注释的步骤

Aspose.PDF Cloud Go 开发人员可以轻松替换 PDF 文档中的注释。开发人员只需几行代码即可完成。

  1. 将文件上传到云存储。
  2. getAnnotation 从云中存储的 PDF 中通过 ID 获取文本注释。
  3. ModifyAnnotation 更新该注释的内容和图标。
  4. 修改后,更新的 PDF 被下载到本地。
 

此示例代码展示了如何使用 PDF Cloud Go SDK 替换 PDF 文档中的文本注释


    package main

    import (
        "fmt"

        asposepdfcloud "github.com/aspose-pdf-cloud/aspose-pdf-cloud-go/v25"
    )

    func getAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, annotation_id string, remote_folder string) *asposepdfcloud.TextAnnotation {
        // Get annotation by Id in the PDF document.
        args := map[string]interface{}{
            "folder": remote_folder,
        }
        result, httpResponse, err := pdf_api.GetTextAnnotation(document_name, annotation_id, args)
        if err != nil {
            fmt.Println(err.Error())
            return nil
        } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
            fmt.Println("getAnnotation(): Failed to get annotation in the document.")
            return nil
        } else {
            fmt.Println("getAnnotation(): nnotation '" + annotation_id + "' successfully found '" + result.Annotation.Contents + "' in the document '" + document_name + "'.")
            return result.Annotation
        }
    }

    func ModifyAnnotation(pdf_api *asposepdfcloud.PdfApiService, document_name string, output_document string, annotation_id string, remote_folder string) {
        // Change annotation by Id in the PDF document.
        UploadFile(pdf_api, document_name)
        args := map[string]interface{}{
            "folder": remote_folder,
        }
        annotation := getAnnotation(pdf_api, document_name, annotation_id, remote_folder)
        annotation.Contents = REPLACED_CONTENT
        annotation.Icon = asposepdfcloud.TextIconStar

        _, httpResponse, err := pdf_api.PutTextAnnotation(document_name, annotation_id, *annotation, args)
        if err != nil {
            fmt.Println(err.Error())
        } else if httpResponse.StatusCode < 200 || httpResponse.StatusCode > 299 {
            fmt.Println("ModifyAnnotation(): Failed to modify annotation in the document.")
        } else {
            fmt.Println("ModifyAnnotation(): annotation '" + annotation.Id + "' successfully modified in the document '" + document_name + "'.")
            DownloadFile(pdf_api, document_name, output_document, "replaced_annotatiom_")
        }
    }
 

使用我们的 Go SDK 您可以

  • 以文本或图像格式添加 PDF 文档的页眉和页脚。
  • 向 PDF 文档添加表格和文本或图像印章。
  • 将多个 PDF 文档附加到现有文件。
  • 处理 PDF 附件、注释和表单字段。
  • 对 PDF 文档应用加密或解密并设置密码。
  • 从页面或整个 PDF 文档中删除所有印章和表格。
  • 根据 ID 从 PDF 文档中删除特定印章或表格。
  • 替换 PDF 页面或整个文档中的单个或多个文本实例。
  • 广泛支持将 PDF 文档转换为多种其他文件格式。
  • 提取 PDF 文件的各种元素并优化 PDF 文档。
  • 您可以尝试我们的免费应用在线替换 PDF 文件中的注释并测试功能。

  •