Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When I print to one printer on the network (HP LaserJet 8100 Series PCL 5e) the report comes out fine, however when I print to another printer on the network (RICOH Aficio 1022 PCL 5e) the report comes out as gobble-de-gook.

 

The printer drivers for both printers are installed on the client machine I use.

 

The machine is running on windows 2000.

 

I then downloaded 'vbnet_win_printtoprinter.exe' from Crystal Decisions and ran the application, printing the sample reports to the two different printers again, the same thing happened.

 

It seems the font types aren�t recognised.

 

I then decided to try this on an XP machine instead of a windows 2000 machine, it printed perfect again on one printer but gobble-de-gook again on the other (however some font types printed ok this time).

 

The strange thing is, this only happens when the report is printed using code. When the reports are printed using the printer button of a crystal report viewer these reports print off fine on all machines. My problem is I need to be able to print the reports using.

  • 5 weeks later...
Posted

Hi,

 

May I know your script? I also neet to print using a network printer through script. I don't know how to call the network printer using a CreateFile(). I tried calling a local printer port and worked fine.

 

We can investigate on this together since I also need to specify fonts to printer by script since I will be printing a barcode label.

 

Thanks.

Posted

Hi Susana,

 

Is it a crystal report you are trying to print?

If so I'd recomment having a look at the dotnet example from crystal decisions. Follow the link below...

 

http://support.crystaldecisions.com/communityCS/FilesAndUpdates/vbnet_win_printtoprinter.exe.asp

(This VB .NET Windows application demonstrates how to print a report directly to a printer at runtime using the engine object model. This application is for use with Crystal Reports for Visual Studio .NET and later versions.)

 

 

Change a font at runtime, I'd recommend the example...

 

http://support.crystaldecisions.com/communityCS/FilesAndUpdates/vbnet_win_changefont.exe.asp

(This Visual Basic .NET sample Windows application demonstrates how to change the font of database and text field at runtime. This application is for use with Crystal Reports for Visual Studio .NET and later versions.)

 

 

As it is Ive solved my issue. My problem was resolved by re-installing the printer on the network and using a different driver.

To print to a network printer using script I used the PrintToPrinter method and under the PrinterName property I entered the url location of my network printer.

 

 

I hope you find these examples useful. I know how frustrating it can be when you cant get it to work.

 

If you need any more help please dont hesitate to ask (, although I cant guarantee I'll always have an answer, I'll try and help if I can).

 

Good luck.

 

Lee :p

Posted

Hi Lee,

 

Thanks for the tip. This could help me in my other printing problems. But unfortunately, this is not what I need at the moment.

 

I am trying to print a batch of records directly to a barcode printer, which is a network printer, using TCP/IP.

 

Initially (for investigation purposes), I have these scripts:

 

*******start code*******

Public Class PrintBarCode

Inherits System.Web.UI.Page

Public Const GENERIC_WRITE = &H40000000

Public Const OPEN_EXISTING = 3

Public Const FILE_SHARE_WRITE = &H2

 

Public Shared LPTPORT As String

Public Shared hPort As Integer

Public Shared retval As Integer

Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" ( _

ByVal lpFileName As String, ByVal dwDesiredAccess As Integer, _

ByVal dwShareMode As Integer, _

ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, _

ByVal dwCreationDisposition As Integer, ByVal dwFlagsAndAttributes As Integer, _

ByVal hTemplateFile As Integer) As Integer

 

Public Declare Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As Integer) As Integer

'Dim retval As Integer

 

Public Structure SECURITY_ATTRIBUTES

Private nLength As Integer

Private lpSecurityDescriptor As Integer

Private bInheritHandle As Integer

End Structure

 

Public Shared Function Print()

Dim Texxxt As String

'Dim SA As SECURITY_ATTRIBUTES

Dim SA

Dim outFile As FileStream, hPortP As IntPtr

 

LPTPORT = "LPT1"

Texxxt = "testing"

hPort = CreateFile(LPTPORT, GENERIC_WRITE, FILE_SHARE_WRITE, SA, OPEN_EXISTING, 0, 0)

 

hPortP = New IntPtr(hPort) 'convert Integer to IntPtr

outFile = New FileStream(hPortP, FileAccess.Write, False) 'Create FileStream using Handle

 

Dim fileWriter As New StreamWriter(outFile)

'MessageBox.Show(RichTextBox1.Text)

' fileWriter.AutoFlush = False

fileWriter.WriteLine("Testing")

fileWriter.WriteLine("Hello World2")

fileWriter.WriteLine("Hello World1")

fileWriter.WriteLine("Hello World2")

fileWriter.Write(Chr(12)) '12

fileWriter.Flush()

fileWriter.Close()

outFile.Close()

 

retval = CloseHandle(hPort)

 

End Function

 

End Class

 

*******end code*******

 

This also came from a help... :)

 

Using LPT1 or any other local printers work but when I change the value for LPTPORT with a network printer, "//dbpweb03/Prodigy Label Printer" which is the barcode printer, the CreateFile() function returns -1.

 

to give you an idea of what I really need, below are foxpro codes, which does print records directly to a barcode printer. It also sends escape characters to automatically configures the barcode printer at runtime:

 

? CHR(2) + "L" + CHR(13) &&: ' ENABLE PRINT MODE

? "H15" + CHR(13) && : ' SET BURN TIME (HIGHER = DARKER)

? "PC" + CHR(13) && : ' SET PRINT SPEED TO 2.0 IPS

? "SC" + CHR(13) && : ' SET SLEW RATE TO 2.0 IPS

? "O0000"+CHR(13) && : ' SPITS OUT THE LABEL IN BATCH

MODE

 

'prints one by one a record

? CHR(2) + "L" + CHR(13) &&: ' ENABLE PRINT MODE

? "H15" + CHR(13) && : ' SET BURN TIME (HIGHER = DARKER)

? "PC" + CHR(13) && : ' SET PRINT SPEED TO 2.0 IPS

? "SC" + CHR(13) && : ' SET SLEW RATE TO 2.0 IPS

? "O0000"+CHR(13) && : ' SPITS OUT THE LABEL IN BATCH

MODE

 

I hope you could help me on this. This is actually my first time to use VB.NET so any tips will be of great help.

 

Hope to hear from you soon. Thanks in advance :)...

 

Susana

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...