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>
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 ClassesModifier and TypeClassDescriptionstatic interfaceCallback that writes a PDF document to an output stream.Nested classes/interfaces inherited from class VButton
VButton.BasicClickListener, VButton.ButtonColor, VButton.ButtonSize, VButton.ButtonTypeNested 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
ConstructorsConstructorDescriptionPrintPdfButton(String buttonText, PrintPdfButton.PdfWriterCallback pdfWriterCallback) Creates a print-PDF button with the given text label.PrintPdfButton(PrintPdfButton.PdfWriterCallback pdfWriterCallback) Creates an icon-only print-PDF button showing the defaultVaadinIcon.PRINTicon. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidwritePdf(PrintPdfButton.PdfWriterCallback pdfWriterCallback, com.vaadin.flow.server.VaadinResponse response) Writes the PDF response served to the hidden iframe.Methods inherited from class VButton
addClickListener, getColor, getSize, getType, onClick, setColor, setSize, setType, withAutofocus, withClickShortcut, withColor, withIcon, withIconAfterText, withSize, withThemeVariants, withTypeMethods 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, setTextMethods 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, setVisibleMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.BlurNotifier
addBlurListenerMethods inherited from interface com.vaadin.flow.component.ClickNotifier
addClickListener, addClickShortcut, addDoubleClickListener, addSingleClickListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface FluentAttachNotifier
withAttachListenerMethods inherited from interface FluentBlurNotifier
withBlurListenerMethods inherited from interface FluentClickNotifier
withClickListenerMethods inherited from interface FluentComponent
navigate, setId, setVisible, withId, withVisibleMethods inherited from interface FluentDetachNotifier
withDetachListenerMethods inherited from interface FluentFocusable
withTabIndexMethods inherited from interface FluentFocusNotifier
withFocusListenerMethods inherited from interface FluentHasEnabled
withEnabledMethods inherited from interface FluentHasSize
addResizeListener, withFullHeight, withFullWidth, withHeight, withMaxHeight, withMaxSize, withMaxWidth, withMinHeight, withMinSize, withMinWidth, withSize, withSizeFull, withSizeUndefined, withWidthMethods inherited from interface FluentHasStyle
getStyle, withAddedClassName, withClassName, withStyleMethods inherited from interface FluentHasText
withTextMethods inherited from interface FluentHasTooltip
withTooltipMethods inherited from interface FluentThemableLayout
withBoxSizing, withMargin, withPadding, withSpacingMethods inherited from interface com.vaadin.flow.component.Focusable
addFocusShortcut, blur, focus, focus, getTabIndex, setTabIndexMethods inherited from interface com.vaadin.flow.component.FocusNotifier
addFocusListenerMethods inherited from interface com.vaadin.flow.component.HasAriaLabel
getAriaLabel, getAriaLabelledBy, setAriaLabel, setAriaLabelledByMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabledMethods inherited from interface HasPadding
setPadding, setPadding, setPadding, withPadding, withPadding, withPaddingMethods inherited from interface com.vaadin.flow.component.shared.HasPrefix
getPrefixComponent, setPrefixComponentMethods 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, setWidthFullMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, bindClassName, bindClassNames, getClassName, getClassNames, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameMethods inherited from interface com.vaadin.flow.component.shared.HasSuffix
getSuffixComponent, setSuffixComponentMethods inherited from interface com.vaadin.flow.component.HasText
bindText, getText, getWhiteSpace, setText, setWhiteSpaceMethods inherited from interface com.vaadin.flow.component.HasTheme
addThemeName, addThemeNames, bindThemeName, bindThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNameMethods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant
addThemeVariants, bindThemeVariant, removeThemeVariants, setThemeVariant, setThemeVariants, setThemeVariantsMethods inherited from interface com.vaadin.flow.component.shared.HasTooltip
getTooltip, setTooltipMarkdown, setTooltipTextMethods 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
Creates a print-PDF button with the given text label. The default printer icon is removed.- Parameters:
buttonText- the button labelpdfWriterCallback- invoked on click to write PDF bytes to the response output stream
-
PrintPdfButton
Creates an icon-only print-PDF button showing the defaultVaadinIcon.PRINTicon.- 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 theapplication/pdfcontent type and delegates payload generation to the suppliedPrintPdfButton.PdfWriterCallback.Subclasses can override this to set additional response headers (for example
Content-Dispositionto influence the suggested filename) or to wrap the output stream.- Parameters:
pdfWriterCallback- the callback that produces the PDF bytesresponse- the Vaadin response to write to- Throws:
IOException- if writing to the response fails
-