gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:39:04 25 4
gpt4 key购买 nike

如何使用标准 Windows 打印对话框而不是 Java 对话框进行打印。我在使用标签打印机打印条形码时遇到问题。当我通过 Java 打印对话框打印时,我收到一条错误消息,提示我要打印的文档格式错误。当我打印到 XPS 文件然后通过 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");
}

程序打开 Windows 打印和传真对话框,我可以从中进行打印。该程序调整图像大小,一切正常。

关于java - 使用通常的 Windows 打印对话框而不是 Java 的对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4854913/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com