“PrinterException: Paper's imageable width is too small” I can see what's wrong, but how can I fix it?

你离开我真会死。 提交于 2019-11-28 12:22:21

问题


I'm getting this error when I try to print something for a specific label printer in my current college project:

java.awt.print.PrinterException: Paper's imageable width is too small.
    at sun.print.RasterPrinterJob.printPage(Unknown Source)
    at sun.print.RasterPrinterJob.print(Unknown Source)
    at sun.print.RasterPrinterJob.print(Unknown Source)
    at Printer.print(Printer.java:91)
    at Printer.<init>(Printer.java:43)
    at VisitorDBTest.main(VisitorDBTest.java:10)

But I cannot see the reason why. I have the exact label code for this particular printer, the label width and height are correct. I set the imageable size to the exact label size (in 1/72nd's of an inch), then I tried setting it smaller with no luck. This code works fine when I print to my normal inkjet on an A4 page. I only get the error when I try to print to the DYMO 450 label printer (using different Paper and PageFormat objects). Looking at the google results it appears I'm practically the only person in history to get this error.

EDIT: after printing the imageable width to screen I get these results:

Paper imageable width is 196.0
PageFormat imageable width is 151.0
PrinterJob imageable width is -65.0267716535433

It's my understanding that both the PageFormat takes it's imageable width from the Paper and the PrinterJob takes it's imageable width from the PageFormat. I'm obviously missing something here.


回答1:


I had the same problem with Dymo 420P.

Try setting imageable area to the same size as paper and origin 0,0. Then after PrinterJob.printDialog(), call PrinterJob.validatePage() with your pageformat. It will return valid pageformat with proper imageable area.




回答2:


i solve it adding

    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

    aset.add(OrientationRequested.PORTRAIT);
    aset.add(MediaSizeName.INVOICE);


        job.print( aset);


来源:https://stackoverflow.com/questions/10601620/printerexception-papers-imageable-width-is-too-small-i-can-see-whats-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!