我的应用程序中有一个非常简单的打印功能,可以打印Jtextpane的内容。我想将默认页面大小设置为A4,但是在搜索后我发现很多涉及书籍和文档formater等的方法,我希望尽可能简单。打印JTextPane时的简单页面大小设置?
我的代码目前是:
public void printy(){
JTextPane jtp = new JTextPane();
jtp.setBackground(Color.white);
try {
// open the file we have just decrypted
File myFile = new File(deletefile + "mx.txt");
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(
new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null) {
aBuffer += aDataRow + "\n";
}
String[] splitdata = aBuffer.split("`"); //recover the file and split it based on `
String lines = "";
for(String line : splitdata){
lines = lines + line + System.getProperty("line.separator") + System.getProperty("line.separator");
}
myReader.close();
System.out.println(Arrays.toString(splitdata));
System.out.println(lines);
jtp.setText(lines);
boolean show = true;
try {
//set the header and footer data here
MessageFormat headerFormat = new MessageFormat("HEADER HERE");
MessageFormat footerFormat = new MessageFormat("FOOTER HERE");
Paper A4 = new Paper();
A4.setSize(595, 842);
A4.setImageableArea(43, 43, 509, 756);
jtp.print(headerFormat, footerFormat, show, null, null, show);
} catch (java.awt.print.PrinterException ex) {
ex.printStackTrace();
}
} catch (Exception ez) {
System.out.println("error in array building");
}
}
}
我已经设置了A4纸大小,但不知道如何在对的JTextPane的属性.PRINT设置。
感谢您的帮助;
安迪
Can [this](http://stackoverflow.com/questions/13558152/how-can-i-print-a-custom-paper-size-cheques-8-x-4)有帮助吗? – Mateusz 2013-05-07 21:00:59
排序,但我很努力地看到如何在我的代码中使用示例。我希望我可以保持大致相同的代码(如其简单),但用某种纸张大小替换空参数之一? – andy 2013-05-07 21:32:43