java.awt.print.Book Java Examples

The following examples show how to use java.awt.print.Book. 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: WrongPaperForBookPrintingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 7 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #2
Source File: WrongPaperForBookPrintingTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #3
Source File: PrintPageDirect.java    From haxademic with MIT License 6 votes vote down vote up
public void sendToDefaultPrinter() {
	// configure the printing job & simple single-page document
	PrinterJob printJob = PrinterJob.getPrinterJob();
	Book book = new Book();
	book.append(new ImagePage(), printJob.defaultPage());
	PageFormat documentPageFormat = new PageFormat();
	/*
	// new settings to play with
	Paper pape = new Paper();
	pape.setSize(10000, 6000);
	pape.setImageableArea(0, 0, 10000, 6000);
	documentPageFormat.setPaper(pape);
	*/
	documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
	printJob.setPageable(book);

	// use the print dialog UI or just print it!
	if(useDialog) {
		if (printJob.printDialog()) printPage(printJob);
	} else {
		printPage(printJob);
	}
}
 
Example #4
Source File: WrongPaperForBookPrintingTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #5
Source File: PrintPageDirect.java    From haxademic with MIT License 5 votes vote down vote up
/**
	 * Constructor: Example3
	 * <p>
	 *  
	 */
	public void doPrintDemo() {

		//--- Create a new PrinterJob object
		PrinterJob printJob = PrinterJob.getPrinterJob();

		//--- Create a new book to add pages to
		Book book = new Book();

		//--- Add the cover page using the default page format for this print job
		book.append(new ImagePage(), printJob.defaultPage());
//		book.append(new IntroPage(), printJob.defaultPage());

		//--- Add the document page using a landscape page format
		PageFormat documentPageFormat = new PageFormat();
		documentPageFormat.setOrientation(PageFormat.PORTRAIT);
		//	    book.append(new Document(), documentPageFormat);

		//--- Add a third page using the same painter
		//	    book.append(new Document(), documentPageFormat);

		//--- Tell the printJob to use the book as the pageable object
		printJob.setPageable(book);

		//--- Show the print dialog box. If the user click the
		//--- print button we then proceed to print else we cancel
		//--- the process.

		// remove the print dialog and just print it!
		//	    if (printJob.printDialog()) {
		try {
			printJob.print();
		} catch (Exception PrintException) {
			PrintException.printStackTrace();
		}
		//	    }

	}
 
Example #6
Source File: WrongPaperForBookPrintingTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
Example #7
Source File: Foo.java    From coming with MIT License 5 votes vote down vote up
public AudioFormat colorized(Book b1, Book b2, int random) throws Exception, IllegalArgumentException {
    LinkedList<Point2D> points = new LinkedList<Point2D>();
    points.add(new Point(10, 20));
    points.add(new Point(20, 20));
    points.add(new Point(30, 20));

    if(random > 100) {
        Bar barInstance = new Bar();
        barInstance.returnField(new JLabel("I am a JLabel object"));

        if(random < 150) {
            for(int i = 0 ; i < 10 ; ++i) {
                JButton button = new JButton("I am a JButton object");
            }

            barInstance = new Bar(new JTextArea());

            return new AudioFormat(Encoding.ALAW, (float)1.0, 8, 2, 1, (float)1.0, true, new HashMap<String, Object>());
        }
        else {
            throw new Exception("a test exception");
        }
    }
    else {
        throw new IllegalArgumentException("a test illegal format exception");
    }
}
 
Example #8
Source File: PrintPageDirectNew.java    From haxademic with MIT License 4 votes vote down vote up
/**
	* Constructor: Example3
	* <p>
	*  
	*/
	public void doPrintDemo() {

		//--- Create a new PrinterJob object
		PrinterJob printJob = PrinterJob.getPrinterJob();

		//--- Create a new book to add pages to
		Book book = new Book();

		//--- Add the cover page using the default page format for this print job
		book.append(new ImagePage(), printJob.defaultPage());
//		book.append(new IntroPage(), printJob.defaultPage());

		//--- Add the document page using a landscape page format
		PageFormat documentPageFormat = new PageFormat();
		documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
		

		//documentPageFormat.add(new Copies(1)); 
		
		book.append(new Document(), documentPageFormat);

		//--- Add a third page using the same painter
		//	    book.append(new Document(), documentPageFormat);

		//--- Tell the printJob to use the book as the pageable object
		printJob.setPageable(book);

		//--- Show the print dialog box. If the user click the
		//--- print button we then proceed to print else we cancel
		//--- the process.

		// remove the print dialog and just print it!
		//	    if (printJob.printDialog()) {
		try {
			printJob.print();
		} catch (Exception PrintException) {
			PrintException.printStackTrace();
		}
		//	    }

	}
 
Example #9
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;
}
 
Example #10
Source File: JRPrinterAWT.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 *
 */
public boolean printPages(
	int firstPageIndex,
	int lastPageIndex,
	boolean withPrintDialog
	) 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 (withPrintDialog)
		{
			if (printJob.printDialog())
			{
				printJob.print();
			}
			else
			{
				isOK = false;
			}
		}
		else
		{
			printJob.print();
		}
	}
	catch (Exception ex)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_ERROR_PRINTING_REPORT,
				null, 
				ex);
	}

	return isOK;
}
 
Example #11
Source File: HeadlessBook.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    new Book().getNumberOfPages();
}
 
Example #12
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #13
Source File: RasterPrinterJob.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #14
Source File: RasterPrinterJob.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #15
Source File: RasterPrinterJob.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #16
Source File: RasterPrinterJob.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #17
Source File: RasterPrinterJob.java    From jdk8u_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #18
Source File: RasterPrinterJob.java    From Bytecoder with Apache License 2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #19
Source File: RasterPrinterJob.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #20
Source File: RasterPrinterJob.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #21
Source File: RasterPrinterJob.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #22
Source File: RasterPrinterJob.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #23
Source File: RasterPrinterJob.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #24
Source File: RasterPrinterJob.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}
 
Example #25
Source File: PrintPageDirectNew.java    From haxademic with MIT License 2 votes vote down vote up
public void sendToDefaultPrinter() {
	// configure the printing job & simple single-page document
	PrinterJob printJob = PrinterJob.getPrinterJob();
	
	
	
	PageFormat pageFormat = printJob.defaultPage();
	Paper paper = pageFormat.getPaper();
	
	float inchWidth = 16;
	float inchHeight = 20;
	
	float marginWidth = 100;
	float marginHeight = 100;
	
	int pWidth = (int) ((inchWidth * 25.4f) * 2.835f);// quick: convert inch to mm, mm to pt
	int pHeight = (int) ((inchHeight * 25.4f) * 2.835f);
	
	paper.setSize(pWidth, pHeight);
	paper.setImageableArea(marginWidth, marginHeight, pWidth, pHeight);
	pageFormat.setPaper(paper);
	
	//not sure this exactly works, we should probably just scale the square to fit and we send it the correct rotation orientation
	//pageFormat.setOrientation(PageFormat.LANDSCAPE);
	

	// we might also be able to set attributes here
	Printable page = new ImagePage();
	Book book = new Book();
	
	book.append(page, pageFormat);
	
	
	/*
	Early testing at "LikeMinded Productions":
	
	PageFormat documentPageFormat = new PageFormat();
	
	// new settings to play with
	Paper pape = new Paper();
	pape.setSize(10000, 6000);
	pape.setImageableArea(0, 0, 10000, 6000);
	documentPageFormat.setPaper(pape);
	
	documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
	*/
	
	
	printJob.setPageable(book);

	// use the print dialog UI or just print it!
	if(useDialog) {
		if (printJob.printDialog()) printPage(printJob);
	} else {
		printPage(printJob);
	}
}
 
Example #26
Source File: RasterPrinterJob.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Return the zero based index of the first page to
 * be printed in this job.
 */
protected int getFirstPage() {
    return mFirstPage == Book.UNKNOWN_NUMBER_OF_PAGES ? 0 : mFirstPage;
}