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
May 23, 2021 01:59
-
-
Save aspose-cloud/c997b4a8d954453f60ad36d27ca48148 to your computer and use it in GitHub Desktop.
This Gist contains code snippets regarding Annotations feature inside PDF document
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 Annotatiions features supported by 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 = "7042694c-5251-4aba-83c9-e81e7518724f"; | |
String clientSecret = "db246d4742e8cd22e7266c9391992689"; | |
// createPdfApi instance | |
PdfApi pdfApi = new PdfApi(clientSecret,clientId); | |
// input PDF document | |
String sourcePDF = "PdfWithTable.pdf"; | |
// Load the file from local system | |
File file = new File("/Users/nayyershahbaz/Downloads/" + sourcePDF); | |
// upload the file to cloud storage | |
FilesUploadResult uploadResponse = pdfApi.uploadFile(sourcePDF, file, null); | |
// page number where Annotation will be added | |
int pageNumber = 1; | |
// create rectangular region for Annotation | |
Rectangle rect = new Rectangle() | |
.LLX(100.) | |
.LLY(700.) | |
.URX(300.) | |
.URY(500.); | |
// create List object of AnnotationFlags type | |
List<AnnotationFlags> flags = new ArrayList<>(); | |
flags.add(AnnotationFlags.DEFAULT); | |
// Create Highlight Annotations object | |
CircleAnnotation annotation = new CircleAnnotation(); | |
annotation.setName("Name"); | |
annotation.setRect(rect); | |
annotation.setFlags(flags); | |
annotation.setRichText("Rich Text"); | |
annotation.setSubject("Subj"); | |
annotation.setTitle("Title"); | |
// create color instance for staleblue | |
Color color = new Color(); | |
color.setR(0xC7); | |
color.setG(0xE2); | |
color.setB(0x6f); | |
// set annotation color | |
annotation.interiorColor(color); | |
// set Annotation modify date | |
annotation.setModified("05/22/2021 00:00:00.000 AM"); | |
// Create List instance of Highlight Annotations | |
List<CircleAnnotation> annotations = new ArrayList<>(); | |
// add CircleAnnotation object to Circle Annotations list | |
annotations.add(annotation); | |
// call API method to add Circle Annotation to PDF file | |
AsposeResponse response = pdfApi.postPageCircleAnnotations(sourcePDF, pageNumber, annotations, null, null); |
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 = "7042694c-5251-4aba-83c9-e81e7518724f"; | |
String clientSecret = "db246d4742e8cd22e7266c9391992689"; | |
// createPdfApi instance | |
PdfApi pdfApi = new PdfApi(clientSecret,clientId); | |
// input PDF document | |
String sourcePDF = "PdfWithTable.pdf"; | |
// Load the file from local system | |
File file = new File("/Users/nayyershahbaz/Downloads/" + sourcePDF); | |
// upload the file to cloud storage | |
FilesUploadResult uploadResponse = pdfApi.uploadFile(sourcePDF, file, null); | |
// page number where annotation will be added | |
int pageNumber = 1; | |
// create rectangular region for Annotation | |
Rectangle rect = new Rectangle() | |
.LLX(100.) | |
.LLY(500.) | |
.URX(400.) | |
.URY(510.); | |
// create List object of AnnotationFlags type | |
List<AnnotationFlags> flags = new ArrayList<>(); | |
flags.add(AnnotationFlags.DEFAULT); | |
// Create Line Annotations object | |
LineAnnotation annotation = new LineAnnotation(); | |
annotation.setName("Name"); | |
annotation.setRect(rect); | |
annotation.setFlags(flags); | |
annotation.setRichText("Rich Text"); | |
annotation.setSubject("Subj"); | |
annotation.setTitle("Title"); | |
// set the starting point of line | |
annotation.setStarting(new Point().X(100.).Y(100.)); | |
// set hte ending point of line | |
annotation.setEnding(new Point().X(20.).Y(680.)); | |
// create color instance for staleblue | |
Color color = new Color(); | |
color.setA(0x00); | |
color.setR(0x6A); | |
color.setG(0x5A); | |
color.setB(0xCD); | |
// set annotation color | |
annotation.interiorColor(color); | |
// set Annotation modify date | |
annotation.setModified("05/22/2021 00:00:00.000 AM"); | |
// Create List instance of Line Annotations | |
List<LineAnnotation> annotations = new ArrayList<>(); | |
// add LineAnnotation object to Line Annotations list | |
annotations.add(annotation); | |
// call API method to add Line Annotation to PDF file | |
AsposeResponse response = pdfApi.postPageLineAnnotations(sourcePDF, pageNumber, annotations, null, null); |
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 = "7042694c-5251-4aba-83c9-e81e7518724f"; | |
String clientSecret = "db246d4742e8cd22e7266c9391992689"; | |
// createPdfApi instance | |
PdfApi pdfApi = new PdfApi(clientSecret,clientId); | |
// input PDF document | |
String sourcePDF = "PdfWithTable.pdf"; | |
// Load the file from local system | |
File file = new File("/Users/nayyershahbaz/Downloads/" + sourcePDF); | |
// upload the file to cloud storage | |
FilesUploadResult uploadResponse = pdfApi.uploadFile(sourcePDF, file, null); | |
int pageNumber = 1; | |
// create rectangular region for Annotation | |
Rectangle rect = new Rectangle() | |
.LLX(200.) | |
.LLY(30.) | |
.URX(250.) | |
.URY(35.); | |
// create List object of AnnotationFlags type | |
List<AnnotationFlags> flags = new ArrayList<>(); | |
flags.add(AnnotationFlags.DEFAULT); | |
// create List object of Point type and define highlight points | |
List<Point> points = new ArrayList<>(); | |
points.add(new Point().X(132.).Y(380.)); // Top-Left edge of the Strike Through line | |
points.add(new Point().X(95.).Y(200.)); // Top-Right edge of the strike through line | |
points.add(new Point().X(130.).Y(125.)); // bottom of the highlight area | |
points.add(new Point().X(130.).Y(125.)); // X value defines Bottom-Left of highlight area | |
// Create Highlight Annotations object | |
HighlightAnnotation annotation = new HighlightAnnotation(); | |
annotation.setName("Name"); | |
annotation.setRect(rect); | |
annotation.setFlags(flags); | |
annotation.setHorizontalAlignment(HorizontalAlignment.CENTER); | |
annotation.setRichText("Rich Text"); | |
annotation.setSubject("Subj"); | |
annotation.setZindex(1); | |
annotation.setTitle("Title"); | |
annotation.setQuadPoints(points); | |
annotation.setModified("05/22/2021 00:00:00.000 AM"); | |
// Create List instance of Highlight Annotations | |
List<HighlightAnnotation> annotations = new ArrayList<>(); | |
// add HighlightAnnotation object to Highlight Annotations list | |
annotations.add(annotation); | |
// call API method to add Highlight Annotation to PDF file | |
AsposeResponse response = pdfApi.postPageHighlightAnnotations(sourcePDF, pageNumber, annotations, null, null); |
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"; | |
int pageNumber = 1; | |
// create rectangular region for Annotation | |
Rectangle rect = new Rectangle() | |
.LLX(200.) | |
.LLY(380.) | |
.URX(250.) | |
.URY(375.); | |
List<AnnotationFlags> flags = new ArrayList<>(); | |
flags.add(AnnotationFlags.DEFAULT); | |
List<Point> points = new ArrayList<>(); | |
points.add(new Point().X(132.).Y(380.)); // Top-Left edge of the Strike Through line | |
points.add(new Point().X(95.).Y(10.)); // Top-Right edge of the strike through line | |
points.add(new Point().X(130.).Y(25.)); | |
points.add(new Point().X(130.).Y(10.)); | |
StrikeOutAnnotation annotation = new StrikeOutAnnotation(); | |
annotation.setName("Name"); | |
annotation.setRect(rect); | |
annotation.setFlags(flags); | |
annotation.setHorizontalAlignment(HorizontalAlignment.CENTER); | |
annotation.setRichText("Rich Text"); | |
annotation.setSubject("Subj"); | |
annotation.setZindex(1); | |
annotation.setTitle("Title"); | |
annotation.setQuadPoints(points); | |
annotation.setModified("05/22/2021 00:00:00.000 AM"); | |
List<StrikeOutAnnotation> annotations = new ArrayList<>(); | |
annotations.add(annotation); | |
AsposeResponse response = pdfApi.postPageStrikeOutAnnotations(sourcePDF, pageNumber, annotations, null, null); | |
assertEquals(200, (int)response.getCode()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment