Dmitry159
(Dmitry Krivenko)
July 8, 2020, 12:15pm
1
Excuse me, but i cant understand: why component doesn’t work. Using Vaadin 14.2.3.
…
InputStream is, String fileName;
…
MemoryBuffer buffer = new MemoryBuffer();
upload = new Upload(buffer);
upload.addSucceededListener(event → {
is = buffer.getInputStream();
fileName = buffer.getFileName();
}
Then
sm.addItem(“Открыть документ”, e → {
StreamResource streamResource = new StreamResource(fileName, () -> is);
streamResource.setContentType("application/pdf");
streamResource.setCacheTime(0);
PdfBrowserViewer viewer = new PdfBrowserViewer(streamResource);
viewer.setHeight("100%");
add(viewer)
});
Result in attachment.
Maybe you need to call setHeightFull()
on the layout?
Valentin27
(Valentin Schuravlov)
September 7, 2020, 3:19pm
3
I have the same problem.
Vaadin 14.3.4,
plugin 3.0.1
InputStreamFactory just isn’t called
alejandro.du
(Alejandro Duarte)
September 10, 2020, 9:57am
4
Did you try setting a height for the parent layout?
Valentin27
(Valentin Schuravlov)
September 10, 2020, 11:57am
5
Yes of course:
streamResource
= new StreamResource(customFile.getPdfFileName(), () -> convertService.getConvertedToPdfInputStream(customFile));
pdfBrowserViewer = new PdfBrowserViewer(streamResource);
pdfBrowserViewer.setHeight("100%");
pdfBrowserViewer.setWidth("100%");
panel.setHeightFull();
panel.add(pdfBrowserViewer);
The method getConvertedToPdfInputStream() method is not called.
With version 1.0.0-alpha/1.0.0-alpha1 works fine
alejandro.du
(Alejandro Duarte)
September 10, 2020, 2:56pm
6
Ah sorry, I think the problem in your app is different to the one in the first question of this thread.
alejandro.du
(Alejandro Duarte)
September 10, 2020, 2:58pm
7
Are you able to provide the full source code?
Valentin27
(Valentin Schuravlov)
September 10, 2020, 3:08pm
8
The complete code is quite large. You are right, I will do a small test and send it with the result
Valentin27
(Valentin Schuravlov)
September 11, 2020, 8:47am
9
Code:
public class CustomFileDemo extends VerticalLayout {
public static final String route = "customFileUploadOnDemand";
public CustomFileDemo() {
log.info("CustomFileDemo - start");
this.setSizeFull();
StreamResource streamResource = new StreamResource("AnyFile.pdf",
this::getInputStream);
PdfBrowserViewer pdfBrowserViewer = new PdfBrowserViewer(streamResource);
pdfBrowserViewer.setHeight("100%");
VerticalLayout previewPanel = new VerticalLayout();
previewPanel.setHeightFull();
previewPanel.setWidthFull();
previewPanel.add(new Label("Begin"), pdfBrowserViewer, new Label("End"));
this.add(previewPanel);
log.info("CustomFileDemo - initialized");
}
InputStream getInputStream() {
InputStream inputStream = null;
try {
inputStream = new FileInputStream("/Users/pathToPdf/Work/IntelliJ_WS/workbaskets/src/main/resources/111.pdf");
} catch (FileNotFoundException e) {
log.info("File not found");
e.printStackTrace();
}
log.info("File is here");
return inputStream;
}
}
It works nice with 1.0.0-alpha1 or 1.0.0-alpha.
In log:
10:31:02 [https-jsse-nio-9443-exec-2]
INFO d.x.w.filesCache.CustomFileDemo - CustomFileDemo - start
10:31:02 [https-jsse-nio-9443-exec-2]
INFO d.x.w.filesCache.CustomFileDemo - CustomFileDemo - initialized
10:31:02 [https-jsse-nio-9443-exec-2]
INFO d.x.w.commonUI.WorkbasketApp - WorkbasketApp. showRouterLayoutContent. contentLength: 0
10:31:02 [https-jsse-nio-9443-exec-2]
INFO d.x.w.commonUI.WorkbasketApp - WorkbasketApp. New content:
10:31:02 [https-jsse-nio-9443-exec-2]
WARN c.v.f.s.c.r.AbstractRpcInvocationHandler - Got an RPC for non-existent node: 11
10:31:02 [https-jsse-nio-9443-exec-10]
INFO d.x.w.filesCache.CustomFileDemo - File is here
but with 3.0.1 looks like that:
10:41:27 [https-jsse-nio-9443-exec-8]
INFO d.x.w.filesCache.CustomFileDemo - CustomFileDemo - start
10:41:27 [https-jsse-nio-9443-exec-8]
INFO d.x.w.filesCache.CustomFileDemo - CustomFileDemo - initialized
10:41:27 [https-jsse-nio-9443-exec-8]
INFO d.x.w.commonUI.WorkbasketApp - WorkbasketApp. showRouterLayoutContent. contentLength: 0
10:41:27 [https-jsse-nio-9443-exec-8]
INFO d.x.w.commonUI.WorkbasketApp - WorkbasketApp. New content:
10:41:27 [https-jsse-nio-9443-exec-8]
WARN c.v.f.s.c.r.AbstractRpcInvocationHandler - Got an RPC for non-existent node: 11
alejandro.du
(Alejandro Duarte)
September 11, 2020, 9:26am
10
Thanks for the code. Have you tried with getClass().getResourceAsStream("/report.pdf")
? The file should be located in the resources
directory. The getInputStream
method is actually called, so I wasn’t able to reproduce the issue.
Valentin27
(Valentin Schuravlov)
September 11, 2020, 2:39pm
11
I guess the problem is in the build tool - I am using gradle: