0

我在服务器上上传了一个文本文件。

当用户单击打印按钮时,我希望使用他/她的打印机打印文件。

目前我正在使用下面的代码,但它是用于服务器端打印的。

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

在此处输入图像描述

4

1 回答 1

0

使用对象的Javascript打印功能window

于 2013-05-06T19:35:01.237 回答