Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save groupdocs-cloud-kb/a19f1addf8360d1fb72d60888a88c5f6 to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-kb/a19f1addf8360d1fb72d60888a88c5f6 to your computer and use it in GitHub Desktop.
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