Article View: borland.public.jbuilder.java.language
Article #17892Re: Bugs in PrintJob under Windows
From: John P. McGrath
Date: Thu, 17 Sep 1998 00:00
Date: Thu, 17 Sep 1998 00:00
56 lines
2732 bytes
2732 bytes
Hans Georg Frey <hfrey@she.de> wrote: > whats wrong with the methods getPageDimension() and getPageResolution() > from the class PrintJob under Windows? The methods doesn't return > correct values. I've read in "JAVA in a Nutshell, Examples" that > the methods doesn't work. There is a workaround with the methode > getScreenResolution() from the class Toolkit. The result is very bad > and different on different clients. > > Does anybody know whats on with the class PrintJob and how I can > do printing correct? As I noted in my previous message, there are a _lot_ of problems with the PrintJob class. Here are some of the things that I have found out: In order to make it easy for you to print components that are displayed on your monitor, PrintJob modifies the resolution of the print Graphics to make it scale the same as the screen. Since the "normal" resolution of a monitor is 72dpi, that's what you get with your print job. getPageResolution() always returns this hard-coded value. The result is that it effectively turns your 600dpi printer into a 72dpi printer. The value returned by getPageDimension() is based on the paper size and the 72dpi resolution. So if you print to 8 1/2 x 11 paper, getPageDimension() will return 612 x 792. This value does not take into account the printable area of the page. So the actual printable area will be less than the reported area. As far as I know, there is no way to get the printable dimension. What I have done is to create a resource file that defines the printable area for specified page dimensions. It contains strings that look something like: 612x792 = 540x732 792x612 = 732x540 Then I wrote a class that loads the resource file and translates a page dimension to the corresponding printable dimension. This is far from ideal, but it allows me to configure my code to print within the printable area of the printer. Another note: Be sure to put a try/catch block around the call to Toolkit.getPrintJob(), which catches Errors. I found that it sometimes throws an java.lang.InternalError when there are problems connecting to the printer. I hope this helps. -- Regards, John P. McGrath <mcgrath@enter.net> <jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.106aa2c587a7b36e9896ad@forums.inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<35FB83C4.769F@she.de>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,78820e80254f39c8 X-Google-Attributes: gidf74b3,public From: mcgrath@enter.net (John P. McGrath) Subject: Re: Bugs in PrintJob under Windows Date: 1998/09/17 Message-ID: <MPG.106aa2c587a7b36e9896ad@forums.inprise.com> X-Deja-AN: 391998963 References: <35FB83C4.769F@she.de> Organization: Software Consulting Services Newsgroups: borland.public.jbuilder.java.language