I try to integrate this add-on in my Vaadin24 app. The example given for creating a screenshot for button click works perfectly. I want to have the screenshot open by the browser in a separate Tab. Thus I use Anchor. But it seems that the CompletableFuture
which Html2Canvas using inside, doesn’t work within the streamfactory needed by the anchor.
Anchor anchor = new Anchor(
new StreamResource("bauzeitenplan.pdf",
() -> {
ByteArrayInputStream result = null;
CompletableFuture<String> completableFuture = HTML2CANVAS.takeScreenShot(bauzeitenplan.getElement());
completableFuture.thenRun(() -> {
try {
String base64 = completableFuture.get();
} catch (InterruptedException | ExecutionException ignored) {
}
});
// here, also a loop waiting for completableFuture.isDone() doesn't help
try {
result = new ByteArrayInputStream(base64decoder.decode(content));
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return result;
}), "");
anchor.getElement().setAttribute("download", true);
anchor.add(new Button("Print"));
return anchor;
How can I integrate the Future with the Anchor ?
But maybe there is any other solution, to download a file by the browser than with Anchor/ Streamfactory ?