在4x6"上使用java打印gif.纸 [英] Print gif using java on a 4x6" paper

查看:86
本文介绍了在4x6"上使用java打印gif.纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,以4x6英寸大小的纸张打印以byte[]ByteArrayInputStream形式给出的gif的最佳方法是什么?

What is the best way in Java to print a gif given as byte[] or ByteArrayInputStream on a paper with a size of 4x6 inches?

此:

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new MediaSize(4, 6, Size2DSyntax.INCH));
aset.add(new Copies(1));
PrintService[] pservices =
PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, aset);

DocPrintJob printJob = pservices[0].createPrintJob();
Doc doc = new SimpleDoc(sap.getGraphicImageBytes(), DocFlavor.INPUT_STREAM.GIF, null);
printJob.print(doc, aset);

不起作用,因为MediaSize不是PrintRequestAttribute.这应该与 Package javax中的几乎相同.print说明

does not work because the MediaSize is not a PrintRequestAttribute. This should be almost the same as in Package javax.print Description

推荐答案

我找到了解决问题的方法

I found a way to solve my problem

PageFormat format = new PageFormat();
format.setOrientation(PageFormat.REVERSE_LANDSCAPE);

PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(OrientationRequested.REVERSE_LANDSCAPE);
aset.add(MediaSizeName.JAPANESE_POSTCARD);

PrinterJob printerJob = PrinterJob.getPrinterJob();
printerJob.setPrintable(new ImagePrintable(sap.getGraphicImage()));
printerJob.defaultPage(format);
printerJob.print(aset);

诀窍是使用日本明信片作为媒体尺寸.

The trick was using japanese postcard as media size.

这篇关于在4x6"上使用java打印gif.纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆