使用asp.net打印客户端打印机上的文本文件的内容
问题描述:
我正在服务器上传文本文件。使用asp.net打印客户端打印机上的文本文件的内容
当用户点击打印按钮时,我希望使用他/她的打印机打印文件。
当前我正在使用下面的代码,但它是用于服务器端打印。
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
我刚刚尝试了你的suggession。但它打印整个页面。我想打印文本文件的内容。 – Vishal 2013-05-06 19:41:58
您需要有一个只显示您想要打印的内容的页面,然后在该页面调用'print'功能。例如,像维基百科这样的站点,每个页面都有一个“打印友好”的版本,这正是你所需要的。 – Renan 2013-05-06 19:44:58
雅但它仅打印半页。 2分钟后查看问题中附带的图片。 – Vishal 2013-05-06 19:49:48