About annotation UI and Signature UI

Hi Aleksei,

Is there any update regarding the issue discussed, specifically the slow document loading you were investigating?

Thanks,
Abhinay Patel

Hello,

Thank you for following up.

We are still investigating the issue related to the slow document loading. Our team is actively analyzing the root cause, and we will provide you with an update as soon as we have more information.

Thank you for your patience and understanding.

Best regards,
Aleksei

is there is any update on this?

We analyzed the reasons for the slow performance when working with large PDF files.

First of all, we would like to emphasize that this code is part of a basic sample (demo) application, intended to demonstrate integration and core functionality. It is not designed for production use or large-scale/high-load scenarios without additional optimization.

Main performance bottlenecks

1. Loading all document pages at once (critical)

Issue:
The current configuration uses preloadPageCount: 0, which causes all pages to be loaded and rendered when the document is opened.
For a 100-page PDF, this means rendering all 100 pages at the same time, significantly increasing load time and resource consumption.

Code:

# configuration.yml (line 61)
preloadPageCount: 0
// AnnotationServiceImpl.java (lines 167–169)
if (loadAllPages) {
    pagesContent = getAllPagesContent(password, guid, info);
}

2. Creating a new Annotator instance for each page (critical)

Issue:
In the getAllPagesContent() method, a new Annotator instance is created for each page.
For large documents, this results in repeatedly opening and closing the same document (e.g., 100 times for a 100-page file), which has a significant negative impact on performance.

Code:

// AnnotationServiceImpl.java (lines 482–499)
private List<String> getAllPagesContent(String password, String documentGuid, IDocumentInfo pages) {
    List<String> allPages = new ArrayList<>();
    for (int i = 0; i < pages.getPageCount(); i++) {
        byte[] bytes;
        try (OutputStream memoryStream = renderPageToMemoryStream(i + 1, documentGuid, password)) {
            ByteArrayOutputStream bos = (ByteArrayOutputStream) memoryStream;
            bytes = bos.toByteArray();
        } catch (IOException ex) {
            throw new TotalGroupDocsException(ex.getMessage(), ex);
        }
        String encodedImage = new String(Base64.getEncoder().encode(bytes));
        allPages.add(encodedImage);
    }
    return allPages;
}

3. Reopening the file for each page

Issue:
In the renderPageToMemoryStream() method, the file is opened again for each page.
For multi-page documents, this leads to multiple disk read operations, which is another major performance bottleneck.

Code:

// AnnotationServiceImpl.java (lines 263–297)
private static OutputStream renderPageToMemoryStream(int pageNumberToRender,
                                                    String documentGuid,
                                                    String password) {
    try {
        OutputStream result = new ByteArrayOutputStream();
        InputStream inputStream = new FileInputStream(documentGuid);
        try {
            final Annotator annotator = new Annotator(inputStream, getLoadOptions(password));
            // ... render a single page
        } finally {
            // resource cleanup
        }
    }
}

For real-world production scenarios and working with large PDF files, this sample requires further tuning and optimization (lazy page loading, resource reuse, minimizing I/O operations, etc.).