Search in sources :

Example 1 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet in project ACS by ACS-Community.

the class PrintUtil method printPDF.

//
//  -- PRIVATE METHODS ---------------------------------------------
//
private void printPDF(String name, Printable printable) {
    DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    aset.add(OrientationRequested.PORTRAIT);
    PrintService service = findPrinterService(flavor, aset);
    Assertion.assertTrue(service != null, "service != null");
    PrinterJob pj = PrinterJob.getPrinterJob();
    try {
        pj.setPrintService(service);
        pj.setPrintable(printable);
        pj.pageDialog(aset);
        pj.print(aset);
    } catch (PrinterException e) {
        Log log = LogFactory.getLog(PrintUtil.class);
        log.warn("The component " + name + " could not be printed");
    }
}
Also used : Log(org.apache.commons.logging.Log) PrinterException(java.awt.print.PrinterException) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintService(javax.print.PrintService) PrinterJob(java.awt.print.PrinterJob)

Example 2 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet in project jdk8u_jdk by JetBrains.

the class PageDlgApp method main.

public static void main(String[] args) throws Exception {
    String[] instructions = { "Visual inspection of the dialog is needed. ", "It should be a Printer Job Setup Dialog", "Do nothing except Cancel", "You must NOT press OK" };
    SwingUtilities.invokeAndWait(() -> {
        JOptionPane.showMessageDialog((Component) null, instructions, "information", JOptionPane.INFORMATION_MESSAGE);
    });
    PrinterJob pj = PrinterJob.getPrinterJob();
    PrintRequestAttributeSet pSet = new HashPrintRequestAttributeSet();
    pSet.add(DialogTypeSelection.NATIVE);
    if ((pj.pageDialog(pSet)) != null) {
        throw new RuntimeException("PrinterJob.pageDialog(PrintRequestAttributeSet)" + " does not return null when dialog is cancelled");
    }
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Example 3 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet in project jdk8u_jdk by JetBrains.

the class ImageableAreaTest method printWithCustomImageareaSize.

private static void printWithCustomImageareaSize() {
    final JTable table = createAuthorTable(18);
    PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
    printAttributes.add(DialogTypeSelection.NATIVE);
    printAttributes.add(new Copies(1));
    printAttributes.add(new MediaPrintableArea(0.25f, 0.25f, 8.0f, 5.0f, MediaPrintableArea.INCH));
    Printable printable = table.getPrintable(JTable.PrintMode.NORMAL, new MessageFormat("Author Table"), new MessageFormat("Page - {0}"));
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(printable);
    boolean printAccepted = job.printDialog(printAttributes);
    if (printAccepted) {
        try {
            job.print(printAttributes);
            closeFrame();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("User cancels the printer job!");
    }
}
Also used : MediaPrintableArea(javax.print.attribute.standard.MediaPrintableArea) MessageFormat(java.text.MessageFormat) Copies(javax.print.attribute.standard.Copies) JTable(javax.swing.JTable) Printable(java.awt.print.Printable) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterException(java.awt.print.PrinterException) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrinterJob(java.awt.print.PrinterJob)

Example 4 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet in project adempiere by adempiere.

the class PrintUtil method dump.

//	dump
/**
	 * 	Dump Stream Print Services
	 * 	@param docFlavor flavor
	 */
public static void dump(DocFlavor docFlavor) {
    System.out.println();
    System.out.println("DocFlavor=" + docFlavor);
    PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
    PrintService[] pss = PrintServiceLookup.lookupPrintServices(docFlavor, pras);
    for (int i = 0; i < pss.length; i++) {
        PrintService ps = pss[i];
        System.out.println("- " + ps);
        System.out.println("  Factory=" + ps.getServiceUIFactory());
        ServiceUIFactory uiF = pss[i].getServiceUIFactory();
        if (uiF != null) {
            System.out.println("about");
            JDialog about = (JDialog) uiF.getUI(ServiceUIFactory.ABOUT_UIROLE, ServiceUIFactory.JDIALOG_UI);
            about.setVisible(true);
            System.out.println("admin");
            JDialog admin = (JDialog) uiF.getUI(ServiceUIFactory.ADMIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
            admin.setVisible(true);
            System.out.println("main");
            JDialog main = (JDialog) uiF.getUI(ServiceUIFactory.MAIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
            main.setVisible(true);
            System.out.println("reserved");
            JDialog res = (JDialog) uiF.getUI(ServiceUIFactory.RESERVED_UIROLE, ServiceUIFactory.JDIALOG_UI);
            res.setVisible(true);
        }
        //
        DocFlavor[] dfs = pss[i].getSupportedDocFlavors();
        System.out.println("  - Supported Doc Flavors");
        for (int j = 0; j < dfs.length; j++) System.out.println("    -> " + dfs[j]);
        //	Attribute
        Class[] attCat = pss[i].getSupportedAttributeCategories();
        System.out.println("  - Supported Attribute Categories");
        for (int j = 0; j < attCat.length; j++) System.out.println("    -> " + attCat[j].getName() + " = " + pss[i].getDefaultAttributeValue((Class<? extends Attribute>) attCat[j]));
    //
    }
}
Also used : Attribute(javax.print.attribute.Attribute) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) JDialog(javax.swing.JDialog) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrintService(javax.print.PrintService) ServiceUIFactory(javax.print.ServiceUIFactory)

Example 5 with PrintRequestAttributeSet

use of javax.print.attribute.PrintRequestAttributeSet in project adempiere by adempiere.

the class CPaper method getPrintRequestAttributeSet.

//	pageSetupDialog
/**
	 *  Return Print Request Attributes
	 *  @return PrintRequestAttributeSet
	 */
public PrintRequestAttributeSet getPrintRequestAttributeSet() {
    PrintRequestAttributeSet pratts = new HashPrintRequestAttributeSet();
    //	media-printable-area = (25.4,25.4)->(165.1,228.6)mm - class javax.print.attribute.standard.MediaPrintableArea
    pratts.add(getMediaPrintableArea());
    //	orientation-requested = landscape - class javax.print.attribute.standard.OrientationRequested
    if (isLandscape())
        pratts.add(OrientationRequested.LANDSCAPE);
    else
        pratts.add(OrientationRequested.PORTRAIT);
    return pratts;
}
Also used : HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet)

Aggregations

PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)42 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)33 PrinterJob (java.awt.print.PrinterJob)17 PrintService (javax.print.PrintService)14 PageFormat (java.awt.print.PageFormat)12 PrinterException (java.awt.print.PrinterException)11 IOException (java.io.IOException)10 Copies (javax.print.attribute.standard.Copies)8 DocFlavor (javax.print.DocFlavor)7 Attribute (javax.print.attribute.Attribute)7 JobName (javax.print.attribute.standard.JobName)7 Printable (java.awt.print.Printable)6 DocPrintJob (javax.print.DocPrintJob)6 File (java.io.File)5 PrintException (javax.print.PrintException)5 SimpleDoc (javax.print.SimpleDoc)5 HeadlessException (java.awt.HeadlessException)4 Rectangle (java.awt.Rectangle)4 Paper (java.awt.print.Paper)4 Locale (java.util.Locale)3