Stranger printer happenings?

Discussion in 'Java' started by Knute Johnson, Feb 1, 2014.

  1. 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
     
    Knute Johnson, Feb 1, 2014
    #1
    1. Advertising

  2. Knute Johnson

    Stefan Ram Guest

    Knute Johnson <> writes:
    >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.
     
    Stefan Ram, Feb 1, 2014
    #2
    1. Advertising

  3. Knute Johnson

    markspace Guest

    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.
     
    markspace, Feb 1, 2014
    #3
  4. 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
     
    Knute Johnson, Feb 2, 2014
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel Lee
    Replies:
    0
    Views:
    524
    Samuel Lee
    Nov 11, 2003
  2. Knute Johnson

    Stranger compiler error?

    Knute Johnson, Nov 10, 2006, in forum: Java
    Replies:
    17
    Views:
    642
    Patricia Shanahan
    Nov 13, 2006
  3. Weird socket happenings

    , Dec 27, 2005, in forum: Perl Misc
    Replies:
    5
    Views:
    133
  4. Replies:
    5
    Views:
    149
  5. Kevin Newman

    priveledged stranger?

    Kevin Newman, Jul 27, 2005, in forum: Javascript
    Replies:
    6
    Views:
    81
    Kevin Newman
    Jul 29, 2005
Loading...

Share This Page