Hi All..
I have a one question please solve this..
I have a one web page, in that page one Print Button is there..
I want to write a C# code for print button for printing the web page contents
without asking the print dialog box...
it means whenever i click the print button, the page will be priting directly..
If anybody having this type of code please send me as much as possible...
i am waiting for you replayssss
please do something friends.....
Thanks in Advance..
Niradhip ChakrabortyPosted Aug 6, 2008, 11:52 AM
If you are using window.print then I don’t think it is possible. If you are calling window.print(),It is simply an indirect method to the browser, so whether a dialog shows up or not is dependent on the browser (and maybe it's settings, if applicable),
not your code. I think it is a security related thing which restrict a web page to send thousand unwanted pages to your printer. In the same point of time it will make the code more cross-browser compatible. If you want to set the print settings, you could do something like have the button pop up an window.alert() asking the user to change their print settings before it calls the window.print().
Basu MalipatilPosted Aug 6, 2008, 11:57 PM
Hi Friend..
Thanks for your valueable answer, i am also think like that as you telling,its a security purpose.... fine !...
but, i think you seen some applications like Railway Reservation, Restorent, etc while printing the tickets or bills,they click the print button it is automatically printed..i thought they write the own code in theire project for print button,thats why i am asking, i want such type of answer...in my project also same thing, my client wants asking such type only...what to do ? there is no another way ? except printer setting or window.print(); method ?
i have a one VB code i found in Google, its working fine, but it will be printing blank page & in that code they are passing some parameters, really i did't get that code... so see that code, if you got the answer tell me how to use that ok..
Here is that code:
There is a one Gridview contains some data like MRN, Name,Address etc and below Gridview i am taking one Commnd Button is there called Print ..so when i click the Print Button I want to print Gridview contents that’s all..when i click the Print Button records will be printing directly
-------------------Button----------------
Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
Dim strPrinterName As String
Call SetDefaultSystemPrinter(strPrinterName)
End Sub
--------------------Function -----------------
Public Function SetDefaultSystemPrinter(ByVal strPrinterName As String) As Boolean
' Imports System.Drawing.Printing
' Example: SetDefaultSystemPrinter("Lexmark T620") - local printer
' Example: SetDefaultSystemPrinter("\\Server01\Lexmark T522") - network printer
Dim strOldPrinter As String
Dim WshNetwork As Object
Dim pd As New PrintDocument
'Dim x As String
' Set the default system printer
Try
'strPrinterName = InputBox("Printer name", "Set the default system printer", strPrinterName)
strPrinterName = "\\192.168.1.100\FIRST FLOOR PRINTER" //my system printer path
strOldPrinter = pd.PrinterSettings.PrinterName '/ Get the system default printer
WshNetwork = CreateObject("WScript.Network")
WshNetwork.SetDefaultPrinter(strPrinterName)
pd.PrinterSettings.PrinterName = strPrinterName '/ Specify the printer to use.
If pd.PrinterSettings.IsValid Then '/ Check that the printer exists
pd.Print() '/ Print a document
Return True
Else
MessageBox.Show("Printer <" & strPrinterName & "> is invalid.")
WshNetwork.SetDefaultPrinter(strOldPrinter)
Return False
End If
Catch exptd As Exception
WshNetwork.SetDefaultPrinter(strOldPrinter)
Return False
Finally
WshNetwork = Nothing
pd.Print()=Nothing
End Try
End Function '/ SetDefaultSystemPrinter
Thank you Sir...