Java Code Examples for java.awt.print.PrinterJob#setPrintService()

The following examples show how to use java.awt.print.PrinterJob#setPrintService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DummyPrintTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static void thirdPartyPrintLogic(String printerName) throws Exception {
    PrinterJob printerjob = PrinterJob.getPrinterJob();
    printerjob.setCopies(2);
    printerjob.setJobName("myJobName");
    printerjob.setPrintable(new DummyPrintable());
    for (PrintService printService : PrinterJob.lookupPrintServices()) {
        System.out.println("check printer name of service " + printService);
        if (printerName.equals(printService.getName())) {
            System.out.println("correct printer service do print...");
            printerjob.setPrintService(printService);
            printerjob.print();
            break;
        }
    }
}
 
Example 2
Source File: JRPrinterAWT.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fix for bug ID 6255588 from Sun bug database
 * @param job print job that the fix applies to
 */
public static void initPrinterJobFields(PrinterJob job)
{
	try
	{
		job.setPrintService(job.getPrintService());
	}
	catch (PrinterException e)
	{
	}
}
 
Example 3
Source File: PrintDialog.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 4
Source File: PrintDialog.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 5
Source File: PrintDialog.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 6
Source File: PrintDialog.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 7
Source File: SetPrintServiceTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 8
Source File: PrintDialog.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 9
Source File: SetPrintServiceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 10
Source File: PrintDialog.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 11
Source File: SetPrintServiceTest.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 12
Source File: SetPrintServiceTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 13
Source File: SetPrintServiceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 14
Source File: PrintDialog.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 15
Source File: SetPrintServiceTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 16
Source File: PrintDialog.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 17
Source File: SetPrintServiceTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 18
Source File: PrintDialog.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // instruction dialog
    Frame instruction = new Frame("Verify that no native print dialog is showed");
    instruction.add(new TextArea(instructions));
    instruction.pack();
    instruction.show();
    // test begin
    PrintServiceStub service = new PrintServiceStub("test");
    PrintServiceLookup.registerService(service);
    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintService(service);
    job.printDialog();
    System.out.println("test passed");
}
 
Example 19
Source File: SetPrintServiceTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    PrintServiceStub service = new PrintServiceStub("CustomPrintService");
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    try {
        printerJob.setPrintService(service);
        System.out.println("Test Passed");
    } catch (PrinterException e) {
        throw new RuntimeException("Test FAILED", e);
    }
}
 
Example 20
Source File: JRPrinterAWT.java    From nordpos with GNU General Public License v3.0 4 votes vote down vote up
/**
 *
 */
public boolean printPages(
	int firstPageIndex,
	int lastPageIndex,
	PrintService service
	) throws JRException
{
	boolean isOK = true;

	if (
		firstPageIndex < 0 ||
		firstPageIndex > lastPageIndex ||
		lastPageIndex >= jasperPrint.getPages().size()
		)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_INVALID_PAGE_RANGE,  
				new Object[]{firstPageIndex, lastPageIndex, jasperPrint.getPages().size()}
				);
	}

	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.getOrientationValue())
	{
		case LANDSCAPE :
		{
			pageFormat.setOrientation(PageFormat.LANDSCAPE);
			paper.setSize(jasperPrint.getPageHeight(), jasperPrint.getPageWidth());
			paper.setImageableArea(
				0,
				0,
				jasperPrint.getPageHeight(),
				jasperPrint.getPageWidth()
				);
			break;
		}
		case 
		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 {
				isOK = false;
			}
               } else {
                   printJob.setPrintService(service);
			printJob.print();
		}
	}
	catch (Exception ex)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_ERROR_PRINTING_REPORT,
				null, 
				ex);
	}

	return isOK;
}