Hello, oldman:
Your problem is a common problem when printing on windows, printer
resolution often is much higher than screen resolution and a unit
conversion is needed to make things look right. Not only lines are
affected by this problem, but images and text painted directly on the
printer canvas.
First you need to check out the ScaleX and ScaleY methods of the
printer:
ScaleX, ScaleY Methods
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vb98/html/vbmthscalex.asp
"The ScaleX and ScaleY methods take a value (width or height), with
its unit of measure specified by fromscale, and convert it to the
corresponding value for the unit of measure specified by toscale."
Next I will point you to a sample code which illustrates how to use
this methods:
Print a Picture to Fit a Page!
http://www.andreavb.com/tip070001.html
Here is the code:
Option Explicit
Public Sub PrintPictureToFitPage(Pic As Picture)
Dim PicRatio As Double
Dim printerWidth As Double
Dim printerHeight As Double
Dim printerRatio As Double
Dim printerPicWidth As Double
Dim printerPicHeight As Double
' Determine if picture should be printed in landscape or portrait
' and set the orientation.
If Pic.Height >= Pic.Width Then
Printer.Orientation = vbPRORPortrait ' Taller than wide.
Else
Printer.Orientation = vbPRORLandscape ' Wider than tall.
End If
' Calculate device independent Width-to-Height ratio for picture.
PicRatio = Pic.Width / Pic.Height
' Calculate the dimentions of the printable area in HiMetric.
printerWidth = Printer.ScaleX(Printer.ScaleWidth,
Printer.ScaleMode, vbHimetric)
printerHeight = Printer.ScaleY(Printer.ScaleHeight,
Printer.ScaleMode, vbHimetric)
' Calculate device independent Width to Height ratio for printer.
printerRatio = printerWidth / printerHeight
' Scale the output to the printable area.
If PicRatio >= printerRatio Then
' Scale picture to fit full width of printable area.
printerPicWidth = Printer.ScaleX(printerWidth, vbHimetric,
Printer.ScaleMode)
printerPicHeight = Printer.ScaleY(printerWidth / PicRatio,
vbHimetric, Printer.ScaleMode)
Else
' Scale picture to fit full height of printable area.
printerPicHeight = Printer.ScaleY(printerHeight, vbHimetric,
Printer.ScaleMode)
printerPicWidth = Printer.ScaleX(printerHeight * PicRatio,
vbHimetric, Printer.ScaleMode)
End If
' Print the picture using the PaintPicture method.
Printer.PaintPicture Pic, 0, 0, printerPicWidth, printerPicHeight
End Sub
See how it uses the ScaleX and ScaleY methods to convert the image
width and height to the correct width and height depending on the
printer resolution. If you would try to use the PaintPicture method
with the pic.width and pic.height values without conversion, you would
get different sizes on different printers, bigger ink jet ones and
smaller on laser ones.
I hope this is the information you were looking for, and don't
hesitate to request for any clarification, we are here to help you.
Search terms used
visual basic faq
://www.google.com/search?q=visual+basic+faq&hl=es&lr=&ie=UTF-8&oe=utf-8&start=10&sa=N
Best regards. |
Request for Answer Clarification by
oldman-ga
on
06 Sep 2002 14:35 PDT
Dear joseleon:
Thank you for this answer. I guess it points to the right direction: a
unit conversion has to be made. However, being a not very bright
programmer, I would really like to see how it applies to lines and not
necessarily pictures. I was hoping to see some code that would say:
Printer.DrawWidth = ???MagicFormula???
I am quite sure it's in the code you provided, but I just don't see it
because of by knowledge level.
Again, thank you for your time,
Eugene
|
Clarification of Answer by
joseleon-ga
on
06 Sep 2002 23:28 PDT
Hello, oldman:
Don't worry, if you don't understand my answer is my fault because
we must provide as clearer answers as possible.
Your line:
Printer.DrawWidth = ???MagicFormula???
Is:
Dim yourDrawWidth As Double
yourDrawWidth = 5
Printer.DrawWidth = Printer.ScaleX(yourDrawWidth, vbPixels,
Printer.ScaleMode)
Let's imaging you want to draw 5 pixels wide lines, but the
printer.scalemode is set to twips, you need to use the ScaleX method
to convert your pixels to twips. Is like you were using distance units
when printing, a centimeter is always a centimeter on any printer no
matter the resolution of the printer.
Your MagicFormula is performed inside the ScaleX and ScaleY methods,
which perform the calculations to convert a device dependent unit
(like pixels) to an device independent unit (like twips).
twips - a whatis definition
http://whatis.techtarget.com/definition/0,,sid9_gci213233,00.html
I hope this time the answer is more clear and sorry for any
inconvenience.
Search strategy
twips
://www.google.com/search?q=twips&sourceid=mozilla-search&start=0&start=0&ie=utf-8&oe=utf-8
Best regards.
|