I have a PDF file on my disk and I want to display it. But the following code doesn’t work :
File f = new File("C:/Test/test.pdf");
System.out.println(f.exists()); // Displays "true"
URL url = f.toURI().toURL();
ExternalResource r = new ExternalResource(url);
Embedded e = new Embedded(null, r);
e.setType(Embedded.TYPE_BROWSER);
mainLayout.addComponent(e);
setContent(mainLayout);
You’re putting a physical path to the file while this should be an url. Do not forget this is a client-server application
Put your PDF files into your webapp area somewhere and construct a full or relative url to it. If your goal is to stream arbitrary located pdf file to the client, then consider using a StreamResource, so you can open a stream to any fila at the server and stream it’s contents to the client.
Actually, I have a directory which contains generated PDF files and which has no link with my webapp. This directory is located on my server.
My aim is to display to my webapp client one of the PDF file. So how can I get a file located on my server ?