Example usage for javax.print.attribute.standard MediaSizeName ISO_A4

List of usage examples for javax.print.attribute.standard MediaSizeName ISO_A4

Introduction

In this page you can find the example usage for javax.print.attribute.standard MediaSizeName ISO_A4.

Prototype

MediaSizeName ISO_A4

To view the source code for javax.print.attribute.standard MediaSizeName ISO_A4.

Click Source Link

Document

A4 size.

Usage

From source file:Print.java

public static void main(String[] args) throws IOException {
    // These are values we'll set from the command-line arguments
    boolean query = false;
    String printerName = null;//from  ww  w.  j ava  2  s. co m
    String inputFileName = null;
    String outputFileName = null;
    String outputFileType = null;
    PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();

    // Loop through the arguments
    for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-q"))
            query = true; // Is this is query?
        else if (args[i].equals("-p")) // Specific printer name
            printerName = args[++i];
        else if (args[i].equals("-i")) // The file to print
            inputFileName = args[++i];
        else if (args[i].equals("-ps")) { // Print it to this file
            // Sun's Java 1.4 implementation only supports PostScript
            // output. Other implementations might offer PDF, for example.
            outputFileName = args[++i];
            outputFileType = "application/postscript";
        }
        // The rest of the arguments represent common printing attributes
        else if (args[i].equals("-color")) // Request a color printer
            attributes.add(Chromaticity.COLOR);
        else if (args[i].equals("-landscape")) // Request landscape mode
            attributes.add(OrientationRequested.LANDSCAPE);
        else if (args[i].equals("-letter")) // US Letter-size paper
            attributes.add(MediaSizeName.NA_LETTER);
        else if (args[i].equals("-a4")) // European A4 paper
            attributes.add(MediaSizeName.ISO_A4);
        else if (args[i].equals("-staple")) // Request stapling
            attributes.add(Finishings.STAPLE);
        else if (args[i].equals("-collate")) // Collate multiple copies
            attributes.add(SheetCollate.COLLATED);
        else if (args[i].equals("-duplex")) // Request 2-sided
            attributes.add(Sides.DUPLEX);
        else if (args[i].equals("-2")) // 2 pages to a sheet
            attributes.add(new NumberUp(2));
        else if (args[i].equals("-copies")) // how many copies
            attributes.add(new Copies(Integer.parseInt(args[++i])));
        else {
            System.out.println("Unknown argument: " + args[i]);
            System.exit(1);
        }
    }

    if (query) {
        // If the -q argument was specified, but no printer was named,
        // then list all available printers that can support the attributes
        if (printerName == null)
            queryServices(attributes);
        // Otherwise, look for a named printer that can support the
        // attributes and print its status
        else
            queryPrinter(printerName, attributes);
    } else if (outputFileName != null)
        // If this is not a query and we have a filename, print to a file
        printToFile(outputFileName, outputFileType, inputFileName, attributes);
    else
        // Otherwise, print to the named printer, or to the default
        // printer otherwise.
        print(printerName, inputFileName, attributes);

    // The main() method ends here, but there may be a printing thread
    // operating in the background. So the program may not terminate
    // until printing completes.
}

From source file:ru.trett.cis.services.PrinterServiceImpl.java

@Override
public String print(String file) throws ApplicationException, FileNotFoundException, PrintException {
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    PrintService printServices = PrintServiceLookup.lookupDefaultPrintService();
    if (printServices == null)
        throw new ApplicationException("Default printer not found");
    LOGGER.info("Default printer is " + printServices.getName());
    DocPrintJob printJob = printServices.createPrintJob();
    FileInputStream fis = new FileInputStream(file);
    Doc doc = new SimpleDoc(fis, flavor, null);
    printJob.print(doc, aset);/*from w ww.  ja  v  a  2s. com*/
    return printServices.getName();
}

From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java

private static void print(PrintService printService, byte[] pdf) throws PrintException {
    final DocPrintJob job = printService.createPrintJob();
    final Doc doc = new SimpleDoc(pdf, DocFlavor.BYTE_ARRAY.PDF, null);

    final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(new Copies(1));
    aset.add(MediaSizeName.ISO_A4);
    aset.add(Sides.ONE_SIDED);/*from  w w w. j  av a 2  s .  c o  m*/

    job.print(doc, aset);
}

From source file:com.aw.core.report.ReportFileGenerator.java

public String generateAndPrint(String reportName, Map params, String tempDirectory, Connection conn)
        throws JRException {
    // force temp directory end with "/"
    //        tempDirectory = formatDirectory(tempDirectory);
    //        String fullOutFileName = generateFile(conn);
    //        String fullPdfFileName = fullOutFileName + ".pdf";
    //        JasperExportManager.exportReportToPdfFile(fullOutFileName, fullPdfFileName);

    //Report loading and compilation
    //        JasperDesign jasperDesign = JRXmlLoader.load(compiledReport);
    //        JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);

    // - Report execution

    //        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);

    try {// w  w w.ja v a 2 s .co m
        // - Report creation to printer
        PrinterJob job = PrinterJob.getPrinterJob();
        DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; // This is the Flavour JasperReports uses

        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
        aset.add(MediaSizeName.ISO_A4); // ..or whatever the document size is

        PrintService service = null;
        if (job.printDialog(aset))
            service = job.getPrintService();

        InputStream jasperReport = new FileInputStream("C:/ProgFile/iReport-2.0.2/CorrelativoDocumento.jasper");
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, conn);

        // Export the report using the JasperPrint instance
        JRExporter exporter = new JRPrintServiceExporter();
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
        exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
                service.getAttributes());
        exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
        exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);

        exporter.exportReport();

        //            String fullPdfFileName = "D:\\test.pdf";
        //            JasperExportManager.exportReportToPdfFile(jasperPrint, fullPdfFileName);

        return null;
    } catch (FileNotFoundException e) {
        throw AWBusinessException.wrapUnhandledException(logger, e);
    }

}

From source file:net.sourceforge.fenixedu.util.report.ReportsUtils.java

static private PrintRequestAttributeSet createPrintRequestAttributeSet(int width, int height) {
    final PrintRequestAttributeSet result = new HashPrintRequestAttributeSet();

    result.add(MediaSizeName.ISO_A4);
    result.add(OrientationRequested.PORTRAIT);
    result.add(new MediaPrintableArea(0, 0, width, height, MediaPrintableArea.MM));

    return result;
}

From source file:com.sos.jitl.jasperreports.JobSchedulerJasperReportJob.java

/**
 * Dokument drucken./*from  w ww .ja va 2s.  c  o m*/
 * 
 * @throws Exception
 */
private String printDocument() throws Exception {
    try {
        //         druckername bestimmen
        String prName = getPrinter();
        if (sosString.parseToString(prName).length() > 0) {
            JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(filledReportFile);
            net.sf.jasperreports.engine.export.JRPrintServiceExporter exporter = new net.sf.jasperreports.engine.export.JRPrintServiceExporter();
            //            set the report to print
            exporter.setParameter(
                    net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.JASPER_PRINT,
                    jasperPrint);
            //            count of report to print            
            javax.print.attribute.PrintRequestAttributeSet aset = new javax.print.attribute.HashPrintRequestAttributeSet();
            aset.add(new Copies(getPrinterCopies()));
            aset.add(MediaSizeName.ISO_A4);
            exporter.setParameter(
                    net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET,
                    aset);
            //            let the exporter know which printer we want to print on
            javax.print.attribute.PrintServiceAttributeSet serviceAttributeSet = new javax.print.attribute.HashPrintServiceAttributeSet();
            serviceAttributeSet.add(new javax.print.attribute.standard.PrinterName(prName, null));
            exporter.setParameter(
                    net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET,
                    serviceAttributeSet);
            //            print it
            exporter.exportReport();
            spooler_log.info("..report successfully printed " + getPrinterCopies() + "x.");
            return "..report successfully printed " + getPrinterCopies() + "x.";
        }
        return "";
    } catch (Exception e) {
        throw new Exception("..error in " + SOSClassUtil.getMethodName() + " " + e);
    }
}

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

private static MediaSize lookupMediaSize(final Media media) {

    if (media instanceof MediaSizeName) {
        return MediaSize.getMediaSizeForName((MediaSizeName) media);
    } else if (media instanceof MediaName) {
        if (media.equals(MediaName.ISO_A4_TRANSPARENT) || media.equals(MediaName.ISO_A4_WHITE)) {
            return MediaSize.getMediaSizeForName(MediaSizeName.ISO_A4);
        } else if (media.equals(MediaName.NA_LETTER_TRANSPARENT) || media.equals(MediaName.NA_LETTER_WHITE)) {
            return MediaSize.getMediaSizeForName(MediaSizeName.NA_LETTER);
        }/*from  www  .  java2  s. c  o m*/
    }
    return null;
}