Node.js에서 REST API를 사용하여 PDF 문서에 주석 달기

Node.js 개발자는 클라우드에서 프로그래밍 방식으로 모든 PDF 문서에 쉽게 주석을 달 수 있습니다. 이미지, 댓글, 메모 또는 기타 유형의 외부 설명을 문서에 주석으로 추가할 수 있습니다. 이 기사에서는 Node.js에서 REST API를 사용하여 PDF 문서에 주석을 다는 방법을 배웁니다.

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

문서 주석 REST API 및 Node.js SDK

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

콘솔에서 다음 명령을 사용하여 GroupDocs.Annotation Cloud를 Node.js 애플리케이션에 설치할 수 있습니다.

npm install groupdocs-annotation-cloud

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

global.clientId = "659fe7da-715b-4744-a0f7-cf469a392b73"; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
global.clientSecret = "b377c36cfa28fa69960ebac6b6e36421"; // Get ClientId and ClientSecret from https://dashboard.groupdocs.cloud
global.myStorage = "";

const configuration = new groupdocs_annotation_cloud.Configuration(clientId, clientSecret);
configuration.apiBaseUrl = "https://api.groupdocs.cloud";

Node.js에서 REST API를 사용하여 PDF 문서에 주석 달기

아래 제공된 간단한 단계에 따라 클라우드에서 PDF 문서에 주석을 달 수 있습니다.

  1. 업로드 PDF 파일을 클라우드에
  2. Node.js를 사용하여 PDF 문서에 주석 달기
  3. 다운로드 주석 파일

문서 업로드

먼저 다음 코드 샘플을 사용하여 PDF 파일을 클라우드에 업로드합니다.

// 초기화 API
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);

// 로컬/디스크에서 IOStream의 파일을 엽니다.
var resourcesFolder = 'C:\\Files\\sample.pdf';
// 파일 읽기
fs.readFile(resourcesFolder, (err, fileStream) => {
  // 업로드 파일 요청 생성
  var request = new groupdocs_annotation_cloud.UploadFileRequest("sample.pdf", fileStream, myStorage);
  // 파일 업로드
  fileApi.uploadFile(request)
});

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

Node.js를 사용하여 PDF 문서에 주석 달기

아래 언급된 단계에 따라 프로그래밍 방식으로 PDF 문서에 여러 주석을 추가할 수 있습니다.

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

다음 코드 샘플은 Node.js에서 REST API를 사용하여 여러 주석으로 PDF 문서에 주석을 추가하는 방법을 보여줍니다.

// 초기화 API
let 주석을 달다Api = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);

// 거리 주석
let a1 = new groupdocs_annotation_cloud.AnnotationInfo();
a1.annotationPosition = new groupdocs_annotation_cloud.Point();
a1.annotationPosition.x = 1;
a1.annotationPosition.y = 1;
a1.box = new groupdocs_annotation_cloud.Rectangle();
a1.box.x = 100
a1.box.y = 100
a1.box.width = 200
a1.box.height = 100
a1.pageNumber = 0
a1.penColor = 1201033
a1.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a1.penWidth = 3
a1.opacity = 1
a1.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Distance;
a1.text = "This is 거리 주석";
a1.creatorName = "Anonym A.";

// 영역 주석
let a2 = new groupdocs_annotation_cloud.AnnotationInfo();
a2.annotationPosition = new groupdocs_annotation_cloud.Point();
a2.annotationPosition.x = 1;
a2.annotationPosition.y = 1;
a2.box = new groupdocs_annotation_cloud.Rectangle();
a2.box.x = 80
a2.box.y = 400
a2.box.width = 200
a2.box.height = 100
a2.penColor = 1201033;
a2.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a2.pageNumber = 0;
a2.penWidth = 3;
a2.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Area;
a2.text = "This is 영역 주석";
a2.creatorName = "Anonym A.";

// 텍스트 필드 주석
let a3 = new groupdocs_annotation_cloud.AnnotationInfo();
a3.annotationPosition = new groupdocs_annotation_cloud.Point();
a3.annotationPosition.x = 100;
a3.annotationPosition.y = 100;
a3.box = new groupdocs_annotation_cloud.Rectangle();
a3.box.x = 450
a3.box.y = 150
a3.box.width = 100
a3.box.height = 30
a3.pageNumber = 0;
a3.fontColor = 65535;
a3.fontSize = 16;
a3.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.TextField;
a3.text = "Text field text";
a3.creatorName = "Anonym A.";

// 타원 주석
let a4 = new groupdocs_annotation_cloud.AnnotationInfo();
a4.annotationPosition = new groupdocs_annotation_cloud.Point();
a4.annotationPosition.x = 1;
a4.annotationPosition.y = 1;
a4.box = new groupdocs_annotation_cloud.Rectangle();
a4.box.x = 350;
a4.box.y = 350;
a4.box.width = 200;
a4.box.height = 100;
a4.pageNumber = 0;
a4.penColor = 1201033;
a4.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a4.penWidth = 4;
a4.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Ellipse;
a4.text = "This is 타원 주석";
a4.creatorName = "Anonym A.";

let fileInfo = new groupdocs_annotation_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";
let options = new groupdocs_annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1, a2, a3, a4];
options.outputPath = "Output/output.pdf";

// 주석 요청 생성
let request = new groupdocs_annotation_cloud.AnnotateRequest(options);
// 주석을 달다
let result = await 주석을 달다Api.주석을 달다(request);

console.log("Multiple Annotations added: " + result.href);
Node.js에서 REST API를 사용하여 PDF 문서에 주석 달기

Node.js에서 REST API를 사용하여 PDF 문서에 주석 달기

문서의 adding annotations 섹션에서 지원되는 주석 유형에 대해 자세히 알아볼 수 있습니다.

주석이 달린 파일 다운로드

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

// FileApi 구성
var fileApi = new groupdocs_annotation_cloud.FileApi(configuration);

// 다운로드 파일 요청 생성
let request = new groupdocs_annotation_cloud.DownloadFileRequest("Output/output.pdf", myStorage);
// 파일 다운로드
let response = await fileApi.downloadFile(request);

// 작업 디렉토리에 파일 저장
fs.writeFile("C:\\Files\\output.pdf", response, "binary", function (err) { });
console.log(response);

Node.js를 사용하여 이미지 주석 추가

아래 단계에 따라 프로그래밍 방식으로 PDF 문서에 이미지 주석을 추가할 수 있습니다.

  • AnnotateApi 인스턴스 생성
  • AnnotationInfo의 인스턴스 생성
  • 사각형 정의 및 위치, 높이 및 너비 설정
  • 주석 속성(예: 위치, 텍스트, 높이, 너비 등)을 설정합니다.
  • 주석 유형을 이미지로 설정
  • FileInfo 인스턴스 생성 및 입력 파일 경로 설정
  • AnnotateOptions 인스턴스 생성
  • FileInfo 및 주석을 AnnotateOptions에 할당
  • 출력 파일 경로 설정
  • AnnotateOptions로 AnnotateRequest 메서드를 호출하여 요청 생성
  • AnnotateRequest로 AnnotateApi.annotate() 메서드를 호출하여 결과 얻기

다음 코드 샘플은 Node.js에서 REST API를 사용하여 PDF 문서에 이미지 주석을 추가하는 방법을 보여줍니다. 앞에서 언급한 단계에 따라 파일을 업로드하고 다운로드하십시오.

// 초기화 API
let 주석을 달다Api = groupdocs_annotation_cloud.AnnotateApi.fromKeys(clientId, clientSecret);

// 이미지 주석
let a1 = new groupdocs_annotation_cloud.AnnotationInfo();
a1.annotationPosition = new groupdocs_annotation_cloud.Point();
a1.annotationPosition.x = 1;
a1.annotationPosition.y = 1;
a1.box = new groupdocs_annotation_cloud.Rectangle();
a1.box.x = 300;
a1.box.y = 160;
a1.box.width = 200;
a1.box.height = 40;
a1.pageNumber = 0;
a1.penColor = 1201033;
a1.penStyle = groupdocs_annotation_cloud.AnnotationInfo.PenStyleEnum.Solid;
a1.penWidth = 1;
a1.type = groupdocs_annotation_cloud.AnnotationInfo.TypeEnum.Image;
a1.text = "This is 이미지 주석";
a1.creatorName = "Anonym A.";
a1.imagePath = "JohnSmith.png";

// 입력 파일 경로
let fileInfo = new groupdocs_annotation_cloud.FileInfo();
fileInfo.filePath = "sample.pdf";

// 주석 옵션 정의
let options = new groupdocs_annotation_cloud.AnnotateOptions();
options.fileInfo = fileInfo;
options.annotations = [a1];
options.outputPath = "Output/output.pdf";

// 주석 요청 생성
let request = new groupdocs_annotation_cloud.AnnotateRequest(options);
// 주석을 달다
let result = await 주석을 달다Api.주석을 달다(request);

console.log("Image Annotation added: " + result.href);
Node.js를 사용하여 이미지 주석 추가

Node.js를 사용하여 이미지 주석 추가

온라인 시도

위의 API를 사용하여 개발된 다음 무료 온라인 PDF 주석 도구를 사용해 보십시오. https://products.groupdocs.app/annotation/pdf

결론

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

또한보십시오