By default, DPI is a normal 72 DPI (I believe), which is pretty bad on printed paper. You need to request a print API to try to find a printer with the best DPI.
Basically you need to use the print services API. A.
Try something like ...
public class PrintTest01 { public static void main(String[] args) { PrinterResolution pr = new PrinterResolution(300, 300, PrinterResolution.DPI); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); aset.add(pr); aset.add(OrientationRequested.PORTRAIT); PrinterJob pj = PrinterJob.getPrinterJob(); pj.setPrintable(new Page()); try { pj.print(aset); } catch (PrinterException ex) { ex.printStackTrace(); } } public static class Page implements Printable { @Override public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex > 0) { return NO_SUCH_PAGE; } Graphics2D g2d = (Graphics2D) g; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); g.setFont(new Font("Arial", Font.PLAIN, 128)); FontMetrics fm = g.getFontMetrics(); int x = (int)(pageFormat.getWidth() - fm.stringWidth("A")) / 2; int y = (int)((pageFormat.getHeight() - fm.getHeight()) / 2) + fm.getAscent(); g2d.drawString("A", x, y); return PAGE_EXISTS; } } }
You can find Working with print services and some help attributes ...
I have to warn you, this will print the first printout that it can find, which matches PrintRequestAttributeSet . You can also add in the print dialog to see what it does, but this is another level of difficulty I can live without right now;)
source share