我在服务器上上传了一个文本文件。
当用户点击打印按钮时,我希望使用他/她的打印机打印文件。
目前我使用的是以下代码,但它用于服务器端打印。
Protected Sub btnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPrint.Click
Dim fileName As String = ""
For x As Integer = 0 To FileImageList.Count - 1
If FileImageList(x).parent.backcolor = Drawing.Color.Orange Then
fileName = FileNameList(x).text
End If
Next
ReadFile(fileName, Server.MapPath("~\Medical\Users\" & Session("DocumentUploader") & "\Uploaded\"))
printDocument1.Print()
End Sub
Private Sub printDocument1_PrintPage(ByVal sender As Object, _
ByVal e As PrintPageEventArgs)
Dim charactersOnPage As Integer = 0
Dim linesPerPage As Integer = 0
Dim font As System.Drawing.Font = New Font("Times New Roman", 14, FontStyle.Regular, GraphicsUnit.Pixel)
' Sets the value of charactersOnPage to the number of characters
' of stringToPrint that will fit within the bounds of the page.
e.Graphics.MeasureString(stringToPrint, font, e.MarginBounds.Size, _
StringFormat.GenericTypographic, charactersOnPage, linesPerPage)
' Draws the string within the bounds of the page
e.Graphics.DrawString(stringToPrint, font, Brushes.Black, _
e.MarginBounds, StringFormat.GenericTypographic)
' Remove the portion of the string that has been printed.
stringToPrint = stringToPrint.Substring(charactersOnPage)
' Check to see if more pages are to be printed.
e.HasMorePages = stringToPrint.Length > 0
End Sub