Class PrintPdfButton

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.button.Button
org.vaadin.firitin.components.button.VButton
org.vaadin.firitin.components.button.PrintPdfButton
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.ClickNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.FocusNotifier<com.vaadin.flow.component.button.Button>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasText, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.orderedlayout.ThemableLayout, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.button.ButtonVariant>, com.vaadin.flow.component.shared.HasTooltip, Serializable, FluentAttachNotifier<VButton>, FluentBlurNotifier<com.vaadin.flow.component.button.Button, VButton>, FluentClickNotifier<com.vaadin.flow.component.button.Button, VButton>, FluentComponent<VButton>, FluentDetachNotifier<VButton>, FluentFocusable<com.vaadin.flow.component.button.Button, VButton>, FluentFocusNotifier<com.vaadin.flow.component.button.Button, VButton>, FluentHasEnabled<VButton>, FluentHasSize<VButton>, FluentHasStyle<VButton>, FluentHasText<VButton>, FluentHasTooltip<VButton>, FluentThemableLayout<VButton>, HasPadding<VButton>

public class PrintPdfButton extends VButton
A button that, when clicked, generates a PDF on the server and immediately opens the browser's native print dialog for it.

The PDF is produced by a PrintPdfButton.PdfWriterCallback supplied at construction time; implementations write PDF bytes to the given OutputStream. The bytes are streamed to a hidden <iframe> whose contentWindow.print() is invoked once loading completes -- the classic hidden-iframe print trick that web applications have used for decades.

A new iframe is created on every click and the previous one is removed first, so repeated prints do not accumulate DOM nodes.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Callback that writes a PDF document to an output stream.

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

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C>

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

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C>

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

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

    Constructors
    Constructor
    Description
    PrintPdfButton(String buttonText, PrintPdfButton.PdfWriterCallback pdfWriterCallback)
    Creates a print-PDF button with the given text label.
    Creates an icon-only print-PDF button showing the default VaadinIcon.PRINT icon.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    writePdf(PrintPdfButton.PdfWriterCallback pdfWriterCallback, com.vaadin.flow.server.VaadinResponse response)
    Writes the PDF response served to the hidden iframe.

    Methods inherited from class com.vaadin.flow.component.button.Button

    addBlurListener, addFocusListener, addFocusShortcut, bindEnabled, bindText, click, clickInClient, getIcon, getText, isAutofocus, isDisableOnClick, isIconAfterText, remove, setAutofocus, setDisableOnClick, setEnabled, setIcon, setIconAfterText, setText

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

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

    Methods inherited from class 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.BlurNotifier

    addBlurListener

    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 FluentAttachNotifier

    withAttachListener

    Methods inherited from interface FluentBlurNotifier

    withBlurListener

    Methods inherited from interface FluentClickNotifier

    withClickListener

    Methods inherited from interface FluentComponent

    navigate, setId, setVisible, withId, withVisible

    Methods inherited from interface FluentDetachNotifier

    withDetachListener

    Methods inherited from interface FluentFocusable

    withTabIndex

    Methods inherited from interface FluentFocusNotifier

    withFocusListener

    Methods inherited from interface FluentHasEnabled

    withEnabled

    Methods inherited from interface FluentHasStyle

    getStyle, withAddedClassName, withClassName, withStyle

    Methods inherited from interface FluentHasText

    withText

    Methods inherited from interface FluentHasTooltip

    withTooltip

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

    addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndex

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

    addFocusListener

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

    getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledBy

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

    getElement

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

    bindEnabled, isEnabled, setEnabled

    Methods inherited from interface com.vaadin.flow.component.shared.HasPrefix

    getPrefixComponent, setPrefixComponent

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

    bindHeight, bindWidth, 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, bindClassName, bindClassNames, getClassName, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.shared.HasSuffix

    getSuffixComponent, setSuffixComponent

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

    bindText, getText, getWhiteSpace, setText, setWhiteSpace

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

    addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, bindThemeVariant, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariants

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipMarkdown, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.orderedlayout.ThemableLayout

    getBoxSizing, getSpacing, getThemeList, isMargin, isPadding, isSpacing, isWrap, setBoxSizing, setMargin, setPadding, setSpacing, setSpacing, setSpacing, setWrap
  • Constructor Details

    • PrintPdfButton

      public PrintPdfButton(String buttonText, PrintPdfButton.PdfWriterCallback pdfWriterCallback)
      Creates a print-PDF button with the given text label. The default printer icon is removed.
      Parameters:
      buttonText - the button label
      pdfWriterCallback - invoked on click to write PDF bytes to the response output stream
    • PrintPdfButton

      public PrintPdfButton(PrintPdfButton.PdfWriterCallback pdfWriterCallback)
      Creates an icon-only print-PDF button showing the default VaadinIcon.PRINT icon.
      Parameters:
      pdfWriterCallback - invoked on click to write PDF bytes to the response output stream
  • Method Details

    • writePdf

      protected void writePdf(PrintPdfButton.PdfWriterCallback pdfWriterCallback, com.vaadin.flow.server.VaadinResponse response) throws IOException
      Writes the PDF response served to the hidden iframe. Sets the application/pdf content type and delegates payload generation to the supplied PrintPdfButton.PdfWriterCallback.

      Subclasses can override this to set additional response headers (for example Content-Disposition to influence the suggested filename) or to wrap the output stream.

      Parameters:
      pdfWriterCallback - the callback that produces the PDF bytes
      response - the Vaadin response to write to
      Throws:
      IOException - if writing to the response fails