简体   繁体   English

Java打印:确定正在打印的页面

[英]Java Printing: Determine the page that is printing

I have a print method below from a class: 我下面有一个类的print方法:

public void print(EditorPanePrinter epp) {
    try {
        PrinterJob pj=PrinterJob.getPrinterJob();
        boolean ok = pj.printDialog();
        if(ok) {
            pj.setPageable(epp);
            pj.print();
        }
    } catch (PrinterException e1) {
        e1.printStackTrace();
    }

}

EditorPanePrinter is a JEditorPane wrapped with a JPanel for print previews. EditorPanePrinter是一个JEditorPane包装了一个JPanel以进行打印预览。 See here for details. 有关详细信息,请参见此处

After clicking "OK" from the print dialog shown, the page is printed correctly from the printer. 从显示的打印对话框中单击“确定”后,即可从打印机正确打印页面。

For more than 1 pages, especially with many pages to print, I want to show a dialog on which pages are printed: ie "Printing page 1 of 100" when the 1st page is printing, "Printing page 2 of 100" when the 2nd page is printing, and so on. 对于多于1页的页面,尤其是要打印多页的页面,我想显示一个要在其上打印页面的对话框:即,在打印第一页时为“正在打印100页中的第1页”,在第二页时为“正在打印100页中的2页”页面正在打印,依此类推。

I have searched everywhere and I found no solution. 我到处搜索,但没有找到解决方案。 How to do this? 这个怎么做?

If you need more info, please let me know. 如果您需要更多信息,请告诉我。

A Pageable is made of Printable s, when each Printable is called, it is passed the pageIndex that the system is trying to print, which can used, for example, to print the page number on the output... 一个PageablePrintable ,当每个Printable被调用时,会传递系统正在尝试打印的pageIndex ,例如,它可以用于在输出上打印页码。

See Printable for more details. 有关更多详细信息,请参见Printable

Depending on the framework you are printing from, you might want to execute this from within a SwingWorker and use the publish / process capabilities to change the active page number. 根据您要打印的框架,您可能希望在SwingWorker执行此操作,并使用publish / process功能来更改活动页码。 See Worker Threads and SwingWorker for more details 有关更多详细信息,请参见工作线程和SwingWorker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM