Re: Positioning ouput on printed pages
- From: WayneM <WayneM@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 7 Jan 2006 07:43:02 -0800
Mike,
Thanks a lot for the info. I really appreciate it.
WayneM
"Mike Williams" wrote:
> "WayneM" <WayneM@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:3E65E7AC-7F2E-43F0-9593-D4F963A3F66D@xxxxxxxxxxxxxxxx
>
> > I have a vb6 app that prints info to a metafile and then it is played
> > onto the printer object. This is done to combine information from
> > my vb app plus output from a third party dll. On some printers the
> > output is shifted, so the information is no longer aligned. Any ideas
> > on how to control this or know how to make the adjustments? My
> > only thought is to get the info from the DeviceCaps and try to scale
> > it. Any ideas would be appreciated.
>
> The problem is almost certainly because you are not taking into account the
> "unprintable margins" of the printer. As you've correctly gathered,
> GetDeviceCaps will give you information enabling you to correct for this.
> Basically, all printers have a "printable area" which is often slightly
> smaller than the physical page and the actual position of the top left
> corner of that printable rectangle is offset slightly from the top left
> corner of the physical page. Also, the actual size and position of this
> printable rectangle can vary from one printer to the next, and can also vary
> even on the same printer ar different settings. As far as the VB printer
> object is concerned, location (0, 0) is the top left corner of the
> "printable area" and *not* the top left corner of the physical page. You can
> force the VB printer object to automatically correct for this by getting the
> appropriate values from GetDeviceCaps and then setting the Printer Object's
> ScaleLeft and ScaleTop properties accordingly. The code I've posted in this
> reply (below) shows you how to do this.
>
> The above method (altering ScaleLeft and ScaleTop) will of course work only
> when using native VB printer object drawing methods, because the API
> routines themselves know nothing at all about the VB printer object's Scale
> properties. So, if you are drawing to the printer object's hDC property
> using an API drawing method then you will have to add the appropriate x and
> y pixel offsets returned by GetDeviceCaps to your specified coordinates.
> Alternatively, you could use the various API routines that deal with
> mapmodes and viewport origins and stuff to "instruct" the API routines to
> automatically apply the appropriate offsets, but the former is much simpler
> to do.
>
> To summarise, if you are drawing your metafile using the VB PaintPicture
> method then use the simple SetPrinterOrigin code (as shown below).
> Otherwise, if you are drawing the metafile to the printer hDC using the
> appropriate API functions then add the offsets returned by GetDeviceCaps to
> your drawing code.
>
> All of this of course assumes that the drawing made by the third party DLL
> you mention are being done propewrly (taking into account the unprintable
> margins). I assume that they are, otherwise both the third party DLL and the
> VB printer object would be "making the same mistakes" and the drawings done
> by each would line up with each other (although they would of course both be
> "out" by a small amount).
>
> Anyway, check out the code I have posted and post again if you need any more
> help. By the way, the offsets returned by GetDeviceCaps are in units of
> "printer pixels", hence the ScaleX and ScaleY conversions in my sample code.
> You haven't given a lot of information about exactly how you are combining
> the output from the thrid party DLL and your own code, so forgive me if I've
> misu7nderstrood your problem.
>
> 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 Declare Function Rectangle Lib "gdi32" _
> (ByVal hdc As Long, _
> ByVal X1 As Long, ByVal Y1 As Long, _
> ByVal X2 As Long, ByVal Y2 As Long) As Long
>
> 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.ScaleMode = vbInches
> ' By default the VB printer origin "points to" the top left
> ' corner of the current "printable area", which is usually
> ' *not* the same as the top left corner of the physical page.
> ' You can use this code to fix this problem and to set the
> ' effective origin to any desired position on the physical
> ' page. Here we Here we use (0, 0) to set it to the exact
> ' top left corner:
> SetPrinterOrigin 0, 0
> ' test by printing two very small circles at exact
> ' positions on the page:
> Printer.FillStyle = vbFSSolid
> Printer.Circle (1, 1), 0.02, vbBlack
> Printer.Circle (4.5, 4.5), 0.02, vbBlack
> Printer.EndDoc
> End Sub
>
>
>
>
>
>
.
- References:
- Re: Positioning ouput on printed pages
- From: Mike Williams
- Re: Positioning ouput on printed pages
- Prev by Date: Re: Color Codes
- Next by Date: Re: Open HTML Files?
- Previous by thread: Re: Positioning ouput on printed pages
- Next by thread: Color Codes
- Index(es):
Relevant Pages
|