Domanda

Qual è il modo migliore in Java per stampare un dato come gif byte[] o ByteArrayInputStream su una carta con una dimensione di 4x6 pollici?

Questa:

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

non funziona perché il MediaSize non è un PrintRequestAttribute. Questo dovrebbe essere quasi la stessa javax in pacchetto .print Descrizione

È stato utile?

Soluzione

Ho trovato un modo per risolvere il mio problema

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

Il trucco stava usando cartolina giapponese come formato del supporto.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top