Re: ACCURACY of making templates on a printer
- From: "Michael Williams" <Mike@xxxxxxxxxxxxxxxxx>
- Date: Wed, 18 Mar 2009 20:52:48 -0000
"Randy Gardner" <RandyGardner@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:5539F07E-68B2-4357-9A93-E23B63AFF7F5@xxxxxxxxxxxxxxxx
Is it possible to create very accurately dimensioned templates
by setting printer properties: height, width, zoom, drawwidth,
etc. and printing from VB?
Yes, if you make sure the paper is always stacked and loaded perfectly then you can position and size printed output accurately on the page when printing from VB, but you cannot make a silk purse out of a sow's ear (as the saying goes!) so you will never be able to guarantee positioning to a greater accuracy than the manufacturing tolerances of your printer allow.
I use HP ink jet printer products. When I say accurate
I'm looking for less than +/- 0.0025".
Unless you have an extremely expensive printer then you'll probably find that the manufacturing tolerances are greater than that, although you will be able to get reasonably close to it. For example I've just been looking online at some HP printers and the acceptable positioning tolerance seems to be in the region of 0.03 inches with an "acceptable skew" of an additional 0.03 inches over the height of a 10 inch page. These seem to be the maximum acceptable tolerances and so if you're lucky you'll find that your own printer performs better than that, but even so I think you'll be hard pressed to guarantee accuracy over the whole page to the value of +/- 0.0025 inches you have asked for no matter what application you use to print the output.
I have found that there seem to be some force margin values
that I have not been able to over ride in the past.
Those will be the printer's "unprintable margins", which are different sizes at different settings, even on the same printer depending on whether or not it is currently set to normal or borderless or "minimize margins" or whatever setting your specific printer provides. Essentially the page has a large rectangular "printable area" that is usually a bit smaller than the physical page and the top left corner of which is positioned a specific distance from the top left corner of the page.
As far as VB is concerned (by default) the Printer Object coordinates (0, 0) point to the top left corner of the "printable area" and not to the top left corner of the physical page. This is not a Visual basic thing, it is a printer thing, and all applications which print stuff, including Micro$oft Word and everything else, need to take those things into account. This is not be a problem as far as positioning your output when printing from VB is concerned because you can use the GetDeviceCaps API to "read" both the size and the position of the printable area of the page and you can then take those values into account when printing your stuff.
Neither your VB app nor any other application (MS Word or whatever) can actually print anything into the "unprintable borders" (if there currently are any on your printer at its current settings, which there usually are) because ink will simply not be deposited there, but you can take them into account when positioning your stuff by reading the details with GetDeviceCaps and by then adjusting the Printer Object's ScaleLeft and ScaleTop properties to effectively cause Printer Object coordinates (0, 0) to point to the top left corner of the physical page rather than the top left corner of the "printable area" (which is the default).
Also, I note that height and width are twips setting,
yet printers work in DPI.
That doesn't matter. Most devices (screens and printers for example) use pixels as their native units, but The Visual Basic Printer Object just happens to always use twips as the units of measurement when it tells you the Width and Height of the page (these values relate to the width and height of the entire physical page). However, VB knows exactly how many twips there are in one printer pixel (a value which may be different for different printers and may also be different for the same printer at its different settings) so there is no problem. A twip by the way is 1/1440 inch, so there are 1440 twips in an inch. Incidentally, inches in Windows are "logical inches" and on the screen they are not necessarily (not usually in fact) the same size as a real world inch if you were to hold a ruler up against the screen. However, with printers a Windows logical inch /is/ exactly the same size as a real world inch, so there are no problems there. As far as ScaleWidth and ScaleHeight are concerned, they are the measurements of the "printable area" of the page and are therefore not usually the same as the Width and Height you have mentioned. Also, the ScaleWidth and ScaleHeight can use any units of measurement you desire by setting the Printer's ScaleMode property to the appropriate value. Since you mentioned inches in your post then you are probably most comfortable with those units of measurement, so it would probably be best to set the Printer's ScaleMode to vbInches and work from there.
I use HP ink jet printer products.
That could be a problem :-) Seriously though, it could be a slight problem on some models of HP printer. I've had a couple myself which misreport the size of their unprintable margins at certain printer settings. The difference is not massive (I recall something in the region of one tenth of an inch in the vertical direction on the worst one) but it is certainly enough to throw things out, especially when you are printing stuff onto pre printed forms. There may be other printers which have similar problems, but it just happened to be an HP that I had it on and I never came across the problem in any of the other printers I've had previously and since (except another different HP model!). Again this is not a VB problem, but is a printer problem. On such printers any application on your machine, including Micros$oft Word (I keep using that as an example simply because people tend to trust it!) and Publisher etc, would print things in the wrong place by about a tenth of an inch. With VB of course you can write your code to adjust for such a misreported margin if you were unfortunate enough to have a printer which exhibited it, but it would need to be a "hard coded" value arrived at by running a few simple trial prints and it would work only if you applied the correction only to that one specific model which had the problem and it would cease to work if HP ever got around to fixing the problem for you (which by my experience is unlikely!). It is actually a printer driver problem, but in the case of the two HP printers on which I had the problem they never did get around to producing an updated driver for it. I can't remember which model it was now, but it was a multi purpose inkjet.
Your post was not very detailed regarding exactly what you want to print and it covers a few bases that you may not need to cover, so perhaps you might like to post again giving some more details of exactly what you want to do. In the meantime, just to show that this stuff is by no means as complicated as it sounds, try the following test code. Paste it into a VB Form containing a Command Button. When you run the code and click the button a page should be printed on your default printer with a one inch square printed so that its top left corner is positioned at (1, 1) inches from the top left corner of the physical page. If your printer manufacturing tolerances are okay and if the HP model of printer you have is not one of those which misreports its unprintable margins then the printout should be fairly accurately sized and positioned.
Mike
Option Explicit
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nindex As Long) As Long
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Sub SetPrinterOrigin(x As Single, y As Single)
With Printer
.ScaleLeft = .ScaleX(GetDeviceCaps(.hdc, PHYSICALOFFSETX), _
vbPixels, .ScaleMode) - x
.ScaleTop = .ScaleY(GetDeviceCaps(.hdc, PHYSICALOFFSETY), _
vbPixels, .ScaleMode) - y
.CurrentX = 0
.CurrentY = 0
End With
End Sub
Private Sub Command1_Click()
Printer.Print
Printer.ScaleMode = vbInches
' Set up Printer so that coordinates (0, 0) point
' to the top left corner of the physcial page
' rather than the top left corner of the
' printable area
SetPrinterOrigin 0, 0
' Printer.DrawWidth is unusual in that it is always
' specified in Printer pixels regardless of the ScaleMode
' so we need to perform a conversion here:
Printer.DrawWidth = Printer.ScaleX(0.01, vbInches, vbPixels)
' Draw a one inch square with the top left corner
' located at (1, 1) inches from the top left
' corner of the physical page
Printer.Line (1, 1)-(2, 2), , B
Printer.EndDoc
End Sub
.
- Follow-Ups:
- Re: ACCURACY of making templates on a printer
- From: Micheal Williams
- Re: ACCURACY of making templates on a printer
- References:
- ACCURACY of making templates on a printer
- From: Randy Gardner
- ACCURACY of making templates on a printer
- Prev by Date: Re: VB 6 IDE on 64-bit Windows
- Next by Date: Re: VB 6 IDE on 64-bit Windows
- Previous by thread: Re: ACCURACY of making templates on a printer
- Next by thread: Re: ACCURACY of making templates on a printer
- Index(es):
Relevant Pages
|