Quote:
> > Page to send to printer (PDF/inkjet/whatever).
> > ScaleMode set to millimetres - accuracy of layout is fine.
> > Have had to introduce some coloured, block arrows on 2 charts with
> > vertical
> > positioning set by their values.
> > Using Polygon and CreatePolygonRgn for drawing the block arrows.
> > To translate from pixels to millimetres, I have been trying with:
> > GetDeviceCaps(Printer.hdc, LOGPIXELSX) and GetDeviceCaps(Printer.hdc,
> > LOGPIXELSY)
> > to produce a correction factor for pixels to millimetres - with not much
> > success.
> > The PDF printer is good on horizontal positining but illogically erratic
> > on
> > the vertical
> > An HP inkjet is much more out of position.
> > Any help would be appreciated
> > Michael
> Dot{*filter*}illmeter = DPI / 25.4
> If you are already doing this, post some code, including what
> Printer.ScaleMode is set to, and the values from GetDeviceCaps().
Thanks for reply
Yes, tried the DPI/25.4
Have cut the code down as much as I can - still seems a lot to post
Everything positioned with Printer ScaleMode as vbMillimeters positions
accurately
but not with the pixels to millimetres conversion
Form1:
Option Explicit
Private Sub Command1_Click()
Dim PD As New cPrnDlg
If PD.ShowPrinterDialog Then
Printer.PaperSize = 9 'A4
PrintCoverSheet
Printer.EndDoc
End If
Set PD = Nothing
End Sub
*****************************************************
Bas Module:
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetDeviceCaps Lib "gdi32" _
(ByVal hdc As Long, ByVal nIndex As Long) As Long
Private Declare Function SetBkMode Lib "gdi32" _
(ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function CreatePolygonRgn Lib _
"gdi32" (lpPoint As Any, ByVal nCount As Long, _
ByVal nPolyFillMode As Long) As Long
Private Declare Function Polygon Lib "gdi32" _
(ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
Private Declare Function FillRgn Lib "gdi32" _
(ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" _
(ByVal crColor As Long) As Long
Private Const LOGPIXELSX = 88
Private Const LOGPIXELSY = 90
Private Const ALTERNATE = 1 'constant for FillMode
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Const TRANSPARENT As Long = 1
Private Const OPAQUE As Long = 2
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 DoPrint(sX As Single, sY As Single, Optional lFColor As Long =
vbBlack, _
Optional bBold As Boolean = False, Optional bItalic As
Boolean = False, _
Optional lFSize As Long = 9, Optional sFont As String =
"Times New Roman", _
Optional bText As Boolean = True, Optional sText As
String = "", _
Optional sLongBox As Single = 0, Optional sBoxLength As
Single = 17, _
Optional sLineLength As Single = 0, Optional bLineHoriz
As Boolean = True, _
Optional lLongBoxColour As Long = &HE0E0E0, Optional
sLongBoxHeight As Single = 4.5)
'X co-ord, Y co-ord, text colour, bold or not, italic or
not,
'font size in points, font
'false if data text needs standard box drawing , text to
print
'if box is longbox for headings with fill, otherwise box
length
'if line then length, line horizontal or vertical
'options for long box
On Error GoTo EH
With Printer
.ScaleMode = vbMillimeters
.FontName = sFont
.FontSize = lFSize
.FontBold = bBold
.FontItalic = bItalic
.ForeColor = lFColor
End With
If sLongBox > 0 Then
Printer.FillColor = lLongBoxColour
Printer.FillStyle = 0 'solid
Call SetBkMode(Printer.hdc, OPAQUE)
SetPrinterOrigin sX, sY - 0.25
Printer.Line -(sLongBox, sLongBoxHeight), lLongBoxColour, B
Call SetBkMode(Printer.hdc, TRANSPARENT)
SetPrinterOrigin sX + 1, sY
Printer.Print sText
Exit Sub
End If
If sLineLength > 0 Then
SetPrinterOrigin sX, sY
Printer.DrawWidth = 1
If bLineHoriz Then
Printer.Line -(sLineLength, 0), vbGrayText
Else
Printer.Line -(0, sLineLength), vbGrayText
End If
Exit Sub
End If
If bText Then
SetPrinterOrigin sX, sY
Printer.Print sText 'print text
Else
SetPrinterOrigin sX, sY - 0.5
Printer.FillColor = vbWhite
Call SetBkMode(Printer.hdc, TRANSPARENT)
Printer.DrawWidth = 1
Printer.Line -(sBoxLength, 4.2), , B
If Len(sText) > 0 Then
Dim sngText As Single
sngText = Printer.TextWidth(sText)
SetPrinterOrigin sX + sBoxLength - 1 - sngText, sY
Printer.Print sText
End If
End If
Exit Sub
EH:
MsgBox Err.Number & vbCrLf & Err.Description
End Sub
Public Sub PrintCoverSheet()
'Dim sPath As String
'Dim picLogo As StdPicture
Dim ptStart As POINTAPI
Dim sSAP As String, sEIR As String
Dim lSAPColour As Long, lEIRColour As Long, lEIR As Long
On Error GoTo EH
' sPath = "E:\VbMyFiles\SAP_wsheet_2005_TER_9.81\Cover_sheets\logo.jpg"
' Set picLogo = LoadPicture(sPath)
' SetPrinterOrigin 145, 14
' Printer.PaintPicture picLogo, 0, 0, 32, 28
' Set picLogo = Nothing
DoPrint 30, 15, , , , 24, , , Trim$("Architect Name") & " " &
Trim$("MCIAT")
DoPrint 30, 25, , , , 12, , , Trim$("Address bla bla bla")
DoPrint 30, 31, , , , 10, , , Trim$("Telephone / email")
DoPrint 15, 50, , , , 18, , , "SAP2005 WORKSHEET / DOCUMENT L1A (2006)"
DoPrint 15, 68, , , , 12, , , CStr(Date)
DoPrint 15, 78, , , , 12, , , "Project Ref: 9999"
DoPrint 15, 88, , , , 12, , , "Project Address:"
DoPrint 20, 99, , , , 12, , , "Client Name"
DoPrint 20, 105, , , , 12, , , "Address1"
DoPrint 20, 111, , , , 12, , , "Address2"
DoPrint 20, 117, , , , 12, , , "Address3"
DoPrint 20, 123, , , , 12, , , "Address4"
DoPrint 15, 135, , , , 12, , , "Copy to: Office"
'insert charts
'draw the lines
DoPrint 10, 168, , , , , , False, , , 0, 70.5, False
DoPrint 72, 168, , , , , , False, , , 0, 62.5, False
DoPrint 86, 168, , , , , , False, , , 0, 62.5, False
DoPrint 100, 168, , , , , , False, , , 0, 70.5, False
DoPrint 10, 168, , , , , , False, , , 0, 90, True
DoPrint 10, 172.5, , , , , , False, , , 0, 90, True
DoPrint 10, 230.5, , , , , , False, , , 0, 90, True
DoPrint 10, 238.5, , , , , , False, , , 0, 90, True
DoPrint 10, 160.5, vbWhite, True, , 12, "Arial", , " Energy Efficiency
Rating", 90, , , , RGB(11, 103, 171), 5.5
DoPrint 75, 169, , , , 7, "Arial", , "Current"
DoPrint 88, 169, , , , 7, "Arial", , "Potential"
DoPrint 11.5, 174, , , True, 7, "Arial", , " Very energy efficient -
lower running costs"
DoPrint 11, 178, vbWhite, True, False, 7, "Arial", False, "(92-100)",
14, , , , RGB(0, 127, 83), 5
DoPrint 24, 178, vbWhite, True, False, 11, "Arial", False, "A", 6, , , ,
RGB(0, 127, 83), 5
DoPrint 11, 185, vbWhite, True, False, 7, "Arial", False, "(81-91)", 21,
, , , RGB(40, 164, 85), 5
DoPrint 30, 185, vbWhite, True, False, 11, "Arial", False, "B", 6, , , ,
RGB(40, 164, 85), 5
DoPrint 11, 192, vbWhite, True, False, 7, "Arial", False, "(69-80)", 28,
, , , RGB(134, 187, 67), 5
DoPrint 36, 192, vbWhite, True, False, 11, "Arial", False, "C", 6, , , ,
RGB(134, 187, 67), 5
DoPrint 11, 199, vbWhite, True, False, 7, "Arial", False, "(55-68)", 35,
, , , RGB(255, 203, 35), 5
DoPrint 42, 199, vbWhite, True, False, 11, "Arial", False, "D", 6, , , ,
RGB(255, 203, 35), 5
DoPrint 11, 206, vbWhite, True, False, 7, "Arial", False, "(39-54)", 42,
, , , RGB(247, 166, 98), 5
DoPrint 48, 206, vbWhite, True, False, 11, "Arial", False, "E", 6, , , ,
RGB(247, 166, 98), 5
DoPrint 11, 213, vbWhite, True, False, 7, "Arial", False, "(21-38)", 49,
, , , RGB(240, 120, 43), 5
DoPrint 54, 213, vbWhite, True, False, 11, "Arial", False, "F", 6, , , ,
RGB(240, 120, 43), 5
DoPrint 11, 220, vbWhite, True, False, 7, "Arial", False, "(1-20)", 56,
, , , RGB(288, 19, 56), 5
DoPrint 60, 220, vbWhite, True, False, 11, "Arial", False, "G", 6, , , ,
RGB(288, 19, 56), 5
DoPrint 11.5, 226, , , True, 7, "Arial", , " Not energy efficient -
higher running costs"
DoPrint 12, 232.5, , , , 12, "Arial", , "England & Wales"
DoPrint 70, 231.5, , , , 8, "Arial", , "EU Directive"
DoPrint 70, 235, , , , 8, "Arial", , "2002/91/EC"
Dim lTemp As Long
'test to try different values for lTemp & lEIR
lTemp = 80
lEIR = 70
sSAP = CStr(lTemp)
Select Case lTemp
Case Is < 21: lSAPColour = RGB(288, 19, 56)
Case Is < 39: lSAPColour = RGB(240, 120, 43)
Case Is < 55: lSAPColour = RGB(247, 166, 98)
Case Is < 69: lSAPColour = RGB(255, 203, 35)
Case Is < 81: lSAPColour = RGB(134, 187, 67)
Case Is < 92: lSAPColour = RGB(40, 164, 85)
Case Is >= 92: lSAPColour = RGB(0, 127, 83)
End Select
'range for pointer between 0 and 100 covers 49mm
ptStart.X = 73: ptStart.Y = 177 + (49 - CLng(lTemp * 0.49))
Call
...
read more »