How to set printer margin in java

前端 未结 2 483
天命终不由人
天命终不由人 2020-12-11 19:46

when trying to print using the Print API - the margins seem to be something not in our control!.. Please help me out to set printer margins or is there any way to set margin

2条回答
  •  [愿得一人]
    2020-12-11 20:23

    PageFormat defaultPF = printJob.defaultPage();
    Paper paper = defaultPF.getPaper();
    if (isPortrait)
    {
        defaultPF.setOrientation(PageFormat.PORTRAIT);
        paper.setImageableArea(0, 0, defaultPF.getWidth(), defaultPF.getHeight());
    }
    else
    {
        defaultPF.setOrientation(PageFormat.LANDSCAPE);
        paper.setImageableArea(0, 0, defaultPF.getHeight(), defaultPF.getWidth());
    }
    defaultPF.setPaper(paper);
    defaultPF = printJob.validatePage(defaultPF);
    
    // now dialog has margins set to minimum
    PageFormat pf = printJob.pageDialog(defaultPF);
    

提交回复
热议问题