Tom
Tom

Reputation: 16246

C# or VB scaling the text being sent to a printer

enter image description here

I am using this to print text to a label printer:

Private Sub PrintTextControl_PrintPage(
    ByVal sender As System.Object, 
    ByVal e As System.Drawing.Printing.PrintPageEventArgs) 
    Handles PrintTextControl.PrintPage
    '.....
    e.Graphics.DrawString("Hello World", font1, Brushes.Black, x, y, strFormat)
    '.....
End Sub

It works well, except that the standard fonts are quite wide for the label printer, even the "Arial Narrow".

I like the Arial/Sanserif style fonts as they are clean and clear. I looked into 3rd party non-standard fonts, but no luck finding any Airal/Sanserif style clean clear fonts.

Is there a way to scale the text to "squeeze" them horizontally? I am not talking about using a smaller font, as the whole word will become smaller. I want it to keep the same height, just scale it narrower.

Upvotes: 0

Views: 1007

Answers (1)

bwdeng
bwdeng

Reputation: 358

Try this out:

Private Sub PrintTextControl_PrintPage(
    ByVal sender As System.Object, 
    ByVal e As System.Drawing.Printing.PrintPageEventArgs) 
    Handles PrintTextControl.PrintPage
    '.....
    Dim scaleMatrix As New Matrix()
    scaleMatrix.Scale(0.8, 1)
    e.Graphics.Transform = scaleMatrix
    e.Graphics.DrawString("Hello World", font1, Brushes.Black, x, y, strFormat)
    '.....
End Sub

Just replace the 0.8 with the scale value appropriate for your printer.

Upvotes: 1

Related Questions