Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2815
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Knute Johnson <september@knutejohnson.com> |
| Newsgroups | comp.lang.java.help |
| Subject | Re: Print BufferedImage the result is blank |
| Date | Tue, 15 Oct 2013 19:43:36 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 114 |
| Message-ID | <l3kugm$t88$1@dont-email.me> (permalink) |
| References | <103e51b9-a464-4d94-b3e6-e752f014e546@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Wed, 16 Oct 2013 02:43:34 +0000 (UTC) |
| Injection-Info | mx05.eternal-september.org; posting-host="aba33539224e5c782fe0c4053f7756fd"; logging-data="29960"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Zj4sEp7EldTLdhelQASl6" |
| User-Agent | Mozilla/5.0 (Windows NT 6.2; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 |
| In-Reply-To | <103e51b9-a464-4d94-b3e6-e752f014e546@googlegroups.com> |
| Cancel-Lock | sha1:vhEyrPJb6QG4ivhcTLxteLk8OKY= |
| Xref | csiph.com comp.lang.java.help:2815 |
Show key headers only | View raw
On 10/15/2013 1:56 AM, p7371464@gmail.com 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
>
Try this code and see if you are still having the problem.
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.print.*;
import java.io.*;
import javax.imageio.*;
public class test implements Printable {
final BufferedImage image;
public test() throws IOException {
image = ImageIO.read(new File("kittens.jpg"));
}
public int print(Graphics g, PageFormat pf, int index) {
if (index != 0)
return Printable.NO_SUCH_PAGE;
g.drawImage(image,(int)pf.getImageableX(),
(int)pf.getImageableY(),null);
return Printable.PAGE_EXISTS;
}
public static void main(String[] args) {
try {
test t = new test();
PrinterJob pj = PrinterJob.getPrinterJob();
PageFormat pf = pj.defaultPage();
pj.setPrintable(t);
if (pj.printDialog())
try {
pj.print();
} catch (PrinterException pe) {
pe.printStackTrace();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
--
--
Knute Johnson
Back to comp.lang.java.help | Previous | Next — Previous in thread | Find similar
Print BufferedImage the result is blank p7371464@gmail.com - 2013-10-15 01:56 -0700
Re: Print BufferedImage the result is blank Joerg Meier <joergmmeier@arcor.de> - 2013-10-15 13:27 +0200
Re: Print BufferedImage the result is blank Knute Johnson <september@knutejohnson.com> - 2013-10-15 07:53 -0700
Re: Print BufferedImage the result is blank Jeff Higgins <jeff@invalid.invalid> - 2013-10-15 12:04 -0400
Re: Print BufferedImage the result is blank Knute Johnson <september@knutejohnson.com> - 2013-10-15 19:43 -0700
csiph-web