Python 개발자는 클라우드에서 프로그래밍 방식으로 모든 Word(.doc 또는 .docx) 파일에 주석을 달 수 있습니다. 주석은 일반적으로 주석, 메모, 설명 또는 기존 데이터에 대한 추가 정보를 제공하는 문서의 기타 유형의 외부 설명 형식의 메타데이터입니다. 이 기사는 Python에서 REST API를 사용하여 DOCX 파일에 주석을 추가하는 방법에 중점을 둘 것입니다.

이 문서에서는 다음 항목을 다룹니다.

문서 주석 REST API 및 Python SDK

GroupDocs.Annotation 클라우드

DOC 또는 DOCX 문서에 주석을 달기 위해 GroupDocs.Annotation Cloud의 Python SDK API를 사용합니다. 프로그래밍 방식으로 온라인 문서 및 이미지 주석 도구를 구축할 수 있습니다. 이러한 도구를 사용하여 널리 사용되는 모든 형식의 비즈니스 문서에 주석, 워터마크 오버레이, 텍스트 교체, 교정, 스티커 메모 및 텍스트 마크업을 추가할 수 있습니다. 또한 Cloud API용 문서 주석 제품군 구성원으로 .NET, Java, PHP, Ruby 및 Node.js SDK를 제공합니다.

콘솔에서 다음 명령을 사용하여 Python 프로젝트에 GroupDocs.Annotation Cloud를 설치할 수 있습니다.

pip install groupdocs_annotation_cloud

단계와 사용 가능한 코드 예제를 시작하기 전에 대시보드에서 클라이언트 ID와 클라이언트 암호를 얻으십시오. 아래와 같이 코드에 ID와 암호를 추가합니다.

client_id = "112f0f38-9dae-42d5-b4fc-cc84ae644972"
client_secret = "16ad3fe0bdc39c910f57d2fd48a5d618"
my_storage = ""

configurations = groupdocs_annotation_cloud.Configuration(client_id, client_secret)
configurations.api_base_url = "https://api.groupdocs.cloud"

Python에서 REST API를 사용하여 DOCX 파일에 주석 달기

아래에 언급된 간단한 단계에 따라 DOCX 파일에 주석을 추가할 수 있습니다.

문서 업로드

먼저 아래 제공된 코드 예제를 사용하여 DOCX 파일을 클라우드에 업로드합니다.

# API 인스턴스 생성
file_api = groupdocs_annotation_cloud.FileApi.from_config(configurations)

request = groupdocs_annotation_cloud.UploadFileRequest("one-page.docx", "C:\\Files\\one-page.docx", my_storage)
response = file_api.upload_file(request)

결과적으로 업로드된 DOCX 파일은 클라우드 대시보드의 파일 섹션에서 사용할 수 있습니다.

Python의 DOCX 파일에 주석 추가

프로그래밍 방식으로 Word 문서에 주석을 삽입하려면 아래에 언급된 단계를 따르십시오.

  • AnnotationInfo 인스턴스 생성
  • 위치, 유형, 텍스트 등 다양한 주석 속성을 설정합니다.
  • FileInfo 인스턴스 생성
  • 파일 경로 설정
  • AnnotateOptions 인스턴스 생성
  • 파일 정보를 AnnotateOptions로 설정
  • 주석을 AnnotateOptions로 설정
  • AnnotateRequest 메서드를 호출하여 요청 생성
  • AnnotateApi.annotate() 메서드를 호출하여 결과 얻기

다음 코드 스니펫은 REST API를 사용하여 Word 문서에 영역 주석을 삽입하는 방법을 보여줍니다.

api = groupdocs_annotation_cloud.AnnotateApi.from_keys(client_id, client_secret)

a1 = groupdocs_annotation_cloud.AnnotationInfo()
a1.annotation_position = groupdocs_annotation_cloud.Point()
a1.annotation_position.x = 1
a1.annotation_position.y = 1
a1.box = groupdocs_annotation_cloud.Rectangle()
a1.box.x = 100
a1.box.y = 100
a1.box.width = 200
a1.box.height = 100
a1.page_number = 0
a1.pen_color = 1201033
a1.pen_style = "Solid"
a1.pen_width = 1
a1.opacity = 0.7

# 영역 주석 추가
a1.type = "Area"
a1.text = "This is area annotation"
a1.creator_name = "Anonym A."

file_info = groupdocs_annotation_cloud.FileInfo()
file_info.file_path = "one-page.docx"
options = groupdocs_annotation_cloud.AnnotateOptions()
options.file_info = file_info
options.annotations = [a1]
options.output_path = "Output\\output.docx"

request = groupdocs_annotation_cloud.AnnotateRequest(options)
result = api.annotate(request)

결과적으로 아래와 같이 영역 주석이 문서에 삽입됩니다.

Python의 DOCX 파일에 주석 추가

지원되는 주석 유형

아래에서 지원되는 주석 유형 목록을 찾으십시오. 앞서 언급한 단계에 따라 DOCX 파일에 추가할 수 있습니다.

  • 영역
  • 거리
  • 링크
  • 가리키다
  • 폴리라인
  • 영상
  • 텍스트
  • 양수표
  • 화살

업데이트된 파일 다운로드

위의 코드 샘플은 주석이 달린 DOCX 파일을 클라우드에 저장합니다. 다음 코드 샘플을 사용하여 다운로드할 수 있습니다.

# API 인스턴스 생성
file_api = groupdocs_annotation_cloud.FileApi.from_config(configurations)

request = groupdocs_annotation_cloud.DownloadFileRequest("Output\\output.docx", my_storage)
response = file_api.download_file(request)

# 다운로드한 파일을 작업 디렉토리로 이동
shutil.move(response, "C:\\Files\\")

Python을 사용하여 여러 주석 추가

프로그래밍 방식으로 DOCX 파일에 여러 주석을 추가하려면 아래에 언급된 단계를 따르십시오.

  • AnnotationInfo의 첫 번째 인스턴스 생성
  • 첫 번째 인스턴스(예: 위치, 유형, 텍스트 등)에 대한 다양한 주석 속성을 설정합니다.
  • AnnotationInfo 두 번째 인스턴스 만들기
  • 두 번째 인스턴스에 대한 다양한 주석 속성(예: 위치, 유형, 텍스트 등)을 설정합니다.
  • FileInfo 인스턴스 생성
  • 파일 경로 설정
  • AnnotateOptions 인스턴스 생성
  • 파일 정보를 AnnotateOptions로 설정
  • 첫 번째 및 두 번째 주석을 AnnotateOptions로 설정
  • AnnotateRequest 메서드를 호출하여 요청 생성
  • AnnotateApi.annotate() 메서드를 호출하여 결과 얻기

다음 코드 조각은 REST API를 사용하여 DOCX 파일에 여러 주석을 추가하는 방법을 보여줍니다. 앞에서 언급한 단계에 따라 파일을 업로드하고 다운로드하십시오.

api = groupdocs_annotation_cloud.AnnotateApi.from_keys(client_id, client_secret)
  
a1 = groupdocs_annotation_cloud.AnnotationInfo()
a1.annotation_position = groupdocs_annotation_cloud.Point()
a1.annotation_position.x = 1
a1.annotation_position.y = 1
a1.box = groupdocs_annotation_cloud.Rectangle()
a1.box.x = 200
a1.box.y = 200
a1.box.width = 300
a1.box.height = 100
a1.page_number = 0
a1.pen_color = 1201033
a1.pen_style = "Solid"
a1.pen_width = 1
a1.opacity = 0.2
a1.type = "Watermark"
a1.text = "This is watermark annotation"
a1.creator_name = "Anonym A."
    
a2 = groupdocs_annotation_cloud.AnnotationInfo()
a2.annotation_position = groupdocs_annotation_cloud.Point()
a2.annotation_position.x = 852
a2.annotation_position.y = 59.38
a2.box = groupdocs_annotation_cloud.Rectangle()
a2.box.x = 375.8
a2.box.y = 59.38
a2.box.width = 88
a2.box.height = 37
a2.page_number = 2
a2.pen_color = 1201033
a2.pen_style = "Solid"
a2.pen_width = 1
a2.opacity = 0.9
a2.type = "Image"
a2.text = "This is Image annotation"
a2.creator_name = "Anonym A."
a2.image_path = "JohnSmith.png"
    
file_info = groupdocs_annotation_cloud.FileInfo()
file_info.file_path = "ten-pages.docx"
options = groupdocs_annotation_cloud.AnnotateOptions()
options.file_info = file_info
options.annotations = [a1, a2]
options.output_path = "Output\\output.docx"

request = groupdocs_annotation_cloud.AnnotateRequest(options)
result = api.annotate(request)

결과적으로 아래와 같이 이미지 및 워터마크 주석이 문서에 삽입됩니다.

이미지 및 워터마크 주석

결론

이 기사에서는 Python을 사용하여 Document Annotation REST API를 사용하여 클라우드의 Word 문서에 다양한 유형의 주석을 추가하는 방법을 배웠습니다. 프로그래밍 방식으로 클라우드에 DOCX 파일을 업로드한 다음 클라우드에서 주석이 달린 파일을 다운로드하는 방법도 배웠습니다. 문서를 사용하여 GroupDocs.Annotation Cloud API에 대해 자세히 알아볼 수 있습니다. 또한 브라우저를 통해 직접 API를 시각화하고 상호 작용할 수 있는 API 참조 섹션을 제공합니다. 모호한 점이 있으면 언제든지 포럼에 문의해 주십시오.