Last active
June 12, 2025 16:01
-
-
Save groupdocs-cloud-kb/a19f1addf8360d1fb72d60888a88c5f6 to your computer and use it in GitHub Desktop.
Remove Annotations from PDF using Java REST API https://kb.groupdocs.cloud/annotation/java/remove-annotations-from-pdf-using-java-rest-api/
This file contains hidden or 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
package com.groupdocs; | |
import com.groupdocs.cloud.annotation.client.*; | |
import com.groupdocs.cloud.annotation.api.*; | |
import com.groupdocs.cloud.annotation.model.*; | |
import com.groupdocs.cloud.annotation.model.requests.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class RemoveAnnotationsFromPDF { | |
public static void main(String[] args) { | |
// Configure your API credentials for authentication | |
String MyAppKey = "your-app-key"; | |
String MyAppSid = "your-app-sid"; | |
Configuration configuration = new Configuration(MyAppKey, MyAppSid); | |
// Initialize the AnnotateApi class | |
AnnotateApi annotationApi = new AnnotateApi(configuration); | |
try { | |
// Configure source file info | |
FileInfo fileInfo = new FileInfo(); | |
fileInfo.setFilePath("SampleFiles/source.pdf"); | |
// Retrieve all existing PDF annotations | |
ExtractRequest extraction = new ExtractRequest(); | |
extraction.setfileInfo(fileInfo); | |
List<AnnotationInfo> annotations = annotationApi.extract(extraction); | |
// Collect all annotation IDs | |
List<Integer> annotationIds = new ArrayList<>(); | |
for (AnnotationInfo annotation : annotations) { | |
annotationIds.add(annotation.getId()); | |
} | |
// Apply removal options, including the output file path | |
RemoveOptions options = new RemoveOptions(); | |
options.setFileInfo(fileInfo); | |
options.setAnnotationIds(annotationIds); | |
options.setOutputPath("annotation/output.pdf"); | |
// Create and execute the request to remove annotations from PDF | |
RemoveAnnotationsRequest request = new RemoveAnnotationsRequest(options); | |
AnnotationApiLink result = annotationApi.removeAnnotations(request); | |
} catch (Exception e) { | |
System.err.println("An error occurred: " + e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment