I have this code that sends a document to a printer for printing. Currently everything is working ok and the code for that is shown below.
public int print(Graphics g, PageFormat pf, int page) throws
PrinterException {
if (page > 0) {
return NO_SUCH_PAGE;
}
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
g.drawString(content, 100, 100);
return PAGE_EXISTS;
}
public void printDocument(String doc) {
content = doc;
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
} catch (PrinterException ex) {
/* The job did not successfully complete */
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
}
The problem now is when I try to print a document that has a new line it, it still prints it out as one line. the code for calling the function is shown below.
String message ="Library user name: \t" + user +"\n"
+"Item Loaned: \t" + book +"\n"
+"Date Loaned: \t" + dateLoaned +"\n"
+"Return Date: \t" + returnDate +"\n";
print.printDocument(message);