Package java.awt.print

Examples of java.awt.print.PrinterJob


        );
    }

    pageOffset = firstPageIndex;

    PrinterJob printJob = PrinterJob.getPrinterJob();

    // fix for bug ID 6255588 from Sun bug database
    initPrinterJobFields(printJob);
   
    PageFormat pageFormat = printJob.defaultPage();
    Paper paper = pageFormat.getPaper();

    printJob.setJobName("JasperReports - " + jasperPrint.getName());
   
    switch (jasperPrint.getOrientation())
    {
      case JRReport.ORIENTATION_LANDSCAPE :
      {
        pageFormat.setOrientation(PageFormat.LANDSCAPE);
        paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
        paper.setImageableArea(
          0,
          0,
          jasperPrint.getPageHeight(),
          jasperPrint.getPageWidth()
          );
        break;
      }
      case JRReport.ORIENTATION_PORTRAIT :
      default :
      {
        pageFormat.setOrientation(PageFormat.PORTRAIT);
        paper.setSize(jasperPrint.getPageWidth(), jasperPrint.getPageHeight());
        paper.setImageableArea(
          0,
          0,
          jasperPrint.getPageWidth(),
          jasperPrint.getPageHeight()
          );
      }
    }

    pageFormat.setPaper(paper);

    Book book = new Book();
    book.append(this, pageFormat, lastPageIndex - firstPageIndex + 1);
    printJob.setPageable(book);
    try
    {
                    if (service == null) {
                        if (printJob.printDialog()) {
                            printJob.print();
                        }
                    } else {
                        printJob.setPrintService(service);
                        printJob.print();
                    }
    }
    catch (Exception ex)
    {
      throw new JRException("Error printing report.", ex);
View Full Code Here


    /**
     * Prints the document and closes it.
     */
    public static void closePrintDocument(PrintDocument doc){
        defaultPrintOptions = null;
        PrinterJob printJob = getPrinterJob();
        printJob.setPageable(doc);
        try {
            printJob.print();
            printDoc = null;
        } catch(PrinterException pe) {
            RuntimeException errorVar = new RuntimeException(pe.getMessage(), pe);
            ErrorMgr.addError(errorVar);
            throw errorVar;
View Full Code Here

     */
    public static PrintOptionsDesc getDefaultPrintOptions() {
        if (defaultPrintOptions == null) {
          defaultPrintOptions = new PrintOptionsDesc();
        }
        PrinterJob pjob = PrinterJob.getPrinterJob();
        PageFormat defaultPage = pjob.defaultPage();
        Paper paper = new Paper();
        double imagableWidth = defaultPage.getPaper().getWidth() - (defaultPrintMargin * 2);
        double imagableHeight = defaultPage.getPaper().getHeight() - (defaultPrintMargin * 2);
       
        // Swap the width and height if in landscape mode
View Full Code Here

    public PrintSetupActionListener() {
        super();
    }

    public void actionPerformed(ActionEvent e) {
        PrinterJob pjob = PrinterJob.getPrinterJob();

        // Get and change default page format settings if necessary.
        PageFormat pf = pjob.defaultPage();
       
        // Set the default options.  CraigM: 31/03/2008.
        pf.setOrientation(PrintUtilities.getDefaultPrintOptions().getOrientation());
        pf.setPaper(PrintUtilities.getDefaultPrintOptions().getPaper());

        // Show page format dialog with page format settings.
        pf = pjob.pageDialog(pf);
       
        // Update the default options.  CraigM: 31/03/2008.
        PrintUtilities.getDefaultPrintOptions().setOrientation(pf.getOrientation());
        PrintUtilities.getDefaultPrintOptions().setPaper(pf.getPaper());
    }
View Full Code Here

                                boolean success = true;
                                String  message = "";

                                try {
                                        PrinterJob printer = PrinterJob.getPrinterJob();
                                        PageFormat pageFormat = new PageFormat();
                                        printer.pageDialog(pageFormat);
                                        PageableText pageableText;
                                        try {
                                                pageableText = new PageableText(new File(reportFilename), pageFormat);
                                                printer.setPageable(pageableText);
                                                printer.print();
                                        } catch (IOException ex) {
                                                success = false;
                                                message = ex.getMessage();
                                        }
                                } catch (PrinterException ex) {
View Full Code Here

         * @throws IOException
         * @throws PrinterException
         */
        public static void main(String[] args) throws IOException, PrinterException {
                // Get the PrinterJob object that coordinates everything
                PrinterJob job = PrinterJob.getPrinterJob();

                // Get the default page format, then ask the user to customize it
                PageFormat format = job.pageDialog(job.defaultPage());

                // Create our PageableText object, and tell the PrinterJob about it
                job.setPageable(new PageableText(new File(args[0]), format));

                // Ask the user to select a printer, etc., and if not canceled, print!
                if (job.printDialog()) {
                        job.print();
                }
        }
View Full Code Here

                                boolean success = true;
                                String  message = "";


                                try {
                                        PrinterJob printer = PrinterJob.getPrinterJob();
                                        PageFormat pageFormat = new PageFormat();
                                        printer.pageDialog(pageFormat);
                                        PageableText pageableText;
                                        try {
                                                pageableText = new PageableText(new File(reportFilename), pageFormat);
                                                printer.setPageable(pageableText);
                                                printer.print();
                                        } catch (IOException ex) {
                                                success = false;
                                                message = ex.getMessage();
                                        }
                                } catch (PrinterException ex) {
View Full Code Here

    private void jmniPrintVMActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jmniPrintVMActionPerformed
    {//GEN-HEADEREND:event_jmniPrintVMActionPerformed

        if (getAktuelleBasis() != null)
        {
            PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.setPrintable(getVMObject());
            if (printJob.printDialog())
            {
                try
                {
                    printJob.print();
                } catch (PrinterException pe)
                {
                    System.out.println("Error printing: " + pe);
                }
            }
View Full Code Here

    /**
     * Prints the document and closes it.
     */
    public static void closePrintDocument(PrintDocument doc){
        defaultPrintOptions = null;
        PrinterJob printJob = getPrinterJob();
        printJob.setPageable(doc);
        try {
            printJob.print();
            printDoc = null;
        } catch(PrinterException pe) {
            RuntimeException errorVar = new RuntimeException(pe.getMessage(), pe);
            ErrorMgr.addError(errorVar);
            throw errorVar;
View Full Code Here

     */
    public static PrintOptionsDesc getDefaultPrintOptions() {
        if (defaultPrintOptions == null) {
          defaultPrintOptions = new PrintOptionsDesc();
        }
        PrinterJob pjob = PrinterJob.getPrinterJob();
        PageFormat defaultPage = pjob.defaultPage();
        Paper paper = new Paper();
        double imagableWidth = defaultPage.getPaper().getWidth() - (defaultPrintMargin * 2);
        double imagableHeight = defaultPage.getPaper().getHeight() - (defaultPrintMargin * 2);
       
        // Swap the width and height if in landscape mode
View Full Code Here

TOP

Related Classes of java.awt.print.PrinterJob

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.