Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #27432 > unrolled thread
| Started by | Knute Johnson <eternal@knutejohnson.com> |
|---|---|
| First post | 2014-01-31 18:34 -0800 |
| Last post | 2014-02-01 21:17 -0800 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
Stranger printer happenings? Knute Johnson <eternal@knutejohnson.com> - 2014-01-31 18:34 -0800
Re: Stranger printer happenings? markspace <markspace@nospam.nospam> - 2014-02-01 09:02 -0800
Re: Stranger printer happenings? Knute Johnson <eternal@knutejohnson.com> - 2014-02-01 21:17 -0800
| From | Knute Johnson <eternal@knutejohnson.com> |
|---|---|
| Date | 2014-01-31 18:34 -0800 |
| Subject | Stranger printer happenings? |
| Message-ID | <lchmeq$727$1@dont-email.me> |
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 PageFormat was in portrait mode and the other PageFormat parameters looked perfectly normal. Turns out scaling my rendering by 0.5 made it print fine. Anybody ever see anything like this? Thanks, -- Knute Johnson
[toc] | [next] | [standalone]
| From | markspace <markspace@nospam.nospam> |
|---|---|
| Date | 2014-02-01 09:02 -0800 |
| Message-ID | <lcj9c0$epc$1@dont-email.me> |
| In reply to | #27432 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Knute Johnson <eternal@knutejohnson.com> |
|---|---|
| Date | 2014-02-01 21:17 -0800 |
| Message-ID | <lckkcf$ie4$1@dont-email.me> |
| In reply to | #27434 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web