Path: csiph.com!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Knute Johnson Newsgroups: comp.lang.java.programmer Subject: Re: Stranger printer happenings? Date: Sat, 01 Feb 2014 21:17:05 -0800 Organization: A noiseless patient Spider Lines: 131 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sun, 2 Feb 2014 05:17:03 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="aba33539224e5c782fe0c4053f7756fd"; logging-data="18884"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6PN8jj/nu1fWv29JL/cCc" User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: Cancel-Lock: sha1:F2Jw/uu9n0dv48zYfC7c4yz/b84= Xref: csiph.com comp.lang.java.programmer:27439 On 2/1/2014 09:02, markspace wrote: > On 1/31/2014 6:34 PM, Knute Johnson wrote: >> I wrote a little program for the local animal shelter. The program >> prints a poster for lost or found animals. When I wrote the program and >> tested it at home on my printer, an HP LaserJet, it worked fine. When I >> got to the site to test the program, the result from the printer >> appeared to be scaled up by a factor of 2 in the x direction. The > > > What printer (vendor & model) does the shelter have, and what printer > driver? What OS are you each using? > > Contact the printer manufacture with this information and ask about > possible incompatibilities. There maybe other issues (bugs) or APIs > which you are unaware that could be affecting output format. You can > try talking to Oracle too but generally I've found them unresponsive to > small developers. > > Could you post a sample of the printer code? Stefan raises a good point > that the issue could be in your code as well. > > > I don't have the printer manufacturer. It is a color ink jet printer. The OS is Windows 7. The print code is below (with the AffineTransform to make it work). It prints fine on my LaserJet under Windows 8. Thanks, knute... public int print(Graphics g, PageFormat pf, int index) { if (index == 0) { System.out.printf("Width: %f\nHeight: %f\n" + "ImageableWidth: %f\nImageableHeight: %f\n" + "ImageableX: %f\nImageableY: %f\n", pf.getWidth(),pf.getHeight(),pf.getImageableWidth(), pf.getImageableHeight(),pf.getImageableX(),pf.getImageableY()); String orientation; switch (pf.getOrientation()) { case PageFormat.LANDSCAPE: orientation = "Landscape"; break; case PageFormat.PORTRAIT: orientation = "Portrait"; break; case PageFormat.REVERSE_LANDSCAPE: orientation = "Reverse Landscape"; break; default: orientation = "default"; break; } System.out.printf("Orientation: %s\n",orientation); render(g,pf); return Printable.PAGE_EXISTS; } else return Printable.NO_SUCH_PAGE; } private void render(Graphics g2D, PageFormat pf) { Graphics2D g = (Graphics2D)g2D; BufferedImage image = photoPanel.getImage(); AffineTransform at = g.getTransform(); g.scale(0.5,1.0); // needed for SOTH' printer g.setFont(new Font("Arial",Font.BOLD,64)); FontMetrics fm = g.getFontMetrics(); String str = lost.isSelected() ? "LOST" : "FOUND"; g.drawString(str, ((int)pf.getWidth()-fm.stringWidth(str))/2,100); g.setFont(new Font("Arial",Font.PLAIN,18)); fm = g.getFontMetrics(); if (image != null) { double ratio = (double)image.getWidth() / image.getHeight(); double factor; if (ratio >= 1.7777779) // aspect ratio >= than 16x9 factor = 468.0 / image.getWidth(); else factor = 263.0 / image.getHeight(); int w = (int)(image.getWidth() * factor); int h = (int)(image.getHeight() * factor); int x = ((int)pf.getWidth() - w) / 2; g.drawImage(image,x,150,w,h,null); } else { str = "No Photo Available"; g.drawString(str,(int)(pf.getWidth()-fm.stringWidth(str))/2,280); g.drawRect(72,150,468,263); } int y = 450; if (name.getText().length() > 0) { str = String.format("Name: %s",name.getText()); g.drawString(str,72,y); y += (fm.getHeight() * 2); } String[] text = desc.getText().split("\n"); for (String t : text) { g.drawString(t,72,y); y += fm.getHeight(); } y += fm.getHeight(); if (location.getText().length() > 0) { str = String.format("Location: %s",location.getText()); g.drawString(str,72,y); y += (fm.getHeight() * 2); } if (contact.getText().length() > 0) { str = String.format("Contact: %s",contact.getText()); g.drawString(str,72,y); } g.setTransform(at); } -- Knute Johnson