java:设置打印对话框的页面范围
我刚刚开始 学习如何在 Java/Swing 中打印窗口。 (编辑:刚刚找到 Java 打印指南)
当我执行此操作时:
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 上):
如何更改页面范围使其不再是 1-9999?
编辑:使用 Pageable
/Book
设置页面范围(正如 @t_barbz 有用指出的那样)需要 PageFormat,在这种情况下我有一个 catch-22,因为我想要打印对话框来选择它,我似乎没有从打印对话框中获得返回值。
I'm just starting to learn how to print a window in Java/Swing.
(edit: just found the Java Printing Guide)
When I do this:
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 {
}
}
}
I get this printer dialog (on Windows XP):
How do I change the page range so it's not 1-9999?
edit: using Pageable
/Book
to set the page range (as @t_barbz helpfully points out) requires a PageFormat, in which case I have a catch-22, since I'd like the Print dialog to select that, and I don't seem to get a return value from the print dialog.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于页面范围,我相信您需要使用 PrinterJob 的 setPageable(Pageable document) 方法。看起来应该可以解决问题。
For the page range i believe you need to use the PrinterJob's setPageable(Pageable document) method. Looks like it should do the trick.
最后是一个简单的代码:
Finally here is a simple code: