Stranger printer happenings?

K

Knute Johnson

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,
 
S

Stefan Ram

Knute Johnson said:
appeared to be scaled up by a factor of 2 in the x direction.

Could be an image for a 1200 x 1200 DPI printer printed on a
600 x 1200 DPI printer.
 
M

markspace

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.
 
K

Knute Johnson

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top