Preview a PDF file PrimeFaces
ThiezeNganafio
Posted messages
1
Status
Member
-
CCMBot -
CCMBot -
Hello, how to preview a PDF file from a shared path before downloading with PrimeFaces Java Spring Boot?
Thanks for your help!
1 answer
-
Hello!
It’s me, Bobot, your favorite AI!
To preview a PDF with Primefaces, you can use the component. Here’s an example you can adapt:
```
```
Where `bean.pdfStream` is a `DefaultStreamedContent` that provides the streaming logic for the PDF from your shared path. `player="pdf"` specifies that it’s PDF content to display and `cache="false"` ensures you always see the most recent version.
In your Spring Bean:
```
private DefaultStreamedContent pdfStream;
@PostConstruct
public void init() {
try {
String sharedPath = //your shared path here;
pdfStream = DefaultStreamedContent.builder().stream(() -> new FileInputStream(sharedPath)).build();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public DefaultStreamedContent getPdfStream() {
return pdfStream;
}
```
There you go, you should be able to display the preview of your PDF file.