Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Printing in VB .NET on Pocket PC

127 views
Skip to first unread message

Alex

unread,
Mar 21, 2007, 7:50:10 AM3/21/07
to
Hello,

I'm writing an application in VB .NET to run on a Pocket PC Device (HP iPaq)
and at one point, it's supposed to print a text file. After searching the
Internet, I found that I should use System.Drawing.Printing.PrintDocument for
printing.

Apart from the fact that I'm not quite sure how to use PrintDocument, I
haven't been able to experiment at all, because I can't even find
System.Drawing.Printing . It says that the namespace cannot be found.

Is there something I should import or add to the project properties to make
the Printing object accessible? I don't suppose anybody would have any code
samples on how to use PrintDocument on a Pocket PC application?

Any help will be greatly appreciated! Thanks in advance,

Alex

Ginny Caughey [MVP]

unread,
Mar 21, 2007, 8:00:25 AM3/21/07
to
Alex,

It sounds like you found a solution for the desktop, not for a PocketPC.

The easiest way I've found to print to a specific printer connected by some
sort of serial connection is to use the SerialPort class to send the output
to that printer. (You just write a line at a time from the text file.) For
support for a range of printers, there is a 3rd party product called
PrinterCE from FieldSoft that is popular.

--
Ginny


"Alex" <Al...@discussions.microsoft.com> wrote in message
news:15FC1F8C-C09B-4B78...@microsoft.com...

Alex

unread,
Mar 22, 2007, 5:05:49 AM3/22/07
to
Hi Ginny,

Thanks for your reply. I'll look into the PrinterCE software. I was thinking
more like a Bluetooth printer connected to a PDA. I guess there is no way to
do this directly from VB?

Thanks,

Alex

Milsnips

unread,
Mar 22, 2007, 6:40:28 AM3/22/07
to
Hi there,

i just finished a project using vb.net to print from windows mobile 5 to a
usb blutooth printer adapter via serial port. here is the code i use (i
compile the printable content into a text file, then send it to the serial
port - code example below:

-----------------------
Sub SendToSerial(ByVal filename As String)
Dim p As System.IO.Ports.SerialPort
Dim fs As IO.StreamReader
Dim portname As String = "COM6:"
Dim sendValue As String = ""

Try
p = New System.IO.Ports.SerialPort(portname)
p.WriteTimeout = 500
p.ReadTimeout = 500

Try
p.Open()
fs = New IO.StreamReader(filename)
Do Until fs.EndOfStream
sendValue = fs.ReadLine
p.WriteLine(sendValue)
Loop
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
fs = Nothing
If p.IsOpen Then p.Close()
p.Dispose()
p = Nothing
End Try
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
p = Nothing
End Sub
-----------------------
hope it helps.
regards,
Paul

"Alex" <Al...@discussions.microsoft.com> wrote in message

news:7CC5291D-49C1-46C1...@microsoft.com...

Ginny Caughey [MVP]

unread,
Mar 22, 2007, 7:45:00 AM3/22/07
to
Alex,

As Paul says, it works fine. Bluetooth printers appear as serial devices.
The main difference I find with Bluetooth printers is that I need to delay
somewhat longer after printing each line to allow the printer to keep up.

--
Ginny


"Alex" <Al...@discussions.microsoft.com> wrote in message

news:7CC5291D-49C1-46C1...@microsoft.com...

Milsnips

unread,
Mar 22, 2007, 8:33:45 AM3/22/07
to
Yes Ginny, i forgot to mention that. Im using a BlueTake BT200 blutooth
printer adapter (32k cache) connected to an Epson LX300+ (i think 4kb or 8kb
cache) so if the file i'm sending is larger than what the cache can handle,
i add the line:

Threading.Sleep(1000) //sleep for 1 second after it has passed x bytes of
datatransfer, then i reset that counter and continue

regards,
Paul

"Ginny Caughey [MVP]" <ginny.caug...@wasteworks.com> wrote in message
news:98627B80-9AF6-4C32...@microsoft.com...

Ginny Caughey [MVP]

unread,
Mar 22, 2007, 9:44:41 AM3/22/07
to
Paul,

Yes, very important. I usually just delay maybe 100 ms after each line, but
in any case, it is possible to overrun the buffer on all the printers I've
tried.

--
Ginny


"Milsnips" <mils...@hotmail.com> wrote in message
news:uiVZX5Hb...@TK2MSFTNGP03.phx.gbl...

Milsnips

unread,
Mar 22, 2007, 10:33:59 AM3/22/07
to
Hey Ginny,

While i'm still on the topic, i am currently printing only text files, but
i'd like to incorporate barcode image or/and company logo image into my
printouts (eg. invoice with company logo on top and scannable barcode on the
bottom).

I guess this depends on the printer's support for printing graphics, which i
think most of the Epxon LX printers can print out.
Any ideas on how i'd go about passing a graphic to be printed via serial
port?

thanks,
Paul

"Ginny Caughey [MVP]" <ginny.caug...@wasteworks.com> wrote in message

news:F1416BB9-5D3D-49D3...@microsoft.com...

Ginny Caughey [MVP]

unread,
Mar 22, 2007, 11:04:11 AM3/22/07
to
Paul,

You need to use printer specific codes to turn the barcode printing on and
off, but once you know what the output stream is supposed to look like, you
just send that out the port like you do your regular text.

--
Ginny


"Milsnips" <mils...@hotmail.com> wrote in message

news:O5Lej8Ib...@TK2MSFTNGP03.phx.gbl...

Milsnips

unread,
Mar 22, 2007, 11:11:38 AM3/22/07
to
Ok, i'll give that a go and see how i come along.
Thanks for your help.

regards,
Paul

"Ginny Caughey [MVP]" <ginny.caug...@wasteworks.com> wrote in message

news:D27E473A-71D5-4A38...@microsoft.com...

Alex

unread,
Mar 23, 2007, 10:10:03 AM3/23/07
to
Hi Paul & Ginny,

I just wanted to thank you for all your help. I'm actually still waiting for
the bluetooth card for the HP printer so I haven't been able to test it.

Thanks again,

Alex

0 new messages