Loading...
Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon
TUTORIAL

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Opening Pdf in new Window in PDF reader format

Abhilash S
10 years ago Apr 10, 2012 1:06pm
Andreas Buechler
10 years ago Apr 10, 2012 2:44pm
Abhilash S
10 years ago Apr 12, 2012 4:15am
Charles Anthony
10 years ago Apr 12, 2012 7:28am

1) Create a StreamResource that returns an inputstream that accesses the byte array
2) Use an Embedded component in a window

If you look read the comments of the blog post linked to, there is a fully fledged code sample.

I shall simply cut and paste it below. (I did not write, nor have I tested it.) Clearly change the file input stream to a BYteArrayInputStream.
Change the MIMEType for Excel.

Window window = new Window();
((VerticalLayout) window.getContent()).setSizeFull();
window.setResizable(true);
window.setCaption("Exemplo PDF");
window.setWidth("800");
window.setHeight("600");
window.center();
StreamSource s = new StreamResource.StreamSource() {

@Override
public InputStream getStream() {
try {
File f = new File("C:/themes/repy.pdf");
FileInputStream fis = new FileInputStream(f);
return fis;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
};

StreamResource r = new StreamResource(s, "repy.pdf", mainLayout.getApplication());
Embedded e = new Embedded();
e.setSizeFull();
e.setType(Embedded.TYPE_BROWSER);
r.setMIMEType("application/pdf");

e.setSource(r);
window.addComponent(e);
getMainWindow().addWindow(window);

Cheers,

Charles.

Last updated on Apr, 12th 2012
Abhilash S
9 years ago Apr 20, 2012 1:31pm
Charles Anthony
9 years ago Apr 20, 2012 3:13pm
Abhilash S
9 years ago Apr 27, 2012 10:47am
Boris Mitioglov
9 years ago Feb 17, 2013 3:20pm
Nithesh shetty
5 years ago Oct 19, 2016 12:41pm