Reputation: 393
In my application,i need to print my reports without converting to pdf or any other formats.I need to print the record as soon as the user clicks the print button.i have used the following code.but unfortunately,this is not direct print,it is converting into pdf and then printing.converting to pdf takes a lot of time which makes our life dreadful.Below is my code.Please help....
Private Sub imgPrint_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgPrint.Click
'Function to open connection and table
Dim dt As DataTable
Dim SQLString As String = TKSUCSearchChild.SQLWhereClause
Try
'dt = GetTableData("View_Item", SQLString, SQLOrderByClause)
'dt = Your DataTable
oRpt = New YourReportName
oRpt.SetDataSource(dt)
View_PickingSlip.ReportSource = oRpt
Dim exp As ExportOptions
Dim req As ExportRequestContext
Dim st As System.IO.Stream
Dim b() As Byte
Dim pg As Page
pg = View_PickingSlip.Page
exp = New ExportOptions
exp.ExportFormatType = ExportFormatType.PortableDocFormat
exp.FormatOptions = New PdfRtfWordFormatOptions
req = New ExportRequestContext
req.ExportInfo = exp
With oRpt.FormatEngine.PrintOptions
.PaperSize = PaperSize.PaperLegal
.PaperOrientation = PaperOrientation.Landscape
End With
st = oRpt.FormatEngine.ExportToStream(req)
pg.Response.ClearHeaders()
pg.Response.ClearContent()
pg.Response.ContentType = "application/pdf"
ReDim b(st.Length)
st.Read(b, 0, CInt(st.Length))
pg.Response.BinaryWrite(b)
pg.Response.End()
dt.Dispose()
Catch ex As Exception
ShowError(ex.Message)
End Try
End Sub
Upvotes: 1
Views: 2765
Reputation: 2119
Another option (if you have a captive audience with IE/Windows) is to run an "agent" process on the client machine. You can then have a web page "poke" that process with the data to be printed. In modern IE, the easiest way to do this is with APP (asynchronous pluggable protocols).
Without the "benefit" of IE/Windows, you're pretty much stuck with PDF.
Upvotes: 0
Reputation: 37480
@AGoodDisplayName is mostly right. However, you don't give details of your environment - if you're building an intranet-based application, it is possible to have the server print directly to a printer, if that printer is accessible to the server.
There will be issues with security, and it will be a problem if you have many users with many printers, but it is possible.
Upvotes: 0
Reputation: 5653
There is no way to accomplish this becuase you can't issue commands to the client from the server to make the computer print, it just doesn't work that way. There are ways to print using pdf's, but it is not very elegant and you stated you don't want to use pdfs...other than that I think you would have write some kind of browser plugin that would have to be installed on the machine that needs to print.
Upvotes: 1