views:

587

answers:

1

please tell me if I am doing something wrong. I want to print barcodes onto labels, so I need high quality printout for these barcodes so I am pushing printer to print in 300dpi. What I've done:

  1. made a big JFrame; width: 2490px, height: 3515px so it represents A4 paper in 1:1 measure (this is A4 paper resolution if print is to be 300dpi)

  2. draw 40 barcode images onto contentPane of that JFrame

  3. setup print attributes so it will print in 300dpi:

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

  PrinterResolution pr = 
    new PrinterResolution(300,300,PrinterResolution.DPI);
   MediaPrintableArea mpa=new MediaPrintableArea(8,21,
         210-16, 296-42, MediaPrintableArea.MM);

attribute set is filled with this data:

aset.add( mpa  ); 
aset.add( pr );
aset.add( MediaSizeName.ISO_A4 );
aset.add( new Copies(1) );
aset.add(OrientationRequested.PORTRAIT );
aset.add(PrintQuality.HIGH);
aset.add( Fidelity.FIDELITY_TRUE );

printJob.setPrintable(this);
printJob.print(aset);

this class has print method:

 public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
      return(NO_SUCH_PAGE);
    } else {
      Graphics2D g2d = (Graphics2D)g;

      g2d.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
      disableDoubleBuffering(componentToBePrinted);

      componentToBePrinted.paint(g2d);
      enableDoubleBuffering(componentToBePrinted);
      return(PAGE_EXISTS);
    }

I need to have 40 barcodes on that A4 sheet, each in size 48.5mm x 25.4mm. What is printed out on paper is 6 barcodes each doubled in size of 104mm x 46mm (that is in width almost half of page's width) which fulfilled whole paper.

Any idea, what can I do wrong?

A: 

Your resolution is probably being set to 72 dpi which has the effect of increasing the size of the image.

alann