public class Print { Toolkit toolKit = Toolkit.getDefaultToolkit(); PrintJob printJob = toolKit.getPrintJob(new JFrame(), "", null); Font font = new Font("Monospaced",0,12); String s = myTextArea.getText(); int pageNum = 1; int linesForPage = 0; int linesForJob = 0; StringReader sr = new StringReader (s); LineNumberReader lnr = new LineNumberReader (sr); String nextLine; int pageHeight = printJob.getPageDimension().height; public Print() { if (printJob != null) { Graphics g = printJob.getGraphics(); if(g != null) { printInhalt(printJob, g, s); g.dispose(); } printJob.end(); } } //Print string to graphics via printjob void printInhalt(PrintJob printJob, Graphics g, String s) { //Note: String is immutable so won't change while printing. if(!(g instanceof PrintGraphics)) { throw new IllegalArgumentException("Graphics context not PrintGraphics"); } //have to set the font to get any output g.setFont(font); FontMetrics fm = g.getFontMetrics(font); int fontHeight = fm.getHeight(); int fontDescent = fm.getDescent(); int curHeight = 0; try { do { nextLine = lnr.readLine(); if(nextLine != null) { if((curHeight + fontHeight) > pageHeight) { // New Page pageNum++; linesForPage = 0; g.dispose(); g = printJob.getGraphics(); if(g != null) { g.setFont(font); } curHeight = 0; } curHeight += fontHeight; if(g != null) { g.drawString(nextLine, 0, curHeight - fontDescent); linesForPage++; linesForJob++; } } } while(nextLine != null); } catch(Exception e) { System.out.println(e); } }}