Java ダイアログの代わりに標準の Windows 印刷ダイアログを使用して印刷するにはどうすればよいですか。ラベルプリンターでバーコードを印刷する際に問題が発生しました。Java-Print Dialog から印刷すると、印刷しようとしているドキュメントの形式が間違っているというエラーが表示されます。XPS ファイルに出力してから Windows 経由で印刷すると、すべてが完全に機能します。誰でも私を助けてくれることを願っています。
よろしく
Java ダイアログの代わりに標準の Windows 印刷ダイアログを使用して印刷するにはどうすればよいですか。ラベルプリンターでバーコードを印刷する際に問題が発生しました。Java-Print Dialog から印刷すると、印刷しようとしているドキュメントの形式が間違っているというエラーが表示されます。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 ではなく、ラベル プリンター自体に起因するエラーである可能性があります。Java を使用して XPS ファイルにデータを書き込んでから、それを Java から出力してみてください。