Results 1 to 3 of 3

Thread: Printer ScaleHeight/Width confusion [resolved]

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Resolved Printer ScaleHeight/Width confusion [resolved]

    Ok - here goes...

    I've got a deskjet and a big copier/printer. Printing stuff at TWIP position 0 (fully to the the left).

    The deskjet says that the SCALEWIDTH is 10.43 inches in LANDSCAPE mode - but it manages to physically print right on the edge of the paper.

    The big printer says the the SCALEWIDTH is 10.6 inches in LANDSCAPE mode - but it prints 1/4 inch from the edge of the paper.

    I want to fully know the "printable" area - thus the unprintable margins and adjust for all printers - so I have some consistency here...

    Any ideas?
    Last edited by szlamany; Oct 16th, 2004 at 07:40 PM.

  2. #2

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    I found this MS KB article - about using an API GetDeviceCaps to determine printer "printable" area...

    KB article

    Unfortunately I've got a demo tomorrow morning - so I don't have the time to research this for this week...

    Anyone who might have info on this API and use for printer margins, etc - I would greatly appreciate it...

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263
    I used this KB article to develop the following couple of functions...

    Here's a screen shot of what it returns



    First one returns info on printable area - second one formats a string to print about that info...

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    4.  
    5. ' Constants for nIndex argument of GetDeviceCaps
    6. Private Const HORZRES = 8
    7. Private Const VERTRES = 10
    8. Private Const LOGPIXELSX = 88
    9. Private Const LOGPIXELSY = 90
    10. Private Const PHYSICALWIDTH = 110
    11. Private Const PHYSICALHEIGHT = 111
    12. Private Const PHYSICALOFFSETX = 112
    13. Private Const PHYSICALOFFSETY = 113
    14.  
    15. .
    16. .
    17. .
    18.  
    19.  
    20. Public Sub PrintArea(p As Printer, lngdpiX As Long, lngdpiY As Long, lngMarginLeft As Long, lngMarginRight As Long _
    21.                     , lngMarginTop As Long, lngMarginBottom As Long, lngPrintAreaHorz As Long, lngPrintAreaVert As Long _
    22.                     , lngPhysHeight As Long, lngPhysWidth As Long)
    23.  
    24. Debug.Print "   PrintArea"
    25. On Error GoTo Error_Handler
    26.  
    27. Begin:
    28.  
    29.     lngdpiX = GetDeviceCaps(p.hdc, LOGPIXELSX)
    30.    
    31.     lngdpiY = GetDeviceCaps(p.hdc, LOGPIXELSY)
    32.    
    33.     lngMarginLeft = GetDeviceCaps(p.hdc, PHYSICALOFFSETX)
    34.    
    35.     lngMarginTop = GetDeviceCaps(p.hdc, PHYSICALOFFSETY)
    36.    
    37.     lngPrintAreaHorz = GetDeviceCaps(p.hdc, HORZRES)
    38.    
    39.     lngPrintAreaVert = GetDeviceCaps(p.hdc, VERTRES)
    40.    
    41.     lngPhysWidth = GetDeviceCaps(p.hdc, PHYSICALWIDTH)
    42.    
    43.     lngMarginRight = lngPhysWidth - lngPrintAreaHorz - lngMarginLeft
    44.    
    45.     lngPhysHeight = GetDeviceCaps(p.hdc, PHYSICALHEIGHT)
    46.    
    47.     lngMarginBottom = lngPhysHeight - lngPrintAreaVert - lngMarginTop
    48.  
    49. Rtn_Caller:
    50.  
    51.     Exit Sub
    52.  
    53. Error_Handler:
    54.     Call Fatal_Error(Err.Number, Err.Source, Err.Description, "PrintArea")
    55.     Resume Rtn_Caller
    56.  
    57. End Sub
    58.  
    59.  
    60. .
    61. .
    62. .
    63.  
    64. Public Function ScreenResolution(Optional booPrinter As Boolean) As String
    65.  
    66. Dim i As Long, j As Long, k As Long, x As Long, y As Long, z As Long
    67. Dim s1 As String, s2 As String, s3 As String, s4 As String, s5 As String
    68.  
    69. Dim lngdpiX As Long, lngdpiY As Long, lngMarginLeft As Long, lngMarginRight As Long
    70. Dim lngMarginTop As Long, lngMarginBottom As Long, lngPrintAreaHorz As Long, lngPrintAreaVert As Long
    71. Dim lngPhysHeight As Long, lngPhysWidth As Long
    72. Dim strInfo As String
    73.  
    74. Debug.Print "   ScreenResolution"
    75. On Error GoTo Error_Handler
    76.  
    77. Begin:
    78.     i = Screen.Width
    79.     j = Screen.TwipsPerPixelX
    80.     k = i \ j
    81.     x = Screen.Height
    82.     y = Screen.TwipsPerPixelY
    83.     z = x \ y
    84.    
    85.     'iWidth = Screen.Width \ Screen.TwipsPerPixelX
    86.     'iHeight = Screen.Height \ Screen.TwipsPerPixelY
    87.     s1 = CStr(k) & " x " & CStr(z) & " (" & CStr(i) & " @" & CStr(j) & " X " & CStr(x) & " @" & y & ")"
    88.    
    89.     ScreenResolution = s1
    90.    
    91.     If booPrinter Then
    92.         s1 = s1 & vbCrLf & vbCrLf & "Printer Devicename: " & Printer.DeviceName
    93.        
    94.         Call PrintArea(Printer, lngdpiX, lngdpiY, lngMarginLeft, lngMarginRight, lngMarginTop, lngMarginBottom _
    95.                 , lngPrintAreaHorz, lngPrintAreaVert, lngPhysHeight, lngPhysWidth)
    96.        
    97.         strInfo = "Pixels X: " & CStr(lngdpiX) & " dpi"
    98.        
    99.         strInfo = strInfo & vbCrLf & "Pixels Y: " & CStr(lngdpiY) & " dpi"
    100.        
    101.         strInfo = strInfo & vbCrLf & "Unprintable space on left: " & _
    102.                 CStr(lngMarginLeft) & " pixels = " & CStr(lngMarginLeft / lngdpiX) & " inches"
    103.        
    104.         strInfo = strInfo & vbCrLf & "Unprintable space on top: " & _
    105.                 CStr(lngMarginTop) & " pixels = " & CStr(lngMarginTop / lngdpiY) & " inches"
    106.        
    107.         strInfo = strInfo & vbCrLf & "Printable space (Horizontal): " & _
    108.                 CStr(lngPrintAreaHorz) & " pixels = " & CStr(lngPrintAreaHorz / lngdpiX) & " inches"
    109.        
    110.         strInfo = strInfo & vbCrLf & "Printable space (Vertical): " & _
    111.                 CStr(lngPrintAreaVert) & " pixels = " & CStr(lngPrintAreaVert / lngdpiY) & " inches"
    112.        
    113.         strInfo = strInfo & vbCrLf & "Total space (Horizontal): " & _
    114.                 CStr(lngPhysWidth) & " pixels = " & CStr(lngPhysWidth / lngdpiX) & " inches"
    115.        
    116.         strInfo = strInfo & vbCrLf & "Unprintable space on right: " & _
    117.                 CStr(lngMarginRight) & " pixels = " & CStr(lngMarginRight / lngdpiX) & " inches"
    118.        
    119.         strInfo = strInfo & vbCrLf & "Total space (Vertical): " & _
    120.                 CStr(lngPhysHeight) & " pixels = " & CStr(lngPhysHeight / lngdpiY) & " inches"
    121.        
    122.         strInfo = strInfo & vbCrLf & "Unprintable space on bottom: " & _
    123.                 CStr(lngMarginBottom) & " pixels = " & CStr(lngMarginBottom / lngdpiY) & " inches"
    124.        
    125.         s1 = s1 & vbCrLf & vbCrLf & strInfo
    126.        
    127.         ScreenResolution = s1
    128.     End If
    129.    
    130. Rtn_Caller:
    131.     Exit Function
    132.  
    133. Error_Handler:
    134. '    Call Fatal_Error(Err.Number, Err.Source, Err.Description, "ScreenResolution")
    135.     Resume Rtn_Caller
    136.  
    137. End Function
    Attached Images Attached Images  
    Last edited by szlamany; Oct 16th, 2004 at 07:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width