2
我正在嘗試寫一個PhotoBooth程序,但我很難做出無邊界打印。我非常接近,但圖像不填充4「×6」的印刷品。我希望獲得無邊界打印的任何提示。無邊界打印
乾杯!
final BufferedImage img = ImageIO.read(new File(image));
// Assuming that images are going to be 300 DPI
PrinterResolution pr = new PrinterResolution(300, 300,
PrinterResolution.DPI);
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(pr);
// Set print job so the image name shows (in the print queue)
this.pj.setJobName(new File(image).getName());
PageFormat pf = this.pj.getPageFormat(null);
Paper paper = pf.getPaper();
paper.setSize(4 * 72, 6 * 72);
paper.setImageableArea(
0.0, 0.0,
paper.getWidth(), paper.getHeight()
);
if(img.getWidth(null) > img.getHeight(null))
pf.setOrientation(PageFormat.LANDSCAPE);
else
pf.setOrientation(PageFormat.PORTRAIT);
pf.setPaper(paper);
// Create the page
this.pj.setPrintable(new Printable() {
public int print(Graphics g, PageFormat pf, int i) throws
PrinterException {
if (i != 0)
return NO_SUCH_PAGE;
double width = img.getWidth(null);
double height = img.getHeight(null);
double w = Math.floor(pf.getImageableWidth() -
pf.getImageableX())/(width * 1.0);
double h = Math.floor(pf.getImageableHeight() -
pf.getImageableY())/(height * 1.0);
double scale = Math.min(w, h);
Graphics2D g2 = (Graphics2D) g;
g2.translate(0, 0);
g2.scale(scale, scale);
g2.drawImage(img, 0, 0, (int)width, (int)height, null);
return PAGE_EXISTS;
}
}, this.pj.validatePage(pf));
// Get number of copies
int nCopies = SetPrintQuantity.getPrintQuantity(new File(image));
// Print
if(nCopies != 0)
for(int i = 0; i < nCopies; i++)
this.pj.print(pras);
System.out.println(nCopies + ((nCopies == 1) ? " copy" : " copies"));
this.pj =的PrinterJob
除非打印機支持[full bleed](http://en.wikipedia.org/wiki/Bleed_%28printing%29),否則這可能是不可能的。 – trashgod
我不確定打印機是否可以完全流血,但我知道我可以通過使用Windows圖像查看器中的打印功能獲得無邊界打印。所以我想我的目標是實現這樣的目標。 – Johnny
我有同樣的情況,但在Mac上。命令行中的'lp'沒有問題,打印一個完整的出血4x6,但是Java在每一邊放置了'setImageableArea'似乎無法刪除的大量邊際。 –