Which product are you using?
PDF.js Express Plus
PDF.js Express Version
UI version 8.7.0
Core version 8.7.5
Build ‘Ny80LzIwMjR8MzMxOTBmNGM5YQ==’
Detailed description of issue
In order to allow real-time collaboration, we followed the best practices described here under “Store annotations”: PDF.js Express Viewer Integration Best Practices | Documentation
We are currently saving each annotation (add, modify, delete) in a separate table row. And we have until recently without issues loaded these annotations one at a time like this:
Back-end:
def get_annotations
annotations = []
DevPdfAnnotation.where(dev_pdf_id: params[:dev_pdf_id]).each do |annotation|
annotations.push({author: annotation.author, xfdfstring: annotation.xfdfstring})
end
render json: {
annotations: annotations.to_json
}
end
Front-end:
const annotations = JSON.parse(response.annotations);
_.each(annotations, function (annotation) {
instance.annotManager.importAnnotationCommand(annotation.xfdfstring)
.then(importedAnnotations => {
instance.annotManager.showAnnotations(importedAnnotations);
});
});
This has worked until recently, but now with some users doing 400+ annotations on individual documents we’re having issues. The total individual xfdf strings end up adding up to a lot of data, in one case of ours 35+ MB.
On the best practices section I mentioned you say:
“One way to handle this to store the XFDF data for each annotation separately, for example as rows in a database. Then when PDF.js Express requests the annotation data for a document you can run a query to get all the annotations with that document id, append the data together and send it back to PDF.js Express.”
My question is how can we “append the data together and send it back”. Is there a way to merge the individual xfdf strings into one smaller xfdf string like the one exportAnnotations() returns? Could you give us some guidance on how to do this? We’ve spent days on this issue already. Our backend is in ruby.
We can’t keep doing things the way we are because it (1) takes a very long time, many minutes, for the annotations to load individually (35 MB of xfdf strings in the case I mentioned), and (2) we also have issues trying to merge and download afterwards using the /merge endpoint. It fails due to the request being too large.
Do you provide any backend libraries that can be used to do what exportAnnotations() does?