JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java Tools  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 jasperreports 列印至印表機的問題
fabch





發文: 10
積分: 1
於 2006-08-22 13:17 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以下是直接列印至印表機的寫法,但是他會列印到預設印表機,
請問我想要列印到指定印表機應該用什麼指令或方法可以設定。
1
2
3
4
5
6
7
8
9
10
11
12
    public void newViewer(String SSQL, URL url, Map map) {
        try {
            JasperReport jR = (JasperReport) JRLoader.loadObject(url);
            Connection conn = getConnection();
            Statement stm = conn.createStatement();
            ResultSet rs = stm.executeQuery(SSQL);
            JRResultSetDataSource jRDS = new JRResultSetDataSource(rs);
            JasperPrint jP = JasperFillManager.fillReport(jR, map, jRDS);
            JasperPrintManager.printReport(jP, false);
        } catch (Exception ex) {
        }
    }


以下是指定的印表機,
有辦法將指定的 PrintService 設定到上面的 JasperPrintManager 裡面嗎?
1
2
3
4
5
6
7
8
9
10
    private PrintService getPrintService(String SPrinterName) {
        PrintService[] PSs = PrinterJob.lookupPrintServices();
        for (int i = 0; i < PSs.length; i++) {
            String SPS = PSs[i].toString();
            if (SPS.equals(SPrinterName)) {
                return PSs[i];
            }
        }
        return null;
    }


嘗試更改預設印表機卻發生跟他一樣的問題
http://forum.java.sun.com/thread.jspa?threadID=600743&tstart=63
Here are my code in PrintReportServlet.java to tried select printer programmically
1
2
3
4
5
6
7
8
9
    DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
    PrintRequestAttributeSet aset = new HashPrintRequestHashAttributeSet();
    aset.add(MediaSizeName.ISO_A4);
    PrintService[] pservices =PrintServiceLookup.lookupPrintServices(flavor, aset);
    if (pservices.length > 0) {
        DocPrintJob pj = pservices[0].createPrintJob();
        JasperReport jreport = (JasperReport) JRLoader.loadObject("myreport.jprint");
        JasperPrintManager.printReport(jprint, false);
    }

JasperPrintManager still print report via the old default printer.

or I tried this to change default printer programically
1
2
3
4
5
6
    PrinterJob currentJob = PrinterJob.getPrinterJob();
    PrintService services[] = PrinterJob.lookupPrintServices();
    PrintService currentPrinter = services[selected];
    currentJob.setPrintService(currentPrinter);
    JasperReport jreport = (JasperReport) JRLoader.loadObject("myreport.jprint");
    JasperPrintManager.printReport(jprint, false);

JasperPrintManager still print report via the old default printer.


fabch edited on 2006-08-22 14:02
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
14305 jasperreports 列印至印表機的問題 fabch 2340 2006-08-22 13:17
13021 Re:jasperreports 列印至印表機的問題 fabch 808 2006-08-22 15:49
12959 Re:jasperreports 列印至印表機的問題 fabch 1062 2006-08-23 17:59
11702 Re:jasperreports 列印至印表機的問題 fabch 4425 2008-05-12 10:41
8757 Re:jasperreports 列印至印表機的問題 didifong 54 2010-02-09 23:03
» JWorld@TW »  Java Tools

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8