在我的應用程序中,我需要打印報告而不轉換爲pdf或任何其他格式。只要用戶單擊打印按鈕,我需要打印記錄。我使用了以下代碼但不幸的是,這不是直接打印,它是轉換成pdf然後打印。轉換爲pdf需要很多時間,這使我們的生活變得可怕。以下是我的代碼。請幫助....在Asp.net中直接打印
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
@ Chris,怎麼可能? – Nandini 2010-02-05 08:58:35
舉一個例子:如果您擁有網絡上的惠普打印機,則可以直接連接到Web服務器的IP地址和適當的端口,並將PCL 5命令直接發送到打印機。再次,這隻會在非常有限的情況下工作,但它是可能的。 – chris 2010-02-05 14:11:13