打印文本文件的内容的客户端的使用的打印机asp.net [英] Print the contents of a text file on the client's printer using asp.net

查看:311
本文介绍了打印文本文件的内容的客户端的使用的打印机asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有上载到服务器上的一个文本文件中。

I am having a text file uploaded on the server.

在上打印按钮,用户点击我想要的文件使用他/她的打印机进行打印。

When a User Clicks on print button I want the file to be printed using his/her printer.

目前我使用的是低于code,但它是在服务器端打印。

Currently I am using the below code, but it is for the server side printing.

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

推荐答案

使用JavaScript的<一个href=\"http://www.htmlgoodies.com/beyond/javascript/article.php/3471121/Print-a-Web-Page-Using-JavaScript.htm\"相对=nofollow>在窗口打印功能 对象。

Use the Javascript print function of the window object.

这篇关于打印文本文件的内容的客户端的使用的打印机asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆