Printing in VB .NET on Pocket PC

G

Guest

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
 
G

Ginny Caughey [MVP]

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.
 
G

Guest

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
 
M

Milsnips

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
 
G

Ginny Caughey [MVP]

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.
 
M

Milsnips

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
 
G

Ginny Caughey [MVP]

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.
 
M

Milsnips

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
 
G

Ginny Caughey [MVP]

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.
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top