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


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

Print BufferedImage the result is blank

Started byp7371464@gmail.com
First post2013-10-15 01:55 -0700
Last post2013-10-15 21:01 -0700
Articles 5 — 3 participants

Back to article view | Back to comp.lang.java.programmer


Contents

  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

#26320 — Print BufferedImage the result is blank

Fromp7371464@gmail.com
Date2013-10-15 01:55 -0700
SubjectPrint BufferedImage the result is blank
Message-ID<8b6171c2-c78d-49da-9a33-eed6f430605a@googlegroups.com>
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

[toc] | [next] | [standalone]


#26321

FromDaniele Futtorovic <da.futt.news@laposte-dot-net.invalid>
Date2013-10-15 11:25 +0200
Message-ID<l3j1mp$4ra$1@dont-email.me>
In reply to#26320
On 2013-10-15 10:55, p7371464@gmail.com allegedly wrote:
> 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
> 
 You sure there isn't a PrintException getting swallowed somewhere? Try
putting the body of your #print method in a try/catch block.

[toc] | [prev] | [next] | [standalone]


#26322

Fromp7371464@gmail.com
Date2013-10-15 02:53 -0700
Message-ID<ac96eba2-ba30-4ace-b584-8847f85f6394@googlegroups.com>
In reply to#26321
On Tuesday, October 15, 2013 5:25:45 PM UTC+8, Daniele Futtorovic wrote:
> On 2013-10-15 10:55, p7371464@gmail.com allegedly wrote:
> 
> > 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
> 
> > 
> 
>  You sure there isn't a PrintException getting swallowed somewhere? Try
> 
> putting the body of your #print method in a try/catch block.

thanks for reply Daniele,

I change my code and put the whole body of main method in a try block
and remove the throws PrinterException clause from print method declaration.

Finally I put the body of print method in a try block.


I execute my code again but the console not output any error message.


I type 
java -Xmx1024m TestPrinter2

in console window to execute the code.

[toc] | [prev] | [next] | [standalone]


#26323

FromJoerg Meier <joergmmeier@arcor.de>
Date2013-10-15 13:28 +0200
Message-ID<xacc7lz0omv3.crepygshm9of.dlg@40tude.net>
In reply to#26320
On Tue, 15 Oct 2013 01:56:33 -0700 (PDT), p7371464@gmail.com wrote:

(as this is the more active group, I'm reposting my answer here)

> OS: Win 7 64 bit 
> Java: java version "1.6.0_29" 32 bit

And that didn't strike you as odd ? I recommend starting by getting the
upropriate (and current) version of Java for your machine. Your Java
version is two years old and has many large and dangerous security flaws.
Note that Java 7 is the current version. Java 6 is no longer even supported
officially.

As for your problem, you are not giving the image any time to load, and
proceed to trying to print it without ever even checking if it was finished
loading, or loaded even partially.

I'm pretty rusty at loading Images through Java libraries, so I hope this
is the apropriate way, if not, maybe someone else here could correct me.
You get a decent example at

<http://docs.oracle.com/javase/7/docs/api/java/awt/MediaTracker.html>

and you don't need to worry about the Applet crap, but MediaTracker does
need a Component for some obscure reason. You can simply pass it a new
JFrame() and all should be good.

Liebe Gruesse,
		Joerg

-- 
Ich lese meine Emails nicht, replies to Email bleiben also leider
ungelesen.

[toc] | [prev] | [next] | [standalone]


#26324

Fromp7371464@gmail.com
Date2013-10-15 21:01 -0700
Message-ID<46e340ca-eb5d-4eb1-ad66-fa4c47d59286@googlegroups.com>
In reply to#26323
On Tuesday, October 15, 2013 7:28:16 PM UTC+8, Joerg Meier wrote:
> On Tue, 15 Oct 2013 01:56:33 -0700 (PDT), p7371464@gmail.com wrote:
> 
> 
> 
> (as this is the more active group, I'm reposting my answer here)
> 
> 
> 
> > OS: Win 7 64 bit 
> 
> > Java: java version "1.6.0_29" 32 bit
> 
> 
> 
> And that didn't strike you as odd ? I recommend starting by getting the
> 
> upropriate (and current) version of Java for your machine. Your Java
> 
> version is two years old and has many large and dangerous security flaws.
> 
> Note that Java 7 is the current version. Java 6 is no longer even supported
> 
> officially.
> 
> 
> 
> As for your problem, you are not giving the image any time to load, and
> 
> proceed to trying to print it without ever even checking if it was finished
> 
> loading, or loaded even partially.
> 
> 
> 
> I'm pretty rusty at loading Images through Java libraries, so I hope this
> 
> is the apropriate way, if not, maybe someone else here could correct me.
> 
> You get a decent example at
> 
> 
> 
> <http://docs.oracle.com/javase/7/docs/api/java/awt/MediaTracker.html>
> 
> 
> 
> and you don't need to worry about the Applet crap, but MediaTracker does
> 
> need a Component for some obscure reason. You can simply pass it a new
> 
> JFrame() and all should be good.
> 
> 
> 
> Liebe Gruesse,
> 
> 		Joerg
> 
> 
> 
> -- 
> 
> Ich lese meine Emails nicht, replies to Email bleiben also leider
> 
> ungelesen.

Thanks for your sugestion, Joerg.

The problem is resolved.

While I update my JDK to 7u45 64-bit.
The output is correct.

By the way, I try to install JDK 7u45 32-bit version, the output is stil remain blank.
The cause should be I not installed corresponded JVM version with my machine.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.programmer


csiph-web