Class PdfViewer

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.HtmlComponent
com.vaadin.flow.component.HtmlContainer
com.vaadin.flow.component.html.Div
com.vaadin.componentfactory.pdfviewer.PdfViewer
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.html.Div>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasOrderedComponents, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, Serializable

@Tag("vcf-pdf-viewer") @NpmPackage(value="@vaadin-component-factory/vcf-pdf-viewer",version="4.0.1") @NpmPackage(value="print-js",version="1.6.0") @JsModule("@vaadin-component-factory/vcf-pdf-viewer/vcf-pdf-viewer.js") @JsModule("./src/pdf-print.js") @CssImport(value="./styles/toolbar-button.css",themeFor="vaadin-button") @CssImport("print-js/dist/print.css") public class PdfViewer extends com.vaadin.flow.component.html.Div
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasText

    com.vaadin.flow.component.HasText.WhiteSpace
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addThumbnailClickedListener(com.vaadin.flow.component.ComponentEventListener<ThumbnailClickedEvent> listener)
    Adds a listener for ThumbnailClickedEvent to the component.
    void
    Closes thumbnails view.
     
     
    Returns the tooltip text defined for the download button.
    Returns the tooltip text defined for the next page button.
    Returns the tooltip text defined for the previous page button.
    Returns the tooltip text defined for the print button.
    Returns the tooltip text defined for the rotate clockwise button.
    Returns the tooltip text defined for the rotate counterclockwise button.
    Returns the tooltip text defined for the sidebar toggle button.
     
     
    void
    hideZoom(boolean hideZoom)
    Sets the flag to indicate if zoom options dropdown should be visible or not.
    boolean
    Returns whether download button is added to the toolbar or not.
    boolean
    Returns whether print button is added to the toolbar or not.
    boolean
    Returns whether Rotate Clockwise button is added to the toolbar or not.
    boolean
    Returns whether Rotate Counterclockwise button is added to the toolbar or not.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    protected void
    onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
     
    void
    Opens thumbnails view.
    void
    setAddDownloadButton(boolean addDownloadButton)
    Sets the flag to indicate if download button should be added or not.
    void
    setAddPrintButton(boolean addPrintButton)
    Sets the flag to indicate if print button should be added to toolbar or not.
    void
    setAddRotateClockwiseButton(boolean addRotateClockwiseButton)
    Sets the flag to indicate if Rotate Clockwise button should be added to toolbar or not.
    void
    setAddRotateCounterClockwiseButton(boolean addRotateCounterClockwiseButton)
    Sets the flag to indicate if Rotate Counterclockwise button should be added to toolbar or not.
    void
    setAutoZoomOptionLabel(String autoZoomOptionLabel)
    Sets the auto zoom option label.
    void
    setCustomTitle(String customTitle)
    Sets a custom title for the viewer.
    void
    setDownloadButtonTooltipText(String downloadButtonTooltipText)
    Sets tooltip text for the download button in toolbar.
    void
    setNextPageTooltipText(String nextPageTooltipText)
    Sets tooltip text for the next page button in toolbar.
    void
    setPage(Integer currentPage)
    Sets the current page of the rendered pdf file.
    void
    setPageFitZoomOptionLabel(String fitZoomOptionLabel)
    Sets the page fit zoom option label.
    void
    setPreviousPageTooltipText(String previousPageTooltipText)
    Sets a tooltip text for the previous page button in toolbar.
    void
    setPrintButtonTooltipText(String printButtonTooltipText)
    Sets tooltip text for the print button in toolbar.
    void
    setRenderInteractiveForms(boolean renderInteractiveForms)
    Sets the flag to indicate how to render interactive forms.
    void
    setRotateClockwiseButtonTooltipText(String rotateClockwiseButtonTooltipText)
    Sets tooltip text for the rotate clockwise button in toolbar.
    void
    setRotateCounterClockwiseButtonTooltipText(String rotateCounterClockwiseButtonTooltipText)
    Sets tooltip text for the rotate counterclockwise button in toolbar.
    void
    setSidebarToggleTooltipText(String sidebarToggleTooltipText)
    Sets tooltip text for the sidebar toogle button in toolbar.
    void
    setSrc(com.vaadin.flow.server.AbstractStreamResource src)
    Deprecated, for removal: This API element is subject to removal in a future version.
    void
    setSrc(com.vaadin.flow.server.streams.DownloadHandler downloadHandler)
    Sets a pdf file to render as a DownloadHandler.
    void
    Sets a pdf file to render.
    void
    Sets the level of zoom on the rendered pdf file.
    void
    showFilenameOnly(boolean filenameOnly)
    Indicates if toolbar should only show filename as title or default title.

    Methods inherited from class com.vaadin.flow.component.HtmlComponent

    getTitle, setTitle

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.ClickNotifier

    addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasComponents

    add, add, add, addComponentAsFirst, addComponentAtIndex, remove, remove, removeAll

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasEnabled

    isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.HasOrderedComponents

    getChildren, getComponentAt, getComponentCount, indexOf, replace

    Methods inherited from interface com.vaadin.flow.component.HasSize

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.HasText

    getText, getWhiteSpace, setText, setWhiteSpace
  • Constructor Details

    • PdfViewer

      public PdfViewer()
  • Method Details

    • getSrc

      public String getSrc()
      Returns:
      url to source file
    • setSrc

      public void setSrc(String src)
      Sets a pdf file to render.
      Parameters:
      src - url to file
    • setSrc

      @Deprecated(since="5.0.0", forRemoval=true) public void setSrc(com.vaadin.flow.server.AbstractStreamResource src)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets a pdf file to render as a StreamResource.

      Example: StreamResource resource = new StreamResource("mypdf.pdf", () -&gt; getPdfInputStream("mypdf.pdf");

      Parameters:
      src - stream to file
    • setSrc

      public void setSrc(com.vaadin.flow.server.streams.DownloadHandler downloadHandler)
      Sets a pdf file to render as a DownloadHandler.

      Example: DownloadHandler.forClassResource(getClass(), "mypdf.pdf")

      Since:
      5.0.0
    • getZoom

      public String getZoom()
      Returns:
      current zoom level
    • setZoom

      public void setZoom(String zoom)
      Sets the level of zoom on the rendered pdf file.

      Allowed values are - Number: for zoom percentage (e.g. 1.5 means 150% zoom). - 'auto': default value. - 'page-fit': fit a full page into component.

      Parameters:
      zoom - zoom level
    • addThumbnailClickedListener

      public void addThumbnailClickedListener(com.vaadin.flow.component.ComponentEventListener<ThumbnailClickedEvent> listener)
      Adds a listener for ThumbnailClickedEvent to the component.
      Parameters:
      listener - the listener to be added
    • openThumbnailsView

      public void openThumbnailsView()
      Opens thumbnails view.
    • closeThumbnailsView

      public void closeThumbnailsView()
      Closes thumbnails view.
    • getCurrentPage

      @Synchronize("currentPage-changed") public String getCurrentPage()
      Returns:
      current page on viewer
    • setPage

      public void setPage(Integer currentPage)
      Sets the current page of the rendered pdf file.
      Parameters:
      currentPage - current page number
    • showFilenameOnly

      public void showFilenameOnly(boolean filenameOnly)
      Indicates if toolbar should only show filename as title or default title. By default is set to false, so default title will be display if not specified otherwise.

      Conditions:

      • Pdf file should have a filename.
      • This flag should be set on pdf viewer initialization time. It cannot be updated dynamically.
      Parameters:
      filenameOnly - if true, toolbar only shows filename as title
    • setAutoZoomOptionLabel

      public void setAutoZoomOptionLabel(String autoZoomOptionLabel)

      Sets the auto zoom option label.

      This property should be set on pdf viewer initialization time. It cannot be updated dynamically.

      Parameters:
      autoZoomOptionLabel - auto zoom option label
    • setPageFitZoomOptionLabel

      public void setPageFitZoomOptionLabel(String fitZoomOptionLabel)

      Sets the page fit zoom option label.

      This property should be set on pdf viewer initialization time. It cannot be updated dynamically.

      Parameters:
      fitZoomOptionLabel - page fit zoom option label
    • isAddDownloadButton

      public boolean isAddDownloadButton()
      Returns whether download button is added to the toolbar or not.
      Returns:
      true if download button is added
    • setAddDownloadButton

      public void setAddDownloadButton(boolean addDownloadButton)

      Sets the flag to indicate if download button should be added or not. By default the flag is set to true, so download button is always added to the toolbar.

      This flag should be set on pdf viewer initialization time. It cannot be updated dynamically.

      Parameters:
      addDownloadButton - true if download button should be added
    • getCustomTitle

      public String getCustomTitle()
      Returns:
      custom title
    • setCustomTitle

      public void setCustomTitle(String customTitle)

      Sets a custom title for the viewer. If this value is set, it will ignore the filename and the metadata title of the pdf file.

      This value should be set on pdf viewer initialization time. It cannot be updated dynamically.

      Parameters:
      customTitle -
    • isAddPrintButton

      public boolean isAddPrintButton()
      Returns whether print button is added to the toolbar or not.
      Returns:
      true if print button is added to toolbar
    • setAddPrintButton

      public void setAddPrintButton(boolean addPrintButton)

      Sets the flag to indicate if print button should be added to toolbar or not. By default the flag is set to false, so, by default print button is not added to the toolbar.

      This flag should be set on pdf viewer initialization time. It cannot be updated dynamically.

      Parameters:
      addPrintButton - true if print button should be added to toolbar
    • setRenderInteractiveForms

      public void setRenderInteractiveForms(boolean renderInteractiveForms)

      Sets the flag to indicate how to render interactive forms. Renders interactive form elements in the annotation layer (html) if true, renders values of form elements directly onto the canvas if false. By default the flag is set to true.

      This flag should be set on pdf viewer initialization time. It cannot be updated dynamically.

      Parameters:
      renderInteractiveForms -
    • hideZoom

      public void hideZoom(boolean hideZoom)

      Sets the flag to indicate if zoom options dropdown should be visible or not. By default the flag is set to false, so, the dropdown is always shown.

      This flag should be set on pdf viewer initialization time. It cannot be updated dynamically.

      Parameters:
      hideZoom - true to hide the zoom dropdown
    • setPreviousPageTooltipText

      public void setPreviousPageTooltipText(String previousPageTooltipText)
      Sets a tooltip text for the previous page button in toolbar.
      Parameters:
      previousPageTooltipText - text to show in tooltip
    • getPreviousPageTooltipText

      public String getPreviousPageTooltipText()
      Returns the tooltip text defined for the previous page button.
      Returns:
      the previous page button tooltip text
    • setNextPageTooltipText

      public void setNextPageTooltipText(String nextPageTooltipText)
      Sets tooltip text for the next page button in toolbar.
      Parameters:
      nextPageTooltipText - text to show in tooltip
    • getNextPageTooltipText

      public String getNextPageTooltipText()
      Returns the tooltip text defined for the next page button.
      Returns:
      the next page button tooltip text
    • setSidebarToggleTooltipText

      public void setSidebarToggleTooltipText(String sidebarToggleTooltipText)
      Sets tooltip text for the sidebar toogle button in toolbar.
      Parameters:
      sidebarToggleTooltipText - text to show in tooltip
    • getSidebarToggleTooltipText

      public String getSidebarToggleTooltipText()
      Returns the tooltip text defined for the sidebar toggle button.
      Returns:
      the sidebar toggle button tooltip text
    • setPrintButtonTooltipText

      public void setPrintButtonTooltipText(String printButtonTooltipText)
      Sets tooltip text for the print button in toolbar.
      Parameters:
      printButtonTooltipText - the printButtonTooltipText to set
    • getPrintButtonTooltipText

      public String getPrintButtonTooltipText()
      Returns the tooltip text defined for the print button.
      Returns:
      the print button tooltip text
    • setDownloadButtonTooltipText

      public void setDownloadButtonTooltipText(String downloadButtonTooltipText)
      Sets tooltip text for the download button in toolbar.
      Parameters:
      downloadButtonTooltipText - the downloadButtonTooltipText to set
    • getDownloadButtonTooltipText

      public String getDownloadButtonTooltipText()
      Returns the tooltip text defined for the download button.
      Returns:
      the download button tooltip text
    • isAddRotateClockwiseButton

      public boolean isAddRotateClockwiseButton()
      Returns whether Rotate Clockwise button is added to the toolbar or not.
      Returns:
      true if the button is added to toolbar
    • setAddRotateClockwiseButton

      public void setAddRotateClockwiseButton(boolean addRotateClockwiseButton)

      Sets the flag to indicate if Rotate Clockwise button should be added to toolbar or not. By default the flag is set to false, so, by default the button is not added to the toolbar.

      This flag should be set on pdf viewer initialization time.

      Parameters:
      addRotateClockwiseButton - true if rotate clockwise button should be added to toolbar
    • isAddRotateCounterClockwiseButton

      public boolean isAddRotateCounterClockwiseButton()
      Returns whether Rotate Counterclockwise button is added to the toolbar or not.
      Returns:
      true if the button is added to toolbar
    • setAddRotateCounterClockwiseButton

      public void setAddRotateCounterClockwiseButton(boolean addRotateCounterClockwiseButton)

      Sets the flag to indicate if Rotate Counterclockwise button should be added to toolbar or not. By default the flag is set to false, so, by default the button is not added to the toolbar.

      This flag should be set on pdf viewer initialization time.

      Parameters:
      addRotateCounterClockwiseButton - true if rotate counterclockwise button should be added to toolbar
    • setRotateClockwiseButtonTooltipText

      public void setRotateClockwiseButtonTooltipText(String rotateClockwiseButtonTooltipText)
      Sets tooltip text for the rotate clockwise button in toolbar.
      Parameters:
      rotateClockwiseButtonTooltipText - the rotateClockwiseButtonTooltipText to set
    • getRotateClockwiseButtonTooltipText

      public String getRotateClockwiseButtonTooltipText()
      Returns the tooltip text defined for the rotate clockwise button.
      Returns:
      the rotate clockwise button tooltip text
    • setRotateCounterClockwiseButtonTooltipText

      public void setRotateCounterClockwiseButtonTooltipText(String rotateCounterClockwiseButtonTooltipText)
      Sets tooltip text for the rotate counterclockwise button in toolbar.
      Parameters:
      rotateCounterClockwiseButtonTooltipText - the rotateCounterClockwiseButtonTooltipText to set
    • getRotateCounterClockwiseButtonTooltipText

      public String getRotateCounterClockwiseButtonTooltipText()
      Returns the tooltip text defined for the rotate counterclockwise button.
      Returns:
      the rotate counterclockwise button tooltip text
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • onDetach

      protected void onDetach(com.vaadin.flow.component.DetachEvent detachEvent)
      Overrides:
      onDetach in class com.vaadin.flow.component.Component