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

发布于 2024-10-15 04:16:27 字数 166 浏览 5 评论 0原文

如何使用标准 Windows 打印对话框而不是 Java 对话框进行打印。我在使用标签打印机打印条形码时遇到问题。当我通过 Java 打印对话框打印时,收到一条错误消息,告诉我要打印的文档格式错误。当我打印到 XPS 文件,然后通过 Windows 打印时,一切都很完美。希望任何人都可以帮助我。

问候

How can I use the standard Windows Print dialog to print instead of the Java Dialog. I got problems printing a barcode with a label-printer. When I print via the Java-Print Dialog I get an error telling me that the format of the document which I want to print is wrong. When I print to a XPS File and then print it via Windows, everything works perfectly. Hope anyone can help me.

regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

明媚殇 2024-10-22 04:16:27
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 打印和传真对话框,我可以从中进行打印。该程序调整图像大小,一切正常。

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");
}

The program opens the Windows Print and Fax Dialog where I can print from. The program resizes the image and everything works perfectly.

我的奇迹 2024-10-22 04:16:27

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

It's probably an error resulting from the label printer itself, not Java. Try writing your data to an XPS file with Java and then printing that from Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文