Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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.
 
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 17-Feb-13 22:58pm
Comments
E.F. Nijboer at 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 at 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 at 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 at 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 at 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)?
Member 9742322 at 18-Feb-13 6:02am
   
after a bit of reading i put a label to display Mid(RichTextBox1.Text, intCurrentChar + 1) and it gives me the same as what is in my Richtextbox
E.F. Nijboer at 18-Feb-13 6:43am
   
Ah, okay. So it has text. By the way, be sure to check this article on debugging in visual studio. Makes live much easier because you can step through code and check what happens line-by-line. You might want to put a breakpoint after measuring the string and check out intCharsFitted to see if there will be any characters drawn.
 
http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn
Member 9742322 at 1-Mar-13 4:11am
   
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

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  

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



Advertise | Privacy | Mobile
Web01 | 2.8.141022.2 | Last Updated 1 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100