Vaadin 8: StreamResource does not render PDF in MS Edge

I have the code below displaying PDF correctly in both Chrome and IE 11 but it shows garbage in Egde (Microsoft Edge 40.15063.0.0). The code used to work in Vaadin 7 for all 3 browsers. [code]
protected Component addPdf( final byte report ) {

StreamResource.StreamSource source = new StreamResource.StreamSource() {
private InputStream stream;
public InputStream getStream() {
if( stream == null ) {
stream = new ByteArrayInputStream( report );
}
return stream;
}
};
return getFrame( source );
}

private Component getFrame( StreamResource.StreamSource source ) {

StreamResource resource = new StreamResource( source, “illustration.pdf” );
resource.setCacheTime( 0 );
resource.setMIMEType( “application/pdf” );
BrowserFrame frame = new BrowserFrame( null, resource );
frame.setSizeFull();
frame.setHeight( 40, Unit.EM );
return frame;
}
[/code]Has anyone seen this or can provide any ideas on what is happening? Unfortunately, being able to see the PDF in Edge is important. Thank you!

34803.png

My guess is that this may happen because Edge is different to other browsers, since it has builtin internal PDF viewer instead of using plugin.

Could be. However, it used to work in Vaadin 7 in all three browsers.

I have retested this issue and it is NOT working with Vaadin 7 either. So regardless of the Vaadin version, you can see PDFs in Edge. Any suggestions on how to get around this?

I don’t know if it’s related or not but I had problem when trying to download a file with Firefox but not Chrome (or it did work on FF but not Chrome :wink: ).
I use Spring boot and Vaadin, by default Spring boot block iframe (i had to add change default configuration
http.headers().frameOptions().sameOrigin(); )
I had a javascript error before changing this configuration.
Perhaps you can check if you have a javascript error.

Jean-Christophe

Thank you, it is a good idea. I had a similar issue with Spring security blocking a PDF stream until I disabled the headers in the security configuration (that stops the frame from having its own headers which makes Spring security block the comminications with the frame).

I am afraid this is different. There is no errors or warnings at all.

Thanks!

35201.pdf (42.1 KB)

Yes, it is mysterious. The information you have shared strongly indicates, that problem is in Edge. Also it seems that problem has appeared after software update. I found this discussion similar https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12347648/

Interesting. It’s not like the world needed another mediocre Microsoft browser…

Unfortunately, I was able to open and see a PDF generated and saved using Chrome in Edge. I am thinking I should try to test it using a simple HTML file that displays a PDF in a frame.

Has anyone found a solution for this? It’s becoming important for us again to disply PDFs in Edge. Thanks!

Actually, I just have figured it out. I think keeping the stream in the source for future use might have been casuing the problem. The following code works fine

protected Component addPdf( final byte report ) {

  return getFrame( () -> new ByteArrayInputStream( report ) );
}

private Component getFrame( StreamResource.StreamSource source ) {

  StreamResource resource = new StreamResource( source, "illustration.pdf" );
  resource.setCacheTime( 0 );
  resource.setMIMEType( "application/pdf" );
  BrowserFrame frame = new BrowserFrame( null, resource );
  frame.setSizeFull();
  frame.setHeight( 40, Unit.EM );
  return frame;
}