Search in sources :

Example 31 with PageFormat

use of java.awt.print.PageFormat in project adempiere by adempiere.

the class PrintUtil method testPS.

//	dump
/*************************************************************************/
/**
	 * 	Test Print Services
	 */
private static void testPS() {
    PrintService ps = getDefaultPrintService();
    ServiceUIFactory factory = ps.getServiceUIFactory();
    System.out.println(factory);
    if (factory != null) {
        System.out.println("Factory");
        JPanel p0 = (JPanel) factory.getUI(ServiceUIFactory.ABOUT_UIROLE, ServiceUIFactory.JDIALOG_UI);
        p0.setVisible(true);
        JPanel p1 = (JPanel) factory.getUI(ServiceUIFactory.ADMIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
        p1.setVisible(true);
        JPanel p2 = (JPanel) factory.getUI(ServiceUIFactory.MAIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
        p2.setVisible(true);
    }
    System.out.println("1----------");
    PrinterJob pj = PrinterJob.getPrinterJob();
    PrintRequestAttributeSet pratts = getDefaultPrintRequestAttributes();
    //	Page Dialog
    PageFormat pf = pj.pageDialog(pratts);
    System.out.println("Pratts Size = " + pratts.size());
    Attribute[] atts = pratts.toArray();
    for (int i = 0; i < atts.length; i++) System.out.println(atts[i].getName() + " = " + atts[i] + " - " + atts[i].getCategory());
    System.out.println("PageFormat h=" + pf.getHeight() + ",w=" + pf.getWidth() + " - x=" + pf.getImageableX() + ",y=" + pf.getImageableY() + " - ih=" + pf.getImageableHeight() + ",iw=" + pf.getImageableWidth() + " - Orient=" + pf.getOrientation());
    ps = pj.getPrintService();
    System.out.println("PrintService = " + ps.getName());
    //	Print Dialog
    System.out.println("2----------");
    pj.printDialog(pratts);
    System.out.println("Pratts Size = " + pratts.size());
    atts = pratts.toArray();
    for (int i = 0; i < atts.length; i++) System.out.println(atts[i].getName() + " = " + atts[i] + " - " + atts[i].getCategory());
    pf = pj.defaultPage();
    System.out.println("PageFormat h=" + pf.getHeight() + ",w=" + pf.getWidth() + " - x=" + pf.getImageableX() + ",y=" + pf.getImageableY() + " - ih=" + pf.getImageableHeight() + ",iw=" + pf.getImageableWidth() + " - Orient=" + pf.getOrientation());
    ps = pj.getPrintService();
    System.out.println("PrintService= " + ps.getName());
    System.out.println("3----------");
    try {
        pj.setPrintService(ps);
    } catch (PrinterException pe) {
        System.out.println(pe);
    }
    pf = pj.validatePage(pf);
    System.out.println("PageFormat h=" + pf.getHeight() + ",w=" + pf.getWidth() + " - x=" + pf.getImageableX() + ",y=" + pf.getImageableY() + " - ih=" + pf.getImageableHeight() + ",iw=" + pf.getImageableWidth() + " - Orient=" + pf.getOrientation());
    ps = pj.getPrintService();
    System.out.println("PrintService= " + ps.getName());
    System.out.println("4----------");
    pj.printDialog();
}
Also used : JPanel(javax.swing.JPanel) PageFormat(java.awt.print.PageFormat) Attribute(javax.print.attribute.Attribute) PrinterException(java.awt.print.PrinterException) PrintService(javax.print.PrintService) ServiceUIFactory(javax.print.ServiceUIFactory) PrinterJob(java.awt.print.PrinterJob) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet)

Example 32 with PageFormat

use of java.awt.print.PageFormat in project adempiere by adempiere.

the class PrintUtil method dump.

//	getJobPriority
/*************************************************************************/
/**
	 * 	Dump Printer Job info
	 * 	@param job printer job
	 */
public static void dump(PrinterJob job) {
    StringBuffer sb = new StringBuffer(job.getJobName());
    sb.append("/").append(job.getUserName()).append(" Service=").append(job.getPrintService().getName()).append(" Copies=").append(job.getCopies());
    PageFormat pf = job.defaultPage();
    sb.append(" DefaultPage ").append("x=").append(pf.getImageableX()).append(",y=").append(pf.getImageableY()).append(" w=").append(pf.getImageableWidth()).append(",h=").append(pf.getImageableHeight());
    System.out.println(sb.toString());
}
Also used : PageFormat(java.awt.print.PageFormat)

Aggregations

PageFormat (java.awt.print.PageFormat)32 Paper (java.awt.print.Paper)12 PrinterException (java.awt.print.PrinterException)11 PrinterJob (java.awt.print.PrinterJob)10 PrintService (javax.print.PrintService)9 Printable (java.awt.print.Printable)6 PrintRequestAttributeSet (javax.print.attribute.PrintRequestAttributeSet)6 MediaSize (javax.print.attribute.standard.MediaSize)6 HeadlessException (java.awt.HeadlessException)5 StreamPrintService (javax.print.StreamPrintService)5 HashPrintRequestAttributeSet (javax.print.attribute.HashPrintRequestAttributeSet)5 Media (javax.print.attribute.standard.Media)5 Graphics2D (java.awt.Graphics2D)4 BufferedImage (java.awt.image.BufferedImage)4 File (java.io.File)4 MediaSizeName (javax.print.attribute.standard.MediaSizeName)4 OrientationRequested (javax.print.attribute.standard.OrientationRequested)4 AffineTransform (java.awt.geom.AffineTransform)3 Rectangle2D (java.awt.geom.Rectangle2D)3 IOException (java.io.IOException)3