gpt4 book ai didi

java:设置打印对话框的页面范围

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:22:53 25 4
gpt4 key购买 nike

我才刚刚开始to learn how to print a window in Java/Swing .(编辑:刚刚找到 the Java Printing Guide )

当我这样做时:

protected void doPrint() {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
}
catch (PrinterException ex) {
ex.printStackTrace();
}
finally {

}
}
}

我得到这个打印机对话框(在 Windows XP 上):

enter image description here

如何更改页面范围使其不是 1-9999?

编辑:使用Pageable/Book 设置页面范围(正如@t_barbz 有益地指出的那样)需要 PageFormat ,在这种情况下,我有一个 catch-22,因为我希望打印对话框选择它,而且我似乎没有从打印对话框中获得返回值。

最佳答案

对于页面范围,我认为您需要使用 PrinterJob 的 setPageable(Pageable document) 方法。看起来应该可以解决问题。

protected void doPrint() {
PrinterJob job = PrinterJob.getPrinterJob();
Book book = new Book();
book.append(this, job.defaultPage());
printJob.setPageable(book);

boolean ok = job.printDialog();
if (ok) {
try {
job.print();
}
catch (PrinterException ex) {
ex.printStackTrace();
}
finally {

}
}
}

关于java:设置打印对话框的页面范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6216487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com