过节前后都在忙这个打印程序。
现在换了方法能完全打印了,但是打印出来的空白边距很大不知道像我下面的情况有什么可以设置边距的不?
部分代码如下:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(javax.print.attribute.standard.OrientationRequested.LANDSCAPE); //横向打印
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
PrintService printServi[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 50, 50,
printServi, defaultService, flavor, pras);
try{
ByteArrayOutputStream output = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", output);//image为BufferImage
byte[] buff = output.toByteArray();
InputStream iss= new ByteArrayInputStream(buff);
DocPrintJob job = service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(iss, flavor, das);
/* PageFormat pageFormat = new PageFormat();//打印设置
Paper paper=pageFormat.getPaper();
final double MM_TO_PAPER=1.0/25.4*72;//打印的尺寸单位,1/72英寸,转换成mm,要好用些
double widthA4=210*MM_TO_PAPER;//用A4的纸,
double heightA4=297*MM_TO_PAPER;
double marginSize1=15*MM_TO_PAPER;//边距
double marginSize2=10*MM_TO_PAPER;
paper.setSize(widthA4,heightA4);
paper.setImageableArea(marginSize2,marginSize1,widthA4-2*marginSize2,heightA4-2*marginSize1);
pageFormat.setPaper(paper);
//这些用不了。。
*/
job.print(doc, pras);
}
catch(PrintException pe){
pe.printStackTrace();
}
catch (IOException ioe){
// JOptionPane.showMessageDialog(this, ioe);
}
现在换了方法能完全打印了,但是打印出来的空白边距很大不知道像我下面的情况有什么可以设置边距的不?
部分代码如下:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(javax.print.attribute.standard.OrientationRequested.LANDSCAPE); //横向打印
DocFlavor flavor = DocFlavor.INPUT_STREAM.JPEG;
PrintService printServi[] =
PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService =
PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 50, 50,
printServi, defaultService, flavor, pras);
try{
ByteArrayOutputStream output = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", output);//image为BufferImage
byte[] buff = output.toByteArray();
InputStream iss= new ByteArrayInputStream(buff);
DocPrintJob job = service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(iss, flavor, das);
/* PageFormat pageFormat = new PageFormat();//打印设置
Paper paper=pageFormat.getPaper();
final double MM_TO_PAPER=1.0/25.4*72;//打印的尺寸单位,1/72英寸,转换成mm,要好用些
double widthA4=210*MM_TO_PAPER;//用A4的纸,
double heightA4=297*MM_TO_PAPER;
double marginSize1=15*MM_TO_PAPER;//边距
double marginSize2=10*MM_TO_PAPER;
paper.setSize(widthA4,heightA4);
paper.setImageableArea(marginSize2,marginSize1,widthA4-2*marginSize2,heightA4-2*marginSize1);
pageFormat.setPaper(paper);
//这些用不了。。
*/
job.print(doc, pras);
}
catch(PrintException pe){
pe.printStackTrace();
}
catch (IOException ioe){
// JOptionPane.showMessageDialog(this, ioe);
}
解决方案 »
- java 中数据库连接出现的错误 求大师指导
- 获取网页内容的中文乱码,求解,谢谢!
- 字符串分隔(求正则表达式)
- package的使用
- 请问java有没有监控"一段代码是否在一定时间内响应"的程序
- 开贴强烈介意新手设置classpath的问题
- Calendar的setTime方法、computeTime方法、updateTime、isLenient方法的作用??
- 用Java可以操作摄象头么?
- 把properties文件打进jar文件,可是运行时说找不到properties文件。
- 这种验证码怎么识别啊!
- java实现系统文件目录树、目录树节点图标自定义
- 运行一个关于ArrayList的例子,编译出错,不知是什么原因,请赐教。
paper.setImageableArea(marginSize2,marginSize1,widthA4-2*marginSize2,heightA4-2*marginSize1);
marginSize2,marginSize1我设置成0 始终有1英寸的边距 ,求解~~~