0

So I keep getting this error:

THE ERROR: java.awt.print.PrinterException: Paper's imageable width is too small.

I was able to piece together a printing class based off of a lot of questions on s.o. It was working. Until it didn't. I reverted to my code from before the break and it still doesn't work. I have tried numerous answers on stack overflow on the Paper's imageable width is too small. Thus far nothing.

It doesn't matter what printer I try to send it to or what size paper. I can print it to a PDF and it prints exactly how I would want it. 1.125"w x 3.5"h in portrait.

public void printComponenet(){

PrinterJob pj = PrinterJob.getPrinterJob();
pj.setJobName(" Print Component ");

pj.setPrintable (new Printable() {    
public int print(Graphics pg, PageFormat pf, int pageNum){
  if (pageNum > 0){
  return Printable.NO_SUCH_PAGE;
  }

  Graphics2D g2 = (Graphics2D) pg;
  g2.rotate(Math.toRadians(90));
  g2.translate(0,-81);
  g2.translate((int)pf.getImageableX(), (int)pf.getImageableY());
  jPanelPrintLabel.paint(g2);
  return Printable.PAGE_EXISTS;


  }
  });
  if (pj.printDialog() == false)
  return;

  try {
        pj.print();
  } catch (PrinterException ex) {
      System.out.print(ex);
        // handle exception
  }
}
Tony BenBrahim
  • 7,040
  • 2
  • 36
  • 49
Marcus
  • 11
  • 4
  • @MadProgrammer I know you have beat this topic to death but I could really use your insight. – Marcus Jan 25 '17 at 21:24
  • I don't see anywhere you set up the `PageFormat` - something like [this for example](http://stackoverflow.com/questions/14725456/fitting-printerjob-object-to-specific-print-format-of-bufferedimage/14726386#14726386) – MadProgrammer Jan 25 '17 at 22:35
  • @MadProgrammer I see your PageFormat comment. I am looking into it. before you responded though, I deleted the printer from windows and reinstalled it. Oddly enough it started printing after that. I am still going to look into the pageFormat since I have read many of your answers about its importance. Thank you for responding. I wasn't sure if the tag would catch you since you had not commented on this question before. – Marcus Jan 25 '17 at 23:42
  • Remember, printing is fun, especially at 2am after 16 hours of trying to make it work :P – MadProgrammer Jan 25 '17 at 23:43
  • @MadProgrammer is that a quote from one of your other post? I believe it is. Thanks again. – Marcus Jan 25 '17 at 23:44
  • http://stackoverflow.com/questions/10601620/printerexception-papers-imageable-width-is-too-small-i-can-see-whats-wrong @MadProgrammer Why did this work? I cannot wrap my head around it, but it fixed my issue too. – Marcus Jan 31 '17 at 00:49
  • AFAIK `validatePage` does just that, it validates the page size and imageable area, if possible from the information from the printer. It would seem that many of the properties are lazy and don't notify/modify other properties, so validating them allows the API to fix inconsistencies, in a reasonably well defined manner – MadProgrammer Jan 31 '17 at 01:09

0 Answers0