当前位置:主页 > 软件编程 > JAVA代码 >

java控制Pdf自动打印的小例子

时间:2021-02-01 09:55:37 | 栏目:JAVA代码 | 点击:

复制代码 代码如下:

public byte[] autoPrintPdf(byte[] pdf_byte) {

  ByteArrayOutputStream bos=null;
  try {
   PdfReader reader = new PdfReader(pdf_byte);
   bos = new ByteArrayOutputStream();
   PdfStamper ps = new PdfStamper(reader, bos);
   StringBuffer script = new StringBuffer();
   script.append("this.print({bUI: false,bSilent: true,bShrinkToFit: false});").append("\r\nthis.closeDoc();");
   ps.addJavaScript(script.toString());
//   ps.addJavaScript("this.print(true);");
   ps.setFormFlattening(true);
   ps.close();   
  } catch (Exception e) {
   e.printStackTrace();
  }
  return bos.toByteArray();
 }    

您可能感兴趣的文章:

相关文章