Java Printing - getImageableX is useless
There does not seem to be a default printing forum, this forum seems closest, I need advanced help so I will start my post here. Please inform me if there is a more appropriate forum.
I have some serious problems with the Java Printing API.
On Windows at least the getImageableX and Y seem to always be 72.0, regardless of paper chosen or printer or whatever.I have several printers where the hard printer margins are clearly indicated in the drivers and are not one inch. I can maintain my own database of proper printer imagaeble area, and have seen articles indicating I should reset the clipping area, but that seems to defeat the purpose of having the OS and Java do it.
Does the Java VM and appropriate Printing API classes query the driver for the imageable area? Or does it always return 72.0 regardless of what the paper is?
Thanx
Julian
[883 byte] By [
Bodger2a] at [2007-11-26 15:52:49]

# 1
Wake up man! There are no printers at Sun? Researchers don't do printers. It seems everyone is developing his or her own print system (or buying one?)
Just seems like the 900lb elephant that no one wants to play with. I've set about reasearching possibilities of building my own complete print system.
Not really something I want to do either.
Sean
# 2
You should post some code in code tags,see button above, to help jog our minds as to what you are doing. it is hard to read too much into your situation with the info you provided. I'm just a 2d newbie though.Sean
# 3
You should consider iText as a printing subsystem, that is what I'm using. It only outputs PDF files but it is very flexible; you will need to buy the book though if you want to use it professionally. They have an ebook (PDF) that is half the price of the print version and it serves the purpose very well.
Google iText
# 4
Sean
Code is not the issue, but to show you:
What is below is the actionListener code to my test app that basically has a button that brings up a Print dialog allows the user to select a printer and properties etc. Then after the user hits done, it gets the PageFormat information and displays it on my base dialog. I can include the Eclipse/Ant project if you are so inclined.
I have a few other classes that go with it, a Printable that basically returns no such page, so it does not actually get printed.
System.out.println("actionPerformed()");
OurPrintable xPrintable = new OurPrintable ();
myJob = PrinterJob.getPrinterJob ();
myJob.setPrintable (xPrintable);
if (myJob.printDialog ())
{
DoubledImageableX;
DoubledImageableY;
DoubledImageableWidth;
DoubledImageableHeight;
PageFormatpfFormat = myJob.defaultPage ();
dImageableX = new Double (pfFormat.getImageableX ());
dImageableY = new Double (pfFormat.getImageableY ());
dImageableWidth = new Double (pfFormat.getImageableWidth ());
dImageableHeight = new Double (pfFormat.getImageableHeight ());
myImagableX.setText(dImageableX.toString ());
myImagableY.setText(dImageableY.toString ());
myImagableWidth.setText(dImageableWidth.toString ());
myImagableHeight.setText(dImageableHeight.toString ());
}
From the comments I am seeing this appears to be a glaring hole in the ceiling. Someone needs to address this at the OS/VM level.
Thanx
Julian
# 5
You are basically selecting a paper size in the dialog and it doesn't affect the PageFormat object(s) of your Printable. Correct?
My brain is foggy on this but I believe this has been addressed in Sun articles somewhere. What version of Java are you using?
What is myJob.defaultPage() doing?
sean
# 6
It affects everything BUT getImageableX and Y. They ARE ALWAYS 72.Julian
# 7
The dialog doesn't have a place to set margins as I recall; are you expecting Java to get the margins from the printer? Otherwise you have to set the margins yourself which is what I thought you mentioned in your first post.Sean
# 8
this code makes the pageDialog appear with half inch margins
for 8.5x11 paper:
PrinterJob job = PrinterJob.getPrinterJob();
PageFormat pf = job.defaultPage();
Paper p = pf.getPaper();
//the units are 1/72 of an inch...this sets 0.5" margins for 8.5x11
p.setImageableArea(0.5*72,0.5*72,7.5*72,10*72);
pf.setPaper(p);
PageFormat pf2 = job.pageDialog(pf);
I would not be surprised if it doesn't work as intended with all printers,
but it probably works for a large majority. My application has no problem
with a dependency on 8.5"x11" paper.
# 9
forgot to mention in last post - the half inch margin code I just sent changes getImageableX ()and getimageableY() to 32.
# 10
Just use standardprint http://forum.java.sun.com/thread.jspa?forumID=20&threadID=661036
# 11
The problem is I am trying to use small thermal printers that are 2.25 inches or 3 inches in width. The driver (.inf) files indicates a small margin (which I verified). The point is I have to manually set the imagable area on these printers.1 inch margins leave me with 1/4 inch printable area.
Thanx
Julian
# 12
If you just doGraphics.setClip(null)you should be able to print to the whole area