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
Related
I use the following code
Dim PrintR_ As Printing.PrinterSettings = ReportViewer1.PrinterSettings
PrintR_.PrinterName = "Microsoft XPS Document Writer"
ReportViewer1.PrintDialog(PrintR_)
However, when executed, the following form appears
All I want is not to see this screen and to print directly based on the printer's specific name
Thanks for everyone who helps.
I want to be able to have my app check if Adobe Reader is installed.
If it is, I want my program to use it to display the PDF, if not I want to use my free (limited) reader control to display the PDF.
Any suggestions
Edit:
my question seems to be little to broad
So basicly i'm trying to do the following
Try
Dim AcroDisplay As New AxAcroPDFLib.AxAcroPDF
AcroDisplay.Left = 50
AcroDisplay.Top = 50
AcroDisplay.Width = 200
AcroDisplay.Height = 500
me.Controls.Add(AcroDisplay)
MsgBox("Acro Added")
Catch ex As Exception
MsgBox("Acro Not installed")
''Load Alternate PDF viewer (Spire.pdf Free)
End Try
However when Acrobat Isn't installed instead of going to the catch statement it just shows an error "Could not load assembly" and then exits the sub
What i want is that if acrobat control isn't installed, that it wont display and error and instead just load the alternate pdf viewer
is there a way to check for AxAcroPDFLib.AxAcroPDF before attempting to load?
Hopefully this makes things clearer
Edit 2:
After Searching and screwing around i found 2 possible ways i might be able to do this
however both i can't find how to do it in VB.net
First
Look for AxAcroPDFLib.AxAcroPDF in available namespaces
found C# example but i don't know how to change it to Vb.net
C# - How to check if namespace, class or method exists in C#??
Second
Add Unhandled Exception Handler
also found a few examples but none seem to work
Any Chance anyone could direct me to a working example for either (or both) of these options
Manged to fin a working solution, doesn't work how i was originally thinking but it doe work just fine
i used the following code
Dim AdobeSoftwares As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("ADOBE")
If AdobeSoftwares Is Nothing Then
'MessageBox.Show("No Adobe Software")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
Else
If Not Array.IndexOf(AdobeSoftwares.GetSubKeyNames, "Acrobat Reader") = -1 Then
'MessageBox.Show("Adobe Reader Installed")
Dim PdfDisplay As New AxAcroPDFLib.AxAcroPDF
PDFControl = "Acrobat"
Else
'MessageBox.Show("Adobe Reader Not Installed")
Dim PdfDisplay As New PdfiumViewer.PdfViewer
PDFControl = "Pdfium"
End If
End If
Then in my display code i just look to see what "PDFControl" is in use and run the relevant code to display in that display
So now if adobe reader is installed, I'll be using its control, and if it isn't I'll be using the free (but less featured) control to display PDF files
So hopefully if anyone else is looking at doing similar to me then they can
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
I'm trying to print an excel spreadsheet using VB.NET but I'm getting an error
Unable to set the PaperSize property of the PageSetup class
Here is my code,
Dim oldCI As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("en-US")
With application
.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable
.Visible = False
.EnableEvents = False
.DisplayAlerts = False
.ScreenUpdating = False
End With
Dim workbook As Excel.Workbook
Dim worksheet As Excel.Worksheet
'Open as readonly and do not update links
workbook = application.Workbooks.Open(_fileName, 2, True)
For Each worksheet In workbook.Worksheets
worksheet.PageSetup.PaperSize = _paperSize
Next
workbook.PrintOutEx()
workbook.Close(False)
application.Quit()
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI
worksheet = Nothing
application = Nothing
This code works on my development machine, as soon as I deploy to the test server the code fails. There is already a default printer driver installed on the server.
You need to install printer drivers. The PageSetup class of Excel must interact with the printer drivers
I'm having similar issue running related code on Windows 8 operating under Mac Parallels (Virtual Machine). For anyone who are doing Visual Studio deployment on Mac Parallels, here's what I'm doing:
Disable Printers sharing between Mac and Windows. Go to Parallels
(VM) > Configure > Hardware and click Print. Uncheck 'Add all Mac
printers' and 'Synchronize Default Printer'
Install printer's driver on Windows
In order to get assigned IP address by the same wireless router
(if you need to connect to printer wirelessly), you need to set up
networking as bridged. Go to Parallels
(VM) > Configure > Hardware > 'Network 1' and choose Networking type as Airport and DHCP server as Auto
The issue at the core is in the _paperSize constant. In my case, it was giving the same error on: (forgive c#)
worksheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperLedger;
depending on the printer, for example the "ledger" size paper may be defined as 11x17 or Tabloid. Find out what the print driver refers to the page sizing and then
DIDN'T WORK:
excel.ActiveSheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperLedger
excel.ActiveSheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaper11x17
WORKED:
excel.ActiveSheet.PageSetup.PaperSize = Excel.XlPaperSize.xlPaperTabloid
I hope this can help anyone having frustrating issues with funny inconsistencies of Microsoft Excel's enums.
Confirmation of XSham's answer from Microsoft:
https://support.microsoft.com/de-de/help/291298/you-cannot-use-page-setup-properties-in-excel-if-no-printers-were-inst
Symptoms
When you run a Microsoft Visual Basic for Applications macro that attempts to set or get the page setup properties for any
sheet in a workbook in Microsoft Excel, you may receive either of the
following error messages:
Run-time error '1004': Unable to set the x property of the PageSetup
class Run-time error '1004': Unable to get the x property of the
PageSetup class
Cause
This problem occurs when there are no printer drivers installed on your computer. Excel cannot set or get page setup properties if no printer drivers are installed.
Resolution
To prevent this problem from occurring, install a printer driver on your computer. Use the Printers option in Control Panel to add and remove printer drivers.
You can use office automation to change the page size something like this
worksheet.PageSetup.PaperSize = WdPaperSize.wdPaperLetter
or choose any other paper type from the dropdown list on "WdPaperSize."
hope it will help you a bit.
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.