0

My program gives the user a print Dialogue like so:

PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(MainLauncher.printer);
boolean ok = job.printDialog();
if (ok) {
    try {
        job.print();
    } catch (PrinterException ex) {
        System.out.println("Printer Failed to Print.");
    }
}

Which gives them this window:

Java Print Dialogue on Linux

My question is: How do I set all the fields in "Margins" to be 0 by default?

I'm on Linux, in case that makes a difference.

I have tried setting the ImagableArea to be the size of the page in the Printer after the dialogue is finished like so:

public int print(Graphics g, PageFormat pf, int page)
        throws PrinterException {
    double pageWidth = pf.getPaper().getWidth();
    double pageHeight = pf.getPaper().getHeight();
    Paper paper = new Paper();
    paper.setImageableArea(0, 0, pageWidth, pageHeight);
    pf.setPaper(paper);

but that just positions the images and writing I'm printing as if there were no Margin and then cutting out everything in the margin.

I've been trawling through the JavaDocs for hours and it's driving me bonkers. Any help would be much appreciated

Androconus
  • 143
  • 6
  • 1
    Possible duplicate of [How to set printer margin in java](http://stackoverflow.com/questions/25283110/how-to-set-printer-margin-in-java) – Arif Acar Dec 08 '16 at 01:52
  • 1
    @Arif - I've seen that, and have explored all possible leads I could get from it. I decided in the end that the situation is different enough to warrant a separate question. – Androconus Dec 08 '16 at 02:36
  • @Arif - Actually, no, Having read that again, I take it back, this other question _is_ address the same problem, but the answer is too vague. I'll read up on "MediaPrintableArea" and come back and either accept it as a duplicate or write about my findings. – Androconus Dec 08 '16 at 02:49

0 Answers0