Example usage for javax.print.attribute HashPrintRequestAttributeSet HashPrintRequestAttributeSet

List of usage examples for javax.print.attribute HashPrintRequestAttributeSet HashPrintRequestAttributeSet

Introduction

In this page you can find the example usage for javax.print.attribute HashPrintRequestAttributeSet HashPrintRequestAttributeSet.

Prototype

public HashPrintRequestAttributeSet() 

Source Link

Document

Construct a new, empty print request attribute set.

Usage

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);//w w w. ja  v a 2 s .  c om

    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 . j a v  a  2 s. c  o  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:de.cenote.jasperstarter.Report.java

public void print() throws JRException {
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    //printRequestAttributeSet.add(MediaSizeName.ISO_A4);
    if (config.hasCopies()) {
        printRequestAttributeSet.add(new Copies(config.getCopies().intValue()));
    }/*from  w ww.j  ava 2 s .  c  o m*/
    PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
    //printServiceAttributeSet.add(new PrinterName("Fax", null));
    JRPrintServiceExporter exporter = new JRPrintServiceExporter();
    if (config.hasReportName()) {
        jasperPrint.setName(config.getReportName());
    }
    exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
    SimplePrintServiceExporterConfiguration expConfig = new SimplePrintServiceExporterConfiguration();
    if (config.hasPrinterName()) {
        String printerName = config.getPrinterName();
        PrintService service = Printerlookup.getPrintservice(printerName, Boolean.TRUE, Boolean.TRUE);
        expConfig.setPrintService(service);
        if (config.isVerbose()) {
            System.out.println("printer-name: "
                    + ((service == null) ? "No printer found with name \"" + printerName + "\"! Using default."
                            : "found: " + service.getName()));
        }
    }
    //exporter.setParameter(JRExporterParameter.PAGE_INDEX, pageIndex);
    //exporter.setParameter(JRExporterParameter.START_PAGE_INDEX, pageStartIndex);
    //exporter.setParameter(JRExporterParameter.END_PAGE_INDEX, pageEndIndex);
    expConfig.setPrintRequestAttributeSet(printRequestAttributeSet);
    expConfig.setPrintServiceAttributeSet(printServiceAttributeSet);
    expConfig.setDisplayPageDialog(Boolean.FALSE);
    if (config.isWithPrintDialog()) {
        setLookAndFeel();
        expConfig.setDisplayPrintDialog(Boolean.TRUE);
    } else {
        expConfig.setDisplayPrintDialog(Boolean.FALSE);
    }
    exporter.setConfiguration(expConfig);
    exporter.exportReport();
}

From source file:org.martus.client.swingui.actions.ActionMenuCharts.java

private boolean printToPrinter(JFreeChart chart) throws PrinterException {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable(new PrintableChart(chart));
    HashPrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
    removeJavaLogoFromTitle(attributes);
    if (!printJob.printDialog(attributes))
        return false;

    printJob.print(attributes);//from  w w  w  .java2  s  .  co  m
    return true;
}

From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java

/**
 * @param actionableTree//from  w ww.  ja  va  2s  . c  o  m
 */
public void print(final JTree actionableTree) {
    /*if (true)
    {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(OrientationRequested.LANDSCAPE);
    aset.add(new Copies(2));
    aset.add(new JobName("My job", null));
            
    // Create a print job 
    PrinterJob pj = PrinterJob.getPrinterJob();       
    pj.setPrintable(this);
    // locate a print service that can handle the request 
    PrintService[] services =
        PrinterJob.lookupPrintServices();
            
    if (services.length > 0) {
        System.out.println("selected printer " + services[0].getName());
        try {
            pj.setPrintService(services[0]);
            pj.pageDialog(aset);
            if(pj.printDialog(aset)) {
                pj.print(aset);
            }
        } catch (PrinterException pe) { 
            System.err.println(pe);
        }
    }
    return;
    }*/

    DefaultMutableTreeNode clonedTree = GhostActionableTree
            .makeDeepCopy((DefaultMutableTreeNode) actionableTree.getModel().getRoot());
    GhostActionableTree printTree = new GhostActionableTree(this, new DefaultTreeModel(clonedTree));
    printTree.setRowHeight(ROW_HEIGHT);
    //printTree.setEditable(false);
    //printTree.setVisibleRowCount(15);
    ContainerTreeRenderer renderer = new ContainerTreeRenderer(null, false, false);
    renderer.setBGColor(Color.WHITE);
    renderer.setFont(getFont().deriveFont(8.0f));
    //renderer.setLeafIcon(IconManager.getIcon(CollectionObject.class.getSimpleName(), IconManager.IconSize.Std32));
    //renderer.setVerticalTextPosition(SwingConstants.CENTER);
    printTree.setCellRenderer(renderer);

    for (int row = 0; row < printTree.getRowCount(); row++) {
        printTree.expandRow(row);
    }

    PrintablePanel p = new PrintablePanel(new BorderLayout(), printTree);
    p.add(printTree, BorderLayout.CENTER);

    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    //PrinterResolution        pr   = new PrinterResolution(300, 300, PrinterResolution.DPI);
    //MediaPrintableArea       mpa  = new MediaPrintableArea(8,21, 210-16, 296-42, MediaPrintableArea.MM);

    //aset.add( MediaSizeName.IS);
    //aset.add( pr );
    //aset.add( mpa );
    aset.add(new Copies(1));
    aset.add(OrientationRequested.PORTRAIT);
    aset.add(PrintQuality.HIGH);

    PrinterJob job = PrinterJob.getPrinterJob();
    /*PageFormat pageFormat = job.defaultPage();
    Paper      paper      = pageFormat.getPaper();
    paper.setSize(pageFormat.getWidth(), pageFormat.getHeight());
    paper.setImageableArea(
    0,
    0,
    pageFormat.getWidth(),
    pageFormat.getHeight()
    );
    //aset.add( Fidelity.FIDELITY_TRUE );
    pageFormat.setPaper(paper);
            
    Book book = new Book();
    book.append(p, pageFormat, 1);
    job.setPageable(book);*/

    job.setPrintable(p);
    boolean ok = job.printDialog();
    if (ok) {
        try {
            job.print(aset);

        } catch (PrinterException ex) {
            ex.printStackTrace();
            /* The job did not successfully complete */
        }
    }
}

From source file:org.apache.camel.component.printer.PrinterOperations.java

public PrinterOperations() throws PrintException {
    printService = PrintServiceLookup.lookupDefaultPrintService();
    if (printService == null) {
        throw new PrintException("Printer lookup failure. No default printer set up for this host");
    }/*from   w w  w  .j a v a 2  s  .c  om*/
    job = printService.createPrintJob();
    flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
    printRequestAttributeSet = new HashPrintRequestAttributeSet();
    printRequestAttributeSet.add(new Copies(1));
    printRequestAttributeSet.add(MediaSizeName.NA_LETTER);
    printRequestAttributeSet.add(Sides.ONE_SIDED);
}

From source file:org.apache.camel.component.printer.PrinterProducer.java

private PrintRequestAttributeSet assignPrintAttributes() throws PrintException {
    PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
    if (config.getCopies() >= 1) {
        printRequestAttributeSet.add(new Copies(config.getCopies()));
    } else {/*from  w w w .  j  a v  a2 s. com*/
        throw new PrintException("Number of print copies should be greater than zero");
    }
    printRequestAttributeSet.add(config.getMediaSizeName());
    printRequestAttributeSet.add(config.getInternalSides());

    return printRequestAttributeSet;
}

From source file:org.efaps.tests.Printer.java

/**
 * @param args//from www  . j ava  2  s  .c  o  m
 */
public static void main(final String[] args) {
    final AttributeSet aset = new HashAttributeSet();
    aset.add(new PrinterName("HP-LaserJet-100-colorMFP-M175nw", null));
    final PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, aset);
    for (final PrintService serv : pservices) {
        System.out.println(serv);
    }

    try {
        final PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        // pras.add(new Copies(2));

        final PrintService pservice = getPrintService4Name("HP-LaserJet-100-colorMFP-M175nw");
        pservice.getSupportedDocFlavors();
        final DocPrintJob job = pservice.createPrintJob();

        final DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
        final String filename = "/home/janmoxter/Downloads/Notas_de_Pedido_null.DOCX";
        final FileInputStream fis = new FileInputStream(filename);
        final DocAttributeSet das = new HashDocAttributeSet();
        final Doc doc = new SimpleDoc(fis, flavor, das);
        job.print(doc, pras);
    } catch (final FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (final PrintException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.nuclos.server.ruleengine.RuleInterface.java

public void printSilent(String reportName, final NuclosFile file) {
    try {/*from w  w  w .j  a v a 2  s  .c  o  m*/
        final ReportFacadeRemote reportFacade = ServerServiceLocator.getInstance()
                .getFacade(ReportFacadeRemote.class);

        final CollectableSearchCondition clctcond = SearchConditionUtils.newEOComparison(
                NuclosEntity.REPORT.getEntityName(), "name", ComparisonOperator.EQUAL, reportName,
                MetaDataServerProvider.getInstance());
        final List<EntityObjectVO> lstReport = NucletDalProvider.getInstance()
                .getEntityObjectProcessor(NuclosEntity.REPORT.getEntityName())
                .getBySearchExpression(new CollectableSearchExpression(clctcond));

        final Set<ReportOutputVO> reportOutputs = new HashSet<ReportOutputVO>();
        for (EntityObjectVO reportVO : lstReport) {
            for (ReportOutputVO outputVO : reportFacade.getReportOutputs(reportVO.getId().intValue())) {
                if (outputVO.getFormat().equals(ReportOutputVO.Format.PDF)) {
                    reportOutputs.add(outputVO);
                }
            }
        }

        if (reportOutputs.isEmpty()) {
            throw new NuclosFatalRuleException(
                    StringUtils.getParameterizedExceptionMessage("rule.interface.error.18", reportName));
        }

        PrintService prservDflt = reportFacade.lookupDefaultPrintService();

        PrintService[] prservices = reportFacade.lookupPrintServices(null, null);

        if (null == prservices || 0 >= prservices.length) {
            if (null != prservDflt) {
                prservices = new PrintService[] { prservDflt };
            } else {
                throw new NuclosFatalRuleException(SpringLocaleDelegate.getInstance().getMessage(
                        "AbstractReportExporter.5", "Es ist kein passender Print-Service installiert."));
            }
        }

        final PrintService prserv = prservDflt;
        final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

        for (final ReportOutputVO outputVO : reportOutputs) {
            NuclosLocalServerSession.getInstance().runUnrestricted(new Runnable() {
                @Override
                public void run() {
                    try {
                        if (null != prserv) {
                            reportFacade.printViaPrintService((NuclosReportRemotePrintService) prserv,
                                    getNuclosReportPrintJob(outputVO.getFormat()), aset,
                                    file.getFileContents());
                        }
                    } catch (CommonBusinessException e) {
                        throw new NuclosFatalRuleException(e);
                    }
                }
            });
        }
    } catch (Exception e) {
        throw new NuclosFatalRuleException(e);
    }
}