Java Printer Usage testSPS()

Here you can find the source of testSPS()

Description

Test Stream Print Services

License

Open Source License

Declaration

private static void testSPS() 

Method Source Code

//package com.java2s;
/******************************************************************************
 * Product: Adempiere ERP & CRM Smart Business Solution                       *
 * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.                *
 * This program is free software; you can redistribute it and/or modify it    *
 * under the terms version 2 of the GNU General Public License as published   *
 * by the Free Software Foundation. This program is distributed in the hope   *
 * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.           *
 * See the GNU General Public License for more details.                       *
 * You should have received a copy of the GNU General Public License along    *
 * with this program; if not, write to the Free Software Foundation, Inc.,    *
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.                     *
 * For the text or an alternative of this public license, you may reach us    *
 * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
 * or via info@compiere.org or http://www.compiere.org/license.html           *
 *****************************************************************************/

import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;

import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;

public class Main {
    /**//  w  w  w. j  a  v a 2  s  .c o m
     *    Test Stream Print Services
     */
    private static void testSPS() {
        //   dump (DocFlavor.INPUT_STREAM.GIF, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
        //   dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
        //   dump (DocFlavor.INPUT_STREAM.GIF, DocFlavor.BYTE_ARRAY.PDF.getMimeType());
        //   dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE, DocFlavor.BYTE_ARRAY.GIF.getMediaSubtype());
        //   dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE, DocFlavor.BYTE_ARRAY.JPEG.getMediaSubtype());

        //   dump (DocFlavor.SERVICE_FORMATTED.PAGEABLE);               //   lists devices able to output pageable
        //   dump (DocFlavor.SERVICE_FORMATTED.PRINTABLE);
        //   dump (DocFlavor.INPUT_STREAM.TEXT_PLAIN_HOST);
        //   dump (DocFlavor.INPUT_STREAM.POSTSCRIPT);

        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        PrintService[] pss = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, pras);
        for (int i = 0; i < pss.length; i++) {
            PrintService ps = pss[i];
            String name = ps.getName();
            if (name.indexOf("PDF") != -1 || name.indexOf("Acrobat") != -1) {
                System.out.println("----");
                System.out.println(ps);
                Class[] cat = ps.getSupportedAttributeCategories();
                for (int j = 0; j < cat.length; j++) {
                    System.out.println("- " + cat[j]);
                }
            }
        }

        //   dump (null, DocFlavor.BYTE_ARRAY.PDF.getMimeType());         //   lists PDF output
        //   dump (null, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMediaType());   //   lists PS output

        //   dump(null, null);
    }
}

Related

  1. lookupPrintServices()
  2. notInArray(PrintService key, PrintService[] array)
  3. print(PrintService printService, byte[] pdf)
  4. refreshPrinterList()
  5. showAttributes(PrintRequestAttributeSet aset)
  6. validateDPI(int dpi)