Ghostscript.net print pdf to network printer windows service - vb.net

I am using below code to print pdf but it is not working with windows service using network printer.
Dim gvi As New GhostscriptVersionInfo(New Version(0, 0, 0), Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "gsdll32.dll"), String.Empty, GhostscriptLicense.GPL)
Dim processor As New Ghostscript.NET.Processor.GhostscriptProcessor(gvi, True)
Dim switches As New List(Of String)()
switches.Add("-empty")
switches.Add("-dPrinted")
switches.Add("-dBATCH")
switches.Add("-dNOPAUSE")
switches.Add("-dNOSAFER")
switches.Add("-dPDFFitPage")
switches.Add("-dNumCopies=1")
switches.Add("-sDEVICE=mswinpr2")
switches.Add(Convert.ToString("-sOutputFile=%printer%") & _PrinterName)
switches.Add("-f")
switches.Add(PdfFileName)
processor.StartProcessing(switches.ToArray(), Nothing)

Is the networked printer visible to the user on the machine before you try printing ? The way that the mswinpr2 device works, it requires that the printer be visible to the user on the Windows installation its running from.
You cannot print to a printer over the network, unless that printer is mounted on your own system.

Your call seems correct. But for a network printer, you have to use
-sOutputFile="%printer%\\Hostname\Printer"
The hostname (=the machine the printer is pysically connected to) is mandatory here.

Related

Printing a PDF using vb.net and adobe Reader DC not working windows cannot find the application

I have a program that has been working for a while, it basically prints a pdf file to default printer, i had to put this application on a newer pc with the win version 20h2 and now windows returns an error saying it can not find the application. not sure if its a microsoft thing or if my code can be modified to work with it. One constant has to stay in place, Adobe Reader DC has to remain the default PDF reader. below is the code snippet that does the printing , it has worked since january. now will not work with newer windows version.
Private Sub PrintDocument(src As String)
Dim psi As New Process()
psi.StartInfo.UseShellExecute = True
psi.StartInfo.Verb = "print"
psi.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
psi.StartInfo.FileName = src
psi.StartInfo.CreateNoWindow = True
psi.Start()
psi.WaitForInputIdle()
psi.CloseMainWindow()
psi.Close()
Thread.Sleep(10000)
CheckAndCloseAdobeProcess()
End Sub
The Windows update had probably change your default PDF reader, I guess edge is your new PDF reader.

TelnetExpect Reading Output from Stream in VB.NET

Good Morning,
I have been tasked with writing a program that locates the local port a MAC Address is registered to, and to do that I need to SSH and Telnet into Cisco devices and receive the output of the commands so I can parse it and decide what to do with the information.
So far I have the SSH connection and parsing done no problem thanks to Renci.SshNET. But I am having trouble with the Telnet, I set it up to use Telnetlib.dll and I know it works because I can do "show users" on the switch I'm connecting to and see that one of the vty lines are being occupied by my application. But in the application I'm writing all I get is the application freezing up, none of the buttons work, and I can't see the mouse when I hover over the window, so I'm guessing that the application isn't liking something at run-time.
The code I'm using, in VB.NET is:
Using client As TcpClient = New TcpClient(host, 23)
Dim tel As TelnetStream = New TelnetStream(client.GetStream)
Dim buff(client.ReceiveBufferSize) As Byte
Dim result As String
tel.SetRemoteMode(TelnetOption.Echo, False)
Dim exp As Expector = New Expector(tel)
exp.Expect("username: ")
exp.SendLine(username)
exp.Expect("password: ")
exp.SendLine(password)
exp.Expect(">")
tel.Read(buff, 0, buff.Length)
result = System.Text.Encoding.ASCII.GetString(buff)
MessageBox.Show(result)
End Using
Telnetlib.dll include the definitions for the Expector, SendLine, Expect, and TelnetStream.
I did some debugging and found that it freezes when it goes to execute the result = System.Text.Encoding.ASCII.GetString(buff)
command.
Thanks for any help.

Crystal report printing to wrong printer

I'm troubleshooting an issue with a VB.NET app that I inherited.
The following lines execute print operation:
Me.rptShippingLabel1.PrintOptions.PrinterName = "LabelPrinter"
Me.rptShippingLabel1.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape
Me.rptShippingLabel1.PrintToPrinter(Me.txtLabelQty.Text, False, 1, 1)
There is a Zebra ZDesign TLP2844 connected to workstations via direct USB and named LabelPrinter. However, despite target printer being specified in the code, that Zebra must be set as default printer in Windows, otherwise the job would go to any other printer set as default.
What's even more frustrating is that on some computers, with exactly the same configuration jobs go to correct printer but I can't identify controllable pattern.
Any suggestions why might that be?
Reports in question are disassociated from printer in Design>Page Settings.
Look into your report. In page settings see if report is optimized for display. If yes, uncheck it. If report is optimized for displaying only, PrinterOptions enumeration is being discarded. You could still assign to Printer name property in older framework but not anymore.
Try the following code
Dim rptShippingLabel1 As New CrystalReport1
Dim PrinterSettings1 As New Printing.PrinterSettings
Dim PageSettings1 As New Printing.PageSettings
'Replace it with your printer name
PrinterSettings1.PrinterName = "Microsoft XPS Document Writer"
rptShippingLabel1.PrintToPrinter(PrinterSettings1, PageSettings1, False)
to get the printer name, don't read it from rptShippingLabel1.PrintOptions.PrinterName it will show blank. Try reading from PrinterSettings1.PrinterName.
This is tested with Crystal Reports runtime 13.0.9

Process.StartInfo.Arguments "Network Printer Name" not working

I want to print PDF files on a network printer placed on my print server.
I written the code below, and it works for local printers only. When I use a network printer name, it doesn't not work.
Dim ProcessoImp As New Process
Dim VerToUse As String
VerToUse = "PrintTo"
ProcessoImp.StartInfo.CreateNoWindow = False
ProcessoImp.StartInfo.Verb = VerToUse
ProcessoImp.StartInfo.FileName = PrintFileList(i)
ProcessoImp.StartInfo.Arguments = "\\PrintServerMachine\samsung laser"
ProcessoImp.Start()
ProcessoImp.WaitForExit(10000)
ProcessoImp.CloseMainWindow()
ProcessoImp.Close()
Remember that if I use a local printer, it works perfectly, but if it's a network printer, it does not work!
What can I do to solve this problem?
More than likely, you do not have sufficient rights to print to that network printer via Visual Studio. You may try to impersonate another user or elevate current user access levels to allow printing on that network printer.
Alternatively, you should try using the printing.PrintDocument Class.
This is a duplicate question to this: Printing from ASP.NET to a network printer

Ensure connection to a POSPrinter connected via COM

I need to make sure that the connection to a POS printer is successful before writing data to the database and then printing a receipt. The POSprinter is normally of type BTP 2002NP but may differ. The common thing is that they are all connected via COM-port and NOT usb, so no drivers installed at all on the client.
Can I send some kind of "ping" on a COM-port and check if a device is connected and turned on? Any help or suggestions are very much appreciated.
Additional information, the application is developed in VB.net and Visual Studio 2008
About all you can do is write out a character string to the com port and wait and see if your printer responds with a reply. However the string you write and the string you expect will depend on the printer itself.
Refer to the BTP 2002NP printers programming manual for examples (the first link in google that I looked at)
From looking at the manual an appropriate string to send to the printer is the "DLE EOT n" command which requests that the printer send back its current status.
As for other printers in the range, check out this list of drivers and manuals
btw, this is what i came up with in the end.
Public Function ComTest() As Byte()
Dim TXT As String
TXT = Chr(&H10S) & Chr(&H4S) & Chr(1) 'DLE EOT 1
If OpenCom() Then 'Connect to com
moRS232.PurgeBuffer(Rs232.PurgeBuffers.TxClear Or Rs232.PurgeBuffers.RXClear)
moRS232.Write(TXT)
moRS232.Read(1)
Return moRS232.InputStream
Else
Return Nothing
End If
End Function
the function returns 1 byte. i can then from the manual translate this byte into what state the printer is currently in. this probably works for all ESC/P printers.