How can I print JasperPrint directly to printer?

michdraft

I use Java to create report with JasperReports. What i want to do is that user be able to print directly, without print dialog.
I create JasperPrint and I know name and model of my printer.

I have also looked in the sample here but could not figure out how.
I use Java 1.7 and latest JasperReports library.

Does anyone know how to do it?

public class PrintApp  {

    public static void print() {
        JasperPrint jasperPrint = getJasperPrint();
            String printername = AllPrinter.getDepartmentPrinter("Admin");
             // where should i introduce my printer name to jasperreports?
            JasperPrintManager.printReport(jasperPrint, false);
    }

    private static JasperPrint getJasperPrint() {
            return JasperPrinterCreator.getJasperprint();
    }
}
michdraft

I solved it as below, hopefully it helps someone else.

public class PrintApp  {

    public static void print() {
            JasperPrint jasperPrint = getJasperPrint();
            String selectedPrinter = AllPrinter.getDepartmentPrinter("Admin");

            PrinterJob printerJob = PrinterJob.getPrinterJob();
            PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
            PrintService selectedService = null;

            if(services.length != 0 || services != null)
            {
                for(PrintService service : services){
                    String existingPrinter = service.getName().toLowerCase();
                    if(existingPrinter.equals(selectedPrinter))
                    {
                        selectedService = service;
                        break;
                    }
                }

                if(selectedService != null)
                {
                    printerJob.setPrintService(selectedService);
                    boolean printSucceed = JasperPrintManager.printReport(mainPrint, false);
                }
    }

    private static JasperPrint getJasperPrint() {
            return JasperPrinterCreator.getJasperprint();
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I print JasperPrint directly to printer?

From Dev

LPR print, can it be directly to printer?

From Dev

How to print to directly to a wireless printer

From Dev

How to print to directly to a wireless printer

From Dev

How can I print to an actual printer?

From Dev

print a string directly to printer

From Dev

How can I use JavaPOS to print reciepts with an Epson printer?

From Dev

how can I print from a different subnet than the printer?

From Dev

How can I copy a print file to a networked printer?

From Dev

How can I easily set up a Google Cloud Print printer?

From Dev

How can I print PHP syntax highlighting on a colour printer?

From Dev

How many pages can I continuously print without damaging the printer?

From Dev

how can I pass parameter to a reportdocument and print it directly

From Dev

How should i remove printer image on print?

From Dev

How can I force my printer to print in black when it can't recognize 2 colour cartridges?

From Dev

Can I connect a printer directly to a router via USB to Ethernet adapter?

From Dev

How can I force a color printer to print in black and white, when only the color cartridges are allegedly empty?

From Dev

How to skip browser default print preview and print content directly to printer in jquery/javascript?

From Dev

linux print directly to network printer that IS NOT installed

From Dev

How can I install my printer by terminal?

From Dev

How can I install my printer by terminal?

From Dev

Can a printer print white color?

From Dev

PHP print to printer (local / network) directly (stuck in print spooler)

From Dev

PHP print to printer (local / network) directly (stuck in print spooler)

From Dev

Print directly to a network printer without going to a print server

From Dev

how do I convert this code to NOT ask for a printer, just print to default printer?

From Dev

How can I print this?

From Dev

Network printer - can each computer connect directly to the printer?

From Dev

Can I connect a printer directly to a router and send prints through home Wi-Fi network?

Related Related

  1. 1

    How can I print JasperPrint directly to printer?

  2. 2

    LPR print, can it be directly to printer?

  3. 3

    How to print to directly to a wireless printer

  4. 4

    How to print to directly to a wireless printer

  5. 5

    How can I print to an actual printer?

  6. 6

    print a string directly to printer

  7. 7

    How can I use JavaPOS to print reciepts with an Epson printer?

  8. 8

    how can I print from a different subnet than the printer?

  9. 9

    How can I copy a print file to a networked printer?

  10. 10

    How can I easily set up a Google Cloud Print printer?

  11. 11

    How can I print PHP syntax highlighting on a colour printer?

  12. 12

    How many pages can I continuously print without damaging the printer?

  13. 13

    how can I pass parameter to a reportdocument and print it directly

  14. 14

    How should i remove printer image on print?

  15. 15

    How can I force my printer to print in black when it can't recognize 2 colour cartridges?

  16. 16

    Can I connect a printer directly to a router via USB to Ethernet adapter?

  17. 17

    How can I force a color printer to print in black and white, when only the color cartridges are allegedly empty?

  18. 18

    How to skip browser default print preview and print content directly to printer in jquery/javascript?

  19. 19

    linux print directly to network printer that IS NOT installed

  20. 20

    How can I install my printer by terminal?

  21. 21

    How can I install my printer by terminal?

  22. 22

    Can a printer print white color?

  23. 23

    PHP print to printer (local / network) directly (stuck in print spooler)

  24. 24

    PHP print to printer (local / network) directly (stuck in print spooler)

  25. 25

    Print directly to a network printer without going to a print server

  26. 26

    how do I convert this code to NOT ask for a printer, just print to default printer?

  27. 27

    How can I print this?

  28. 28

    Network printer - can each computer connect directly to the printer?

  29. 29

    Can I connect a printer directly to a router and send prints through home Wi-Fi network?

HotTag

Archive