2 xiedijie6828 xiedijie6828 于 2017.01.04 12:12 提问

发票打印时连续出设置现三张只有第一张时打印好的,怎样设置只出现一张呢,还有就是空白边距怎么去掉

JButton button_11 = new JButton("发票");
button_11.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

try

            {
                PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
                PrinterJob job = PrinterJob.getPrinterJob();
                PageFormat pageFormat =new PageFormat();
                pageFormat.setOrientation(PageFormat.PORTRAIT); 



            String sql = "select max(id) id from fee";
                List<Map<String, Object>> list0 = DBUtil.query(sql);
                int sid = (Integer) list0.get(0).get("id");
                sql = "select * from fee where id = '" + sid + "'";
                List<Map<String, Object>> list = DBUtil.query(sql);
                Map<String, Object> data = list.get(0);
                String fpid = (String) data.get("fpid");
                String name = (String) data.get("name");
                String sex = (String) data.get("sex");
                int state = (Integer) data.get("state");
                Date time = (Date) data.get("time");
                String item = (String) data.get("item");
                double fee = (Double) data.get("fee");
                double rfee = (Double) data.get("rfee");
                String[] datas = new String[] { name, sex, state + "", item, fee + "", rfee + "", time + "", fpid,sid+""};

            Printable printable = new PrintJPanel("发票", datas);
                job.setPrintable(printable);
                if (job.printDialog(attributes))
                    job.print(attributes);  
            }
            catch (PrinterException e2)
            {
                JOptionPane.showMessageDialog(frame, e2);
            }
        }

1个回答

Tiger_Zhao
Tiger_Zhao   Rxr 2017.01.04 13:39

应该是默认的纸张大小和发票纸张不一致。
打印机要走3张纸(发票)才能输出任务中的“一页”。
创建一个合适的Paper,调用pageFormat.setPaper()

xiedijie6828
xiedijie6828 是这样加么
11 个月之前 回复
xiedijie6828
xiedijie6828 PageFormat pageFormat =new PageFormat(); pageFormat.setOrientation(PageFormat.PORTRAIT); Paper p = new Paper(); p.setSize(259, 300); p.setImageableArea(0, 0, 250, 300); pageFormat.setPaper(p);
11 个月之前 回复
xiedijie6828
xiedijie6828 可以帮我看看么 留个qq么
11 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!