java控制Pdf自动打印的小例子
程序员文章站
2023-12-13 14:16:46
复制代码 代码如下:public byte[] autoprintpdf(byte[] pdf_byte) {
bytearrayoutputst...
复制代码 代码如下:
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();
}