
데이터 비밀성 때문에 PDF 파일에서 민감한 세부 정보를 삭제해야 하는 요구 사항이 있으므로 일반적으로 PDF 문서의 특정 페이지 영역에서 편집(텍스트, 이미지 등 제거)합니다. 그러나 대량의 문서를 처리할 때는 API를 사용하여 이 요구 사항을 달성해야 합니다.
이 문서에서는 Aspose.PDF Cloud SDK for Java의 RedactionAnnotation 클래스를 사용하여 PDF를 온라인으로 편집하는 방법에 대한 단계를 설명합니다.
SDK 설치
Aspose.PDF Cloud SDK for Java는 Java 개발자를 위한 프로그래밍 API이며 Aspose.PDF Cloud API 위에 구축되었습니다. 당사의 Cloud API는 특별한 소프트웨어 설치 없이 모든 플랫폼에서 사용할 수 있습니다. 그러나 SDK를 사용하려면 먼저 시스템에 설치해야 합니다.
Cloud SDK는 Maven 및 GitHub에서 다운로드할 수 있습니다. 이제 pom.xml 파일에 다음 세부 정보를 추가하여 Maven 빌드 프로젝트에서 Aspose.Pdf.jar를 다운로드하고 사용하십시오.
<repositories>
<repository>
<id>aspose-cloud</id>
<name>artifact.aspose-cloud-releases</name>
<url>https://artifact.aspose.cloud/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf-cloud</artifactId>
<version>21.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
SDK가 설치되면 다음 단계는 개인화된 클라이언트 ID와 클라이언트 비밀번호를 얻는 것입니다. Aspose.Cloud 대시보드를 방문하고 GitHub 또는 Google 계정이 있는 경우 간단히 가입하세요. 그렇지 않은 경우 새 계정 만들기 버튼을 클릭하고 필요한 정보를 제공하세요. 이제 자격 증명을 사용하여 대시보드에 로그인하고 애플리케이션 섹션을 확장하세요. 클라이언트 자격 증명 섹션으로 스크롤하여 클라이언트 ID와 클라이언트 비밀번호 세부 정보를 확인하세요.
Java를 사용하여 Redaction 주석 추가
아래 섹션에서는 Aspose.PDF Cloud SDK for Java를 사용하여 PDF 파일의 내용을 삭제하기 위한 직사각형 상자를 추가하는 방법에 대한 단계를 설명했습니다.
- 우선, Aspose.Cloud 대시보드에서 얻은 ClientId와 ClientSecret 세부 정보를 전달하면서 PdfApi 객체를 생성해야 합니다.
- 둘째, Annotation이 추가될 페이지의 영역을 지정하기 위해 Rectangle 클래스의 객체를 생성합니다.
- 셋째, AnnotationFlags 열거형에서 기본값을 선택하여 AnnotationFlags 유형의 목록에 추가합니다.
- 이제 RedactionAnnotation 클래스의 인스턴스를 생성하고 setRect(…) 메서드를 사용하여 사각형 영역을 설정합니다.
- setHorizontalAlignment(…) 메서드를 사용하여 수평 정렬을 설정하고 HorizontalAlignment 열거형에서 가운데를 선택합니다.
- Annotation 내부에 색상을 채우려면 setFillColor(…) 메서드를 사용하고 Color 객체를 전달합니다.
- setModified(…) 메서드를 사용하여 주석의 마지막 수정 날짜를 설정합니다.
- 마지막으로 RedactionAnnotation 유형의 목록을 만들고 이 목록에 RedactAnnotation 객체를 추가합니다.
- 마지막으로 PdfApi의 postPageRedactionAnnotations(…) 메서드를 호출하고 소스 파일 이름, 주석을 추가해야 하는 페이지 번호를 전달합니다. 또한 RedactionAnnotation List를 인수로 전달하여 편집 프로세스를 시작합니다.
// https://dashboard.aspose.cloud/에서 ClientID와 ClientSecret을 가져옵니다.
String clientId = "29ac1517-753f-4303-b755-7185e35cf939";
String clientSecret = "c537caf71eafc8a75a5ee7813b703276";
// createPdfApi 인스턴스
PdfApi pdfApi = new PdfApi(clientSecret,clientId);
// PDF 문서 입력
String sourcePDF = "PdfWithTable.pdf";
// 주석을 넣을 PDF 페이지
int pageNumber = 1;
// 수정된 주석 영역을 지정하기 위해 사각형 객체를 생성합니다.
// 영역은 페이지의 왼쪽 하단에서 계산됩니다.
Rectangle rect = new Rectangle()
// 측정 단위는 포인트입니다
.LLX(100.)
.LLY(700.)
.URX(200.)
.URY(600.);
// AnnotationFlags 배열 생성
List<AnnotationFlags> flags = new ArrayList<>();
// AnnotationFlag를 기본값으로 설정
flags.add(AnnotationFlags.DEFAULT);
// 포인트의 ArrayList를 생성
List<Point> points = new ArrayList<>();
points.add(new Point().X(10.).Y(40.));
points.add(new Point().X(30.).Y(40.));
// Redact Annotation 객체 생성
RedactionAnnotation annotation = new RedactionAnnotation();
// 주석의 이름을 설정합니다.
// 문서에 여러 개의 주석이 있는 경우 유용합니다.
annotation.setName("Name");
// Redact Annotation에 대한 직사각형 영역 설정
annotation.setRect(rect);
annotation.setFlags(flags);
// 수평 정렬을 중앙으로 설정
annotation.setHorizontalAlignment(HorizontalAlignment.CENTER);
// ZIndex를 1로 설정합니다.
annotation.setZindex(1);
// 16진수 코드로 SlateBlue 색상 정의
Color color = new Color();
color.setA(0x00);
color.setR(0x6A);
color.setG(0x5A);
color.setB(0xCD);
// 주석에 대한 채우기 색상을 지정하세요
annotation.setFillColor(color);
// 주석이 마지막으로 수정된 날짜 및 시간입니다.
annotation.setModified("05/21/2021 12:00:00.000 AM");
// 좌표를 지정하는 8xN 숫자 배열을 설정합니다.
// 제거하려는 콘텐츠 영역입니다.
annotation.setQuadPoint(points);
// RedactAnnotation 유형의 List 객체를 생성합니다.
List<RedactionAnnotation> annotations = new ArrayList<>();
// RedactAnnotation 배열에 이전에 생성한 Annotations 객체를 추가합니다.
annotations.add(annotation);
// PDF 문서에 RedactAnnotation 추가
AsposeResponse response = pdfApi.postPageRedactionAnnotations(sourcePDF, pageNumber, annotations, null, null, true);
assertEquals(200, (int)response.getCode());

이미지 1: PDF 파일에 추가된 주석을 편집했습니다.
위의 예에서 사용된 샘플 파일을 여기에서 다운로드하세요.
페이지 편집 주석 읽기
Aspose.PDF Cloud SDK for Java는 PDF 문서에서 기존 Redact 주석에 대한 정보를 읽는 기능도 제공합니다. 아래에 제공된 단계는 Java를 사용하여 주석 세부 정보를 읽는 방법을 정의합니다.
// https://dashboard.aspose.cloud/에서 ClientID와 ClientSecret을 가져옵니다.
String clientId = "29ac1517-753f-4303-b755-7185e35cf939";
String clientSecret = "c537caf71eafc8a75a5ee7813b703276";
// createPdfApi 인스턴스
PdfApi pdfApi = new PdfApi(clientSecret,clientId);
// PDF 문서 입력
String sourcePDF = "PdfWithTable.pdf";
// 문서 편집 주석 가져오기
RedactionAnnotationsResponse responseAnnotations = pdfApi.getPageRedactionAnnotations(sourcePDF,1, null, null);
assertEquals(200, (int)responseAnnotations.getCode());
// 문서에서 사용 가능한 주석 수를 인쇄합니다.
System.out.println(responseAnnotations.getAnnotations().getList().size());
기존 Redaction 주석 업데이트
PDF 문서에 이미 Redaction 주석이 포함되어 있는 경우 API를 사용하여 업데이트할 수도 있습니다. PDF 문서에서 기존 주석을 업데이트하는 방법에 대한 자세한 내용은 다음과 같습니다.
- 클라이언트 ID와 클라이언트 비밀번호 정보를 인수로 전달하여 PdfApi 인스턴스를 생성합니다.
- 주석 영역을 정의하기 위해 Rectangle 객체를 만듭니다. 문서의 왼쪽 하단에서 계산되며 기본 단위는 Point입니다.
- AnnotationFlags 목록을 만들고 목록에 AnnotationFlags.DEFAULT 값을 추가합니다.
- 이제 RedactionAnnotation 객체를 생성하고 setRect(…) 메서드를 호출하여 주석의 사각형 영역을 정의해야 합니다.
- Annotation의 마지막 수정 날짜를 설정하려면 setModified(…) 메서드를 사용합니다.
- PdfApi 호출의 getDocumentRedactionAnnotations(…) 메서드를 호출하여 문서에서 주석 목록을 읽습니다.
- responseAnnotations.getAnnotations().getList().get(0).getId()를 사용하여 특정 Annotation 객체를 확보합니다.
- 마지막으로 PdfApi 클래스의 putRedactionAnnotation(…) 메서드를 호출하여 PDF 파일에 있는 기존 Redaction Annotation을 업데이트합니다.
// https://dashboard.aspose.cloud/에서 ClientID와 ClientSecret을 가져옵니다.
String clientId = "29ac1517-753f-4303-b755-7185e35cf939";
String clientSecret = "c537caf71eafc8a75a5ee7813b703276";
// createPdfApi 인스턴스
PdfApi pdfApi = new PdfApi(clientSecret,clientId);
// PDF 문서 입력
String sourcePDF = "PdfWithAnnotations.pdf";
// 주석을 위한 직사각형 영역 생성
Rectangle rect = new Rectangle()
.LLX(200.)
.LLY(120.)
.URX(150.)
.URY(100.);
List<AnnotationFlags> flags = new ArrayList<>();
flags.add(AnnotationFlags.DEFAULT);
List<Point> points = new ArrayList<>();
points.add(new Point().X(10.).Y(40.));
points.add(new Point().X(30.).Y(40.));
// Redaction Annotation 객체 생성
RedactionAnnotation annotation = new RedactionAnnotation();
// 주석에 대한 이름을 설정하세요
annotation.setName("Name Updated");
// 주석을 위한 직사각형 영역 설정
annotation.setRect(rect);
annotation.setFlags(flags);
annotation.setHorizontalAlignment(HorizontalAlignment.CENTER);
annotation.setZindex(1);
annotation.setModified("01/01/2018 12:02:03.000 AM");
annotation.setQuadPoint(points);
// 16진수 코드로 SlateBlue 색상 정의
Color color = new Color();
color.setA(0x00);
color.setR(0x6A);
color.setG(0x5A);
color.setB(0xCD);
// 주석에 대한 채우기 색상을 지정하세요
annotation.setFillColor(color);
// 문서에서 기존 주석 가져오기
RedactionAnnotationsResponse responseAnnotations = pdfApi.getDocumentRedactionAnnotations(sourcePDF, null, null);
assertEquals(200, (int)responseAnnotations.getCode());
// 인덱스 0에서 주석을 가져옵니다
String annotationId = responseAnnotations.getAnnotations().getList().get(0).getId();
// 인덱스 0에서 주석을 업데이트합니다.
AsposeResponse response = pdfApi.putRedactionAnnotation(sourcePDF, annotationId, annotation, null, null, true);
assertEquals(200, (int)response.getCode());

이미지 2:- 편집된 주석이 업데이트되었습니다.
위 예제에서 사용된 리소스 파일은 다음 링크에서 다운로드할 수 있습니다.
결론
이 문서에서는 PDF 문서에서 민감한 정보를 삭제하는 방법에 대한 단계를 설명했습니다. 삭제 주석 외에도 API는 다양한 다른 주석 기능을 지원하며 자세한 내용은 주석 작업에서 확인할 수 있습니다. 기능에 대한 자세한 내용은 제품 홈페이지를 방문해보세요. 관련 질문이 있으면 무료 제품 지원 포럼을 통해 언제든지 문의하세요.