Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

i created a small VB.NET Windows app to print labels . when i print the label printer responds but it prints blank labels. i have set the configuration to use default printer settings but it still prints blank. any help will be greatly appreciated please see my code below.

VB
Static intCurrentChar As Int32

        Dim font As New Font("Arial", 24)

        Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32

        With PrintDocument1.DefaultPageSettings

            PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom

            PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right

            marginLeft = .Margins.Left

            marginTop = .Margins.Top

        End With

        Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)

        Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)

        Dim fmt As New StringFormat(StringFormatFlags.LineLimit)

        Dim intLinesFilled, intCharsFitted As Int32

        e.Graphics.MeasureString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)

        e.Graphics.DrawString(Mid(RichTextBox1.Text, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)

        intCurrentChar += intCharsFitted
Posted
Comments
E.F. Nijboer 18-Feb-13 5:05am    
Did you make sure the printer works properly? By printing a test page or something using another application. Also, does your code work on other printers? Maybe try a pdf printer, which is also very environment friendly ;-)
Member 9742322 18-Feb-13 5:08am    
Hi , yes i have printed to normal printer and the page prints as expected.
the label printer itself works as well as they currently use it to print labels but they have to choose from 400 different templates which is very time consuming
E.F. Nijboer 18-Feb-13 5:16am    
Good to know.
- Why do you declare intCurrentChar as static?
- Have you checked the result of Mid(RichTextBox1.Text, intCurrentChar + 1)?
- Font size of 24 seems kind of large, maybe try a somewhat smaller size.
Member 9742322 18-Feb-13 5:32am    
Hi,
i got this code from a sample app for printing from VB.net and not to sure what to change on it.
The font size is currently what they use to print on the labels.
Member 9742322 18-Feb-13 5:36am    
Sorry i am quite new to VB.net still a learning process for me
how can i check the result of Mid(RichTextBox1.Text, intCurrentChar + 1)?

1 solution

Just an update i managed to sort the problem out by using their SDK kit . what i can pick up was that because the printer was not on my machine it picked up normal A4 paper

after installing printer on my pc it picked correct setting and printed correctly
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900