This content has been marked as final. Show 5 replies
h2. Edit: I apologize as I'm not in front of my code at the moment. I will reply again after double-checking the below statement.
COuld you provide code? What's imageable area?
Can you try to set it to 0 in the
Thank you for the quick response. The snippet that you have provided is the same code I used which resulted in the second image (http://i.imgur.com/9lrLj.png)
I'm using a JLabel on a JPanel that implements Printable for a very basic HTML print renderer. i.e.
public int print(Graphics g, PageFormat pf, int pageIndex)
Edited by: 797446 on Mar 1, 2012 12:12 PM
Paper paper = pf.getPaper(); // Paper paper = new Paper(); paper.setImageableArea(0,0,paper.getWidth(), paper.getHeight());
Yeah, I definitely tried that. Is there any known issues with how Java handles margins?
I'll try this with another PostScript processor (such as PrimoPDF) to rule out the Microsoft XPS Document writer as the cause.
boolean doubleBuffered = label.isDoubleBuffered(); label.setDoubleBuffered(false); pf.setOrientation(orientation.get()); //Paper paper = new Paper(); //paper.setSize(8.5 * 72, 11 * 72); //paper.setImageableArea(0, 0, paper.getWidth(), paper.getHeight()); //pf.setPaper(paper); Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); super.paint(g2d); label.setDoubleBuffered(doubleBuffered); return (PAGE_EXISTS);
Edited by: 797446 on Mar 1, 2012 5:46 PM
It took a while, but I was able to fix this printing issue.
The tutorials provided in the print samples (which are now horribly outdated) don't seem to cover this, but in Windows 7 x64, I had to provide additional print attributes to override the default print margins.
Most printers cannot print on the entire surface of the media, due to printer hardware limitations. This class can be used to query the acceptable values for a supposed print job, and to request an area within the constraints of the printable area to be used in a print job.
The key was to provide the attributes along with the print() command. I kept finding this code snippet when finding PDF printing APIs which would suffer from the same border problems.
HashPrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); attr.add(new MediaPrintableArea(0f, 0f, w/72f, h/72f, MediaPrintableArea.INCH)); PrinterJob job = PrinterJob.getPrinterJob(); job.setPrintService(ps); job.setPrintable(this); job.setJobName(jobName); job.print(attr); j.setVisible(false); j.dispose();