I am implement the printing in my application.
I am trying to set the page size(A4, B1 ...) and orientation(Portrait, Landscape).
But I found that we can set this in PageFormat object like :
PageFormat pf = job.defaultPage();
Paper paper = pf.getPaper();
pf.setOrientation(PageFormat.PORTRAIT);
paper.setSize(9*72,6*72);
paper.setImagea开发者_如何学编程bleArea(0.5*72,0.5*72,9*72,6*72);
pf.setPaper(paper);
and also we can set an attribute name called MediaSizeName like
aset.add(MediaSizeName.ISO_A4);
I am not sure what is the relationship between those two and what is the correct way to set up the Size and orientation?
Thanks
paper.setSize(9*72,6*72);
paper.setImageableArea(0.5*72,0.5*72,9*72,6*72);
That is a whole lot of magic numbers.
If you are not sure about something, then create (unit) tests that it has to pass, and try out the options. In this way you fix your problem, and if you or someone changing your code later, needs to solve similar problem, he can use your test.
精彩评论