I currently on Vaadin 24.7.3 and use the HtmlObject class to embedd a PDF document directly in the browser and am registering a StreamResource and calling HtmlObject.setData(fileUri.getPath() + "#nameddest=overview") to navigate the PDF to the given section. This is working great however I am now trying to update Vaadin to 24.8.0 which deprecates the StreamResource. I am able to load the PDF using the new DownloadHandler.forFile(“manual.pdf”, “manual.pdf”) but I am unable to set the nameddest. Since StreamResource is marked for removal, does anyone know how I achieve this with the new DownloadHandler in 4.28.0?
I have already tried appending the nameddest to the file name for the fileNameOverride, DownloadHandler.forFile("manual.pdf", "manual.pdf#nameddest=overview"), but that comes out as “%23namedest%3Doverview”.
This is indeed a use case that we didn’t take into account. To help us determine a solution, could you please also share code that shows how you used to register the stream resource?
Circling back here as well in case others have similar needs.
Based on addtitional details that were dicussed in the GitHub issue, we concluded that this is doable by manually registering the DownloadHandler instance through session.getResourceRegistry() and then adjusting the URL. But for this to work you also need to make sure the DownloadHandler doesn’t set a Content-Disposition: attachment header in the HTTP response. When using the fromInputStream factory, this is by giving null file name to the DownloadReponse constructor.