码迷,mamicode.com
首页 > 其他好文 > 详细

e684. 以多种格式打印

时间:2018-09-02 23:39:42      阅读:215      评论:0      收藏:0      [点我收藏+]

标签:dex   book   sts   tab   examples   int   LTP   default   object   

A Book object is used when printing pages with different page formats. This example prints the first page in landscape and five more pages in portrait.

    public class PrintBook {
        public static void main(String[] args) {
            PrinterJob pjob = PrinterJob.getPrinterJob();
            Book book = new Book();
    
            // First part.
            PageFormat landscape = pjob.defaultPage();
            landscape.setOrientation(PageFormat.LANDSCAPE);
            book.append(new Printable1(), landscape);
    
            // Second part.
            PageFormat portrait = pjob.defaultPage();
            portrait.setOrientation(PageFormat.PORTRAIT);
            book.append(new Printable2(), portrait, 5);
    
            pjob.setPageable(book);
            try {
                pjob.print();
            } catch (PrinterException e) {
            }
        }
        static class Printable1 implements Printable {
            public int print(Graphics g, PageFormat pf, int pageIndex) {
                drawGraphics(g, pf);
                return Printable.PAGE_EXISTS;
            }
        }
        static class Printable2 implements Printable {
            public int print(Graphics g, PageFormat pf, int pageIndex) {
                drawGraphics(g, pf);
                return Printable.PAGE_EXISTS;
            }
        }
    }

 

Related Examples

e684. 以多种格式打印

标签:dex   book   sts   tab   examples   int   LTP   default   object   

原文地址:https://www.cnblogs.com/borter/p/9575608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!