首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用常用的Windows打印对话框而不是Java的对话框

使用常用的Windows打印对话框而不是Java的对话框
EN

Stack Overflow用户
提问于 2011-02-01 03:03:43
回答 2查看 1.9K关注 0票数 3

如何使用标准的Windows打印对话框而不是Java对话框进行打印。我在用标签打印机打印条形码时遇到了问题。当我通过Java-Print对话框打印时,我得到一个错误,告诉我要打印的文档的格式是错误的。当我打印到XPS文件,然后通过Windows打印它时,一切工作正常。希望有谁能帮我。

问候

EN

回答 2

Stack Overflow用户

发布于 2011-02-05 17:55:00

代码语言:javascript
复制
try {
    Code128Bean bean = new Code128Bean();
    final int dpi = 150;

    //Configure the barcode generator
    bean.setModuleWidth(UnitConv.in2mm(2.0f / dpi)); //makes the narrow bar width exactly one pixel
    bean.setBarHeight(10);
    bean.doQuietZone(false);

    //Open output file
    File outputFile = new File("out.png");
    OutputStream out;
    out = new FileOutputStream(outputFile);

    //Set up the canvas provider for monochrome PNG output
    BitmapCanvasProvider canvas = new BitmapCanvasProvider(out, "image/x-png", dpi, BufferedImage.TYPE_BYTE_BINARY, false, 90);

    // 200x 10

    //Generate the barcode
    bean.generateBarcode(canvas, barcode);

    //Signal end of generation
    canvas.finish();
    out.close();


    paintComponent(labelArtikelbezeichnung.getText());
    String working_dir = System.getProperty("user.dir");
    try {
        Runtime rt = Runtime.getRuntime();
        String command = "C:\\WINDOWS\\system32\\rundll32.exe C:\\WINDOWS\\system32\\shimgvw.dll,ImageView_Fullscreen " + "" + working_dir + "\\out.png";
        System.out.println(command);
        Process pr = rt.exec(command);

        BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
        String line=null;
        while((line=input.readLine()) != null) {
            System.out.println(line);
        }

        int exitVal = pr.waitFor();
        System.out.println("Exited with error code "+exitVal);

    } catch(Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
    }
} catch (IOException ex) {
    System.out.println("Error creating the Barcode");
}

程序将打开Windows打印和传真对话框,我可以从中进行打印。程序调整了图像的大小,一切都工作得很完美。

票数 2
EN

Stack Overflow用户

发布于 2011-02-05 08:08:36

这可能是由标签打印机本身导致的错误,而不是Java。尝试使用Java将数据写入XPS文件,然后从Java打印该文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4854913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档