Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: Print BufferedImage the result is blank Date: Tue, 15 Oct 2013 11:25:45 +0200 Organization: A noiseless patient Spider Lines: 64 Message-ID: References: <8b6171c2-c78d-49da-9a33-eed6f430605a@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Tue, 15 Oct 2013 09:25:46 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="eb1b51797ef81b3097eccc55193b584a"; logging-data="4970"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18za++QdvVaGx6Js5epgQ1y" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 In-Reply-To: <8b6171c2-c78d-49da-9a33-eed6f430605a@googlegroups.com> Cancel-Lock: sha1:NBUbiz1Xk/T6tkrTDX5l1YUp0s4= Xref: csiph.com comp.lang.java.programmer:26321 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.