Caching pdfviewer

PdfViewer pdfViewer = new PdfViewer();
StreamResource resource = new StreamResource(“example.pdf”, () → getClass().getResourceAsStream(“/pdf/example.pdf”));
pdfViewer.setSrc(resource);
add(pdfViewer);

My pdf keeps on changing, but this pieces of code is caching the previous one can you please guide me

you have to recreate the StreamResource when the PDF changes

StreamResource resource = new StreamResource(“example.pdf”, () → getClass().getResourceAsStream(“/pdf/example.pdf”));
its not recreating this way when it enter the method

You are loading the pdf from the classpath. If you run it in Feb mode this may work but this will not work in production mode because you cannot save inside the JAR/WAR

You should save the pdf in the filesystem

i have changed it,now the streamResource does not wait for the report to be ready
image.png

If you use

public static byte[] exportReportToPdf​(JasperPrint jasperPrint) throws JRException 

you could use the byte in the stream source and you can save the file if needed

Hi, try setting the cache on the stream to 0, like:
resource = new StreamResource(fileName, () → new ByteArrayInputStream(bos.toByteArray()));
resource.setCacheTime(0);

This wil prevent the browser from caching the stream and once you load the pdf again, the browser does not get it from cache.