As I can adjust the content of a jtextarea for example, I have this line inserted in the JTextArea:
jTextArea1.append("\n----------------------------------------------------------------------------------------------");
With this method I print the content of jtextarea but when it is printed, half of the line is printed and the other half is printed on another sheet.
public boolean imprimirTxtArea() {
String fecha = catsFecha(new Date());
String Cabeza = "Documento" + fecha;
String Pie = "Numero de documento";
try {
MessageFormat header = new MessageFormat(Cabeza, Locale.US);
MessageFormat footer = new MessageFormat(Pie, Locale.US);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.ISO_A4);
aset.add(OrientationRequested.PORTRAIT);
aset.add(Finishings.STAPLE);
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
//Imprimir JTextArea
//jTextArea1.get
jTextArea1.print(header, footer, true, service, aset, true);
String nombre = "DOCUMENTO" + catsFecha(new Date()) + this.getTitle();
String path = nombre + ".txt";
File f = new File(path);
jTextArea1.write(new FileWriter(f));
} catch (PrinterException ex) {
Logger.getLogger(V3.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (IOException ex) {
Logger.getLogger(V3.class.getName()).log(Level.SEVERE, null, ex);
}
return true;
}