저는 Graphics.ScaleTransform
을 사용하여 텍스트 줄을 늘려 페이지 너비에 맞게 조정 한 다음 해당 페이지를 인쇄합니다. 그러나이 작업은 인쇄 작업을 비트 맵으로 변환합니다. 많은 페이지를 인쇄 할 경우 인쇄 작업의 크기가 음란물 비율로 증가하고 인쇄 속도가 크게 떨어집니다..NET Graphics.ScaleTransform은 인쇄 작업을 비트 맵으로 변환합니다. 텍스트 크기를 조정하는 다른 방법은 없습니까?
이렇게 크기를 조정하지 않으면 인쇄 작업이 프린터로 텍스트 인쇄 명령을 보내는 것과 같이 매우 작습니다.
제 질문은 Graphics.ScaleTransform
을 사용하여 텍스트의 너비를 늘리는 것 외에 다른 방법이 있습니까? 이를 증명하기
샘플 코드 (인쇄 작업에 확장의 효과를 보여 Print.Test(True)
및 Print.Test(False)
호출 할 것이다) 다음과 같습니다 :
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Drawing.Imaging
Public Class Print
Dim FixedFont As Font
Dim Area As RectangleF
Dim CharHeight As Double
Dim CharWidth As Double
Dim Scale As Boolean
Const CharsAcross = 80
Const CharsDown = 66
Const TestString = "!""#$%&'()*+,-./:;<=>[email protected][\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
Private Sub PagePrinter(ByVal sender As Object, ByVal e As PrintPageEventArgs)
Dim G As Graphics = e.Graphics
If Scale Then
Dim ws = Area.Width/G.MeasureString(Space(CharsAcross).Replace(" ", "X"), FixedFont).Width
G.ScaleTransform(ws, 1)
End If
For CurrentLine = 1 To CharsDown
G.DrawString(Mid(TestString & TestString & TestString, CurrentLine, CharsAcross), FixedFont, Brushes.Black, 0, Convert.ToSingle(CharHeight * (CurrentLine - 1)))
Next
e.HasMorePages = False
End Sub
Public Shared Sub Test(ByVal Scale As Boolean)
Dim OutputDocument As New PrintDocument
With OutputDocument
Dim DP As New Print
.PrintController = New StandardPrintController
.DefaultPageSettings.Landscape = False
DP.Area = .DefaultPageSettings.PrintableArea
DP.CharHeight = DP.Area.Height/CharsDown
DP.CharWidth = DP.Area.Width/CharsAcross
DP.Scale = Scale
DP.FixedFont = New Font("Courier New", DP.CharHeight/100, FontStyle.Regular, GraphicsUnit.Inch)
.DocumentName = "Test print (with" & IIf(Scale, "", "out") & " scaling)"
AddHandler .PrintPage, AddressOf DP.PagePrinter
.Print()
End With
End Sub
End Class
업데이트 : GDI와 상호 운용성 사용 대신 호출합니다. 다음은 관련 코드입니다. GDI 클래스는 위키에서 복사 한 정의로 가득 차 있습니다. 관련 함수 및 상수는 http://pinvoke.net/입니다.
' convert from Graphics units (100 dpi) to device units
Dim GDIMappedCharHeight As Double = CharHeight * G.DpiY/100
Dim GDIMappedCharWidth As Double = CharWidth * G.DpiX/100
Dim FixedFontGDI As IntPtr = GDI.CreateFont(GDIMappedCharHeight, GDIMappedCharWidth, 0, 0, 0, 0, 0, 0, GDI.DEFAULT_CHARSET, GDI.OUT_DEFAULT_PRECIS, GDI.CLIP_DEFAULT_PRECIS, GDI.DEFAULT_QUALITY, GDI.FIXED_PITCH, "Courier New")
Dim CharRect As New GDI.STRUCT_RECT
Dim hdc As IntPtr = G.GetHdc()
GDI.SelectObject(hdc, FixedFontGDI)
' I used SetBkMode transparent as my text needed to overlay a background
GDI.SetBkMode(hdc, GDI.TRANSPARENT)
' draw it character by character to get precise grid
For CurrentLine = 1 To CharsDown
For CurrentColumn = 1 To CharsAcross
With CharRect
.left = GDIMappedCharWidth * (CurrentColumn - 1)
.right = GDIMappedCharWidth * CurrentColumn
.top = GDIMappedCharHeight * (CurrentLine - 1)
.bottom = GDIMappedCharHeight * CurrentLine
End With
' 2341 == DT_NOPREFIX|DT_NOCLIP|DT_VCENTER|DT_CENTER|DT_SINGLELINE
GDI.DrawText(hdc, Mid(TestString & TestString & TestString, CurrentLine+CurrentColumn, 1), 1, CharRect, 2341)
Next
Next
GDI.DeleteObject(FixedFontGDI)
G.ReleaseHdc(hdc)
귀하의 조언에 감사드립니다! 풍부한 편집 컨트롤을 사용해 보았지만 압도적 인 것처럼 보였으므로 오래된 GDI를 사용하여 interop를 사용하여 그래픽 hDC를 호출했습니다. 다행히도 CreateFont는 너비와 높이를 설정하는 것을 지원하며이를 전달합니다. 비트 맵 렌더링이없는 프린터. –