Load document from FTP

On this page

The following code snippet shows how to annotate document from FTP:

// This example demonstrates loading document from FTP.

String filePath = "sample.pdf";
String server = "localhost";

// Create an instance of Annotator class and create connection and return stream with document
Annotator annotator = new Annotator(getFileFromFtp(server, filePath));
try {
    
    // Create an instance of AreaAnnotation class and set options
    AreaAnnotation area = new AreaAnnotation();
    area.setBox(new Rectangle(100, 100, 100, 100));
    area.setBackgroundColor(65535);
    
    // Add annotation and save to file
    annotator.add(area);
    annotator.save("OutputPath");
} finally {
    if (annotator != null) {
        annotator.dispose();
    }
}

//...

private static InputStream getFileFromFtp(String server, String filePath) throws IOException {
    FTPClient client = new FTPClient();
    client.connect(server);
    InputStream inputStream = client.retrieveFileStream(filePath);
    client.disconnect();

    return inputStream;
}

On this page