org.xhtmlrenderer.demo.browser.actions.PrintAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of flying-saucer-examples Show documentation
Show all versions of flying-saucer-examples Show documentation
Misc. Flying Saucer example code. It is not deployed with a release.
package org.xhtmlrenderer.demo.browser.actions;
import org.xhtmlrenderer.demo.browser.BrowserStartup;
import org.xhtmlrenderer.simple.XHTMLPrintable;
import org.xhtmlrenderer.util.Uu;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
public class PrintAction extends AbstractAction {
private final BrowserStartup root;
public PrintAction(BrowserStartup root, ImageIcon icon) {
super("Print", icon);
this.root = root;
}
public void actionPerformed(ActionEvent evt) {
final PrinterJob printJob = PrinterJob.getPrinterJob();
printJob.setPrintable(new XHTMLPrintable(root.panel.view));
if (printJob.printDialog()) {
new Thread(() -> {
try {
printJob.print();
} catch (PrinterException ex) {
Uu.p(ex);
}
}).start();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy