This gist contains code snippets related to Adding Redact Annotation in PDF document using Aspose.PDF Cloud SDK for Java. For more information, please visit
Last active
November 26, 2022 19:29
-
-
Save aspose-cloud/9da2e78f82783715cde79b5dc31201af to your computer and use it in GitHub Desktop.
This gist contains code snippets related to Redacting PDF file content using using Aspose.PDF Cloud SDK for Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/ | |
String clientId = "29ac1517-753f-4303-b755-7185e35cf939"; | |
String clientSecret = "c537caf71eafc8a75a5ee7813b703276"; | |
// createPdfApi instance | |
PdfApi pdfApi = new PdfApi(clientSecret,clientId); | |
// input PDF document | |
String sourcePDF = "PdfWithTable.pdf"; | |
// page of PDF to place Annotation | |
int pageNumber = 1; | |
// create rectangle object to specify the redact annotation region | |
// the region is calculated from Bottom-Left of page | |
Rectangle rect = new Rectangle() | |
// the measurement unit is point | |
.LLX(100.) | |
.LLY(700.) | |
.URX(200.) | |
.URY(600.); | |
// create AnnotationFlags array | |
List<AnnotationFlags> flags = new ArrayList<>(); | |
// set the AnnotationFlag to default | |
flags.add(AnnotationFlags.DEFAULT); | |
// create ArrayList of points | |
List<Point> points = new ArrayList<>(); | |
points.add(new Point().X(10.).Y(40.)); | |
points.add(new Point().X(30.).Y(40.)); | |
// create Redact Annotation object | |
RedactionAnnotation annotation = new RedactionAnnotation(); | |
// set the name of Annotation. | |
// Its useful when we have multiple annotations in a document | |
annotation.setName("Name"); | |
// set the rectangular region for Redact Annotation | |
annotation.setRect(rect); | |
annotation.setFlags(flags); | |
// set horizontal alignment as center | |
annotation.setHorizontalAlignment(HorizontalAlignment.CENTER); | |
// set the ZIndex to 1. | |
annotation.setZindex(1); | |
// Define SlateBlue color in Hex code | |
Color color = new Color(); | |
color.setA(0x00); | |
color.setR(0x6A); | |
color.setG(0x5A); | |
color.setB(0xCD); | |
// specify the fill color for Annotation | |
annotation.setFillColor(color); | |
// The date and time when the annotation was last modified. | |
annotation.setModified("05/21/2021 12:00:00.000 AM"); | |
// Set an array of 8xN numbers specifying the coordinates | |
// of content region that is intended to be removed. | |
annotation.setQuadPoint(points); | |
// create a List Object of type RedactAnnotation | |
List<RedactionAnnotation> annotations = new ArrayList<>(); | |
// add Annotations object created earlier to RedactAnnotation array | |
annotations.add(annotation); | |
// add RedactAnnotation to PDF document | |
AsposeResponse response = pdfApi.postPageRedactionAnnotations(sourcePDF, pageNumber, annotations, null, null, true); | |
assertEquals(200, (int)response.getCode()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/ | |
String clientId = "29ac1517-753f-4303-b755-7185e35cf939"; | |
String clientSecret = "c537caf71eafc8a75a5ee7813b703276"; | |
// createPdfApi instance | |
PdfApi pdfApi = new PdfApi(clientSecret,clientId); | |
// input PDF document | |
String sourcePDF = "PdfWithTable.pdf"; | |
// Get document redaction annotations | |
RedactionAnnotationsResponse responseAnnotations = pdfApi.getPageRedactionAnnotations(sourcePDF,1, null, null); | |
assertEquals(200, (int)responseAnnotations.getCode()); | |
// print the count of annotations available in document | |
System.out.println(responseAnnotations.getAnnotations().getList().size()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get ClientID and ClientSecret from https://dashboard.aspose.cloud/ | |
String clientId = "29ac1517-753f-4303-b755-7185e35cf939"; | |
String clientSecret = "c537caf71eafc8a75a5ee7813b703276"; | |
// createPdfApi instance | |
PdfApi pdfApi = new PdfApi(clientSecret,clientId); | |
// input PDF document | |
String sourcePDF = "PdfWithAnnotations.pdf"; | |
// create rectangular region for Annotation | |
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.)); | |
// create Redaction Annotation object | |
RedactionAnnotation annotation = new RedactionAnnotation(); | |
// set the name for annotation | |
annotation.setName("Name Updated"); | |
// set the rectangular region for annotation | |
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); | |
// Define SlateBlue color in Hex code | |
Color color = new Color(); | |
color.setA(0x00); | |
color.setR(0x6A); | |
color.setG(0x5A); | |
color.setB(0xCD); | |
// specify the fill color for Annotation | |
annotation.setFillColor(color); | |
// get existing Annotation from document | |
RedactionAnnotationsResponse responseAnnotations = pdfApi.getDocumentRedactionAnnotations(sourcePDF, null, null); | |
assertEquals(200, (int)responseAnnotations.getCode()); | |
// get the annotation at index 0 | |
String annotationId = responseAnnotations.getAnnotations().getList().get(0).getId(); | |
// update the Annotation at index 0 | |
AsposeResponse response = pdfApi.putRedactionAnnotation(sourcePDF, annotationId, annotation, null, null, true); | |
assertEquals(200, (int)response.getCode()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This gist contains code snippets related to Redacting PDF file content using using Aspose.PDF Cloud SDK for Java |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment