java.awt.print.Book#append ( )源码实例Demo

下面列出了java.awt.print.Book#append ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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);
        }
    }
}
 
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);
        }
    }
}
 
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);
        }
    }
}
 
源代码4 项目: jdk8u_jdk   文件: WrongPaperForBookPrintingTest.java
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);
        }
    }
}
 
源代码5 项目: haxademic   文件: PrintPageDirect.java
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);
	}
}
 
源代码6 项目: haxademic   文件: PrintPageDirect.java
/**
	 * 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();
		}
		//	    }

	}
 
源代码7 项目: jasperreports   文件: JRPrinterAWT.java
/**
 *
 */
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;
}
 
源代码8 项目: nordpos   文件: JRPrinterAWT.java
/**
 *
 */
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;
}
 
源代码9 项目: haxademic   文件: PrintPageDirectNew.java
/**
	* 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();
		}
		//	    }

	}
 
源代码10 项目: haxademic   文件: PrintPageDirectNew.java
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);
	}
}
 
 方法所在类