J
Johan
Hi,
I'm trying to print multiple lines from one string array. The text gets
printed, but they overlap each other, instead of being printed one line
at a time.
Does someone know how to do this?
TIA
Johan
This is what I came up with till now:
import java.awt.*;
import java.awt.print.*;
public class PrintData {
public PrintData() {
PrinterJob printerjob = PrinterJob.getPrinterJob();
Book book = new Book();
book.append(new TheData(), printerjob.defaultPage());
printerjob.setPageable(book);
try {
printerjob.print();
} catch (PrinterException e) {
e.printStackTrace();
}
}
}
class TheData implements Printable {
Font fnt = new Font("Arial", Font.PLAIN, 12);
public int print(Graphics g, PageFormat pf, int pageIndex) throws
PrinterException {
String[] test = {"test 1", "test 2", "test 3", "test 4"};
g.setFont(fnt);
g.setColor(Color.black);
for (int i = 1, j = 70; i < test.length; i++, j = j + 20) {
g.drawString(test, 75, j);
}
return Printable.PAGE_EXISTS;
}
}
I'm trying to print multiple lines from one string array. The text gets
printed, but they overlap each other, instead of being printed one line
at a time.
Does someone know how to do this?
TIA
Johan
This is what I came up with till now:
import java.awt.*;
import java.awt.print.*;
public class PrintData {
public PrintData() {
PrinterJob printerjob = PrinterJob.getPrinterJob();
Book book = new Book();
book.append(new TheData(), printerjob.defaultPage());
printerjob.setPageable(book);
try {
printerjob.print();
} catch (PrinterException e) {
e.printStackTrace();
}
}
}
class TheData implements Printable {
Font fnt = new Font("Arial", Font.PLAIN, 12);
public int print(Graphics g, PageFormat pf, int pageIndex) throws
PrinterException {
String[] test = {"test 1", "test 2", "test 3", "test 4"};
g.setFont(fnt);
g.setColor(Color.black);
for (int i = 1, j = 70; i < test.length; i++, j = j + 20) {
g.drawString(test, 75, j);
}
return Printable.PAGE_EXISTS;
}
}