当前位置: 代码迷 >> J2SE >> java打印页面边距设置,该如何解决
  详细解决方案

java打印页面边距设置,该如何解决

热度:67   发布时间:2016-04-23 21:43:27.0
java打印页面边距设置
BufferedImage bufferedimage1 = new BufferedImage(barcode1.getSize().width, barcode1.getSize().height, 1); 
            java.awt.Graphics2D graphics2d1 = bufferedimage1.createGraphics();
            barcode1.paint(graphics2d1); 
            JPEGImageEncoder jpegimageencoder = JPEGCodec.createJPEGEncoder(servletoutputstream);
            JPEGEncodeParam jpegencodeparam = jpegimageencoder.getDefaultJPEGEncodeParam(bufferedimage1);
            jpegencodeparam.setQuality(1.0F, true);
            jpegimageencoder.setJPEGEncodeParam(jpegencodeparam);
            jpegimageencoder.encode(bufferedimage1, jpegencodeparam);
            
//          打印 
            Graphics g =bufferedimage1.createGraphics();  
            g.drawString("", 0, 0);
            ByteArrayOutputStream outstream = new ByteArrayOutputStream(); 
ImageIO.write(bufferedimage1, "jpg", outstream);
byte[] buf = outstream.toByteArray();
InputStream stream = new ByteArrayInputStream(buf);   
PrintService se = PrintServiceLookup.lookupDefaultPrintService();
try { 
DocPrintJob job = se.createPrintJob(); 
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
Doc doc = new SimpleDoc(stream, flavor, null);    
job.print(doc, null);
} catch (Exception ex) {
System.out.print(ex.getMessage());
}

------解决方案--------------------
BufferedImage bufferedimage1 = new BufferedImage(barcode1.getSize().width, barcode1.getSize().height, 1);
  相关解决方案