程序控制打印机,从那个盘口出纸,达到业务的应用,目前只支持TOP,MIDDLE,BOTTOM,其它的一般打印机上没有;
public class PDFPrint implements Printable {
private PDFFile file;
PDFPrint(PDFFile file) {
this.file = file;
}
public int print(Graphics g, PageFormat format, int index)
throws PrinterException {
int pagenum = index + 1;
// don't bother if the page number is out of range.
if ((pagenum >= 1) && (pagenum <= file.getNumPages())) {
// fit the PDFPage into the printing area
Graphics2D g2 = (Graphics2D) g;
PDFPage page = file.getPage(pagenum);
double pwidth = format.getImageableWidth();
double pheight = format.getImageableHeight();
double aspect = page.getAspectRatio();
double paperaspect = pwidth / pheight;
Rectangle imgbounds = null;
if (aspect > paperaspect) {
// paper is too tall pdfpage is too wide
int height = (int) (pwidth / aspect);
imgbounds = new Rectangle(
(int) format.getImageableX(),
(int) (format.getImageableY() + ((pheight - height) / 2)),
(int) pwidth, height);
} else {
// paper is too wide pdfpage is too tall
int width = (int) (pheight * aspect);
imgbounds = new Rectangle(
(int) (format.getImageableX() + ((pwidth - width) / 2)),
(int) format.getImageableY(), width, (int) pheight);
}
// render the page
PDFRenderer pgs = new PDFRenderer(page, g2, imgbounds, null, null);
try {
page.waitForFinish();
pgs.run();
} catch (InterruptedException ie) {
}
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}
public static void main(String[] args) throws Exception {
File f = new File("d:/CNIT1199.pdf");
FileInputStream fis = new FileInputStream(f);
FileChannel fc = fis.getChannel();
ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
PDFFile pdfFile = new PDFFile(bb); // Create PDF Print Page
PDFPrintPage pages = new PDFPrintPage(pdfFile); // Create Print Job
PrinterJob pjob = PrinterJob.getPrinterJob();
PageFormat pf = PrinterJob.getPrinterJob().defaultPage();
pjob.setJobName(f.getName());
Book book = new Book();
book.append(pages, pf, pdfFile.getNumPages());
pjob.setPageable(book); // Send print job to default printer
PrintService printService = PrintServiceLookup
.lookupDefaultPrintService();
pjob.setPrintService(printService);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//pras.add(MediaTray.MIDDLE);// 从2盘出
pras.add(MediaTray.TOP);//从1盘出
// pras.add(MediaTray.BOTTOM);//从3盘出
pjob.print(pras);
}
}
分享到:
相关推荐
经典盘口分析秘籍.pdf
08新书【道破盘口天机】伍朝辉 pdf 共15压缩件
指南针软件的盘口杀补丁,超好用的。指南针软件的盘口杀补丁,超好用的。指南针软件的盘口杀补丁,超好用的。
[盘口].徐小明.扫描版控制系统设计的基本要求、控制系统设计中的约束、伺服系统设计、调节系统设计。
高清PPT 盘口语言[老姜] 涨停盘口口诀: 今天能否拉涨停,大单挂单是眼睛: 夹板大单是洗盘,拦截大单护亦出。 压迫大单是发令,蜂窝大单要起飞! 脉冲涨停初起步,阶梯涨停多主升。 震荡涨停洗又拉,斜刺涨停最...
7种必看的盘口语言.pdf
典型洗盘分时及盘口特征参考.pdf
典型洗盘分时及盘口特征[规整].pdf
1450945_盘口信息深度学习攻略[归类].pdf
盘口语言解密高级版
识别分时盘口陷阱,庄家意图
运用tushare爬取五档盘口实时数据
盘口语言解密高级版第七讲[老姜]特殊性涨停共24页.pdf.zip
盘口语言解读大全.doc
通达信指标公式源码 真实盘口.doc
通达信指标公式源码软件盘口异动副图指标 源码 通达信.doc
0801---布林通道线在盘口实战应用的四条法则[归类].pdf
通达信指标公式源码 盘口成交量指标.doc
通达信指标公式源码 自用的真实盘口.doc
通达信指标公式源码盘口异动.doc