Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26320

Print BufferedImage the result is blank

Newsgroups comp.lang.java.programmer
Date 2013-10-15 01:55 -0700
Message-ID <8b6171c2-c78d-49da-9a33-eed6f430605a@googlegroups.com> (permalink)
Subject Print BufferedImage the result is blank
From p7371464@gmail.com

Show all headers | View raw


Hi, every one

following are parameter set of my environment

/////////////////

OS: Win 7 64 bit 
Java: java version "1.6.0_29" 32 bit
Test Printer: CutePDF Writer 2.8 、Microsoft XPS Document Writer

///////////

I try to print a image to printer, while the image file size is small the result is correct,
but while the file is large (jpeg format about 1.4 MB) the result is blank!!
I have assign -Xmx1024m to JVM.

following is the code to print, can any one give some suggestions 
///////////////

public class TestPrinter2 {
	public static void main(String[] args) throws Exception {
		PrintService service = PrintServiceLookup.lookupDefaultPrintService();

		PrintRequestAttributeSet set = new HashPrintRequestAttributeSet();

		set.add(new Copies(1));


		PrinterJob pj = PrinterJob.getPrinterJob();

		if (pj.printDialog(set)) {

			service = pj.getPrintService();

			final BufferedImage img = ImageIO.read(new File("C:/TEMP/large.jpg"));

			DocFlavor inFlavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;

			Doc doc = new SimpleDoc(new Printable() {

				public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
					if (pageIndex > 0)
						return Printable.NO_SUCH_PAGE;
					Graphics2D g2d = (Graphics2D) graphics;
					g2d.drawImage(img, (int)pageFormat.getImageableX(), (int)pageFormat.getImageableY(), (int)pageFormat.getWidth(), (int)pageFormat.getHeight(),null);
					return Printable.PAGE_EXISTS;
				}

			}, inFlavor, null);

			DocPrintJob job = service.createPrintJob();

			job.print(doc, set);
		}
	}
}

//////////////////

thanks for reply

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Print BufferedImage the result is blank p7371464@gmail.com - 2013-10-15 01:55 -0700
  Re: Print BufferedImage the result is blank Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-10-15 11:25 +0200
    Re: Print BufferedImage the result is blank p7371464@gmail.com - 2013-10-15 02:53 -0700
  Re: Print BufferedImage the result is blank Joerg Meier <joergmmeier@arcor.de> - 2013-10-15 13:28 +0200
    Re: Print BufferedImage the result is blank p7371464@gmail.com - 2013-10-15 21:01 -0700

csiph-web