Directory

← Back

PdfThumbnails

Preview/Thumbnail of pdf files rendered within browser via pdf.js

Author

Contributors

Rating

Vaadin wrapper for pdfThumbnails that renders a preview for the first page of an pdf-document.

Allows to render embedded files + Vaadin-Resources...

Is a JavaScriptExtension so that no GWT-Rendering is needed.

Sample code

PdfThumbnail pdfThumbnail = new PdfThumbnail();
pdfThumbnail.setUrl("./VAADIN/pdf/example.pdf");
pdfThumbnail.setPreviewWidth(400);
pdfThumbnail.setWidth("300px");
pdfThumbnail.setHeight("300px");
layout.addComponent(pdfThumbnail);
PdfThumbnail pdfThumbnail = new PdfThumbnail();
pdfThumbnail.setResource(new DownloadStreamResource("https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"));
pdfThumbnail.setPreviewWidth(400);
pdfThumbnail.setWidth("300px");
pdfThumbnail.setHeight("300px");
layout.addComponent(pdfThumbnail);
    

public static class DownloadStreamResource extends StreamResource {

    private String url;

    public DownloadStreamResource(String url) {
        super((StreamSource) () -> {
            try {
                return new URL(url).openStream();
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }, "download.pdf");
    }
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

  • added link option
  • fixed setResource change to trigger repaint
Released
2020-02-13
Maturity
EXPERIMENTAL
License
MIT License

Compatibility

Framework
Vaadin 8.0+
Browser
N/A

PdfThumbnails - Vaadin Add-on Directory

Preview/Thumbnail of pdf files rendered within browser via pdf.js PdfThumbnails - Vaadin Add-on Directory
Vaadin wrapper for [pdfThumbnails](https://github.com/scandel/pdfThumbnails) that renders a preview for the first page of an pdf-document. Allows to render embedded files + Vaadin-Resources... Is a JavaScriptExtension so that no GWT-Rendering is needed.
Online