VB.net PDF格式打印多页

前端之家收集整理的这篇文章主要介绍了VB.net PDF格式打印多页前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
    Dim dt As DataTable         '数据集
    Dim cyMgr As CyManagement = New CyManagement()


    Private Sub DeskOrderEfficiencyForm2_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        dt = cyMgr.CyAgent()
        DataGridView1.DataSource = dt
    End Sub

 

    Dim pageCount = 0   '总页数
    Dim currePage = 0   '当前页数
    Dim pageSize = 0    '每页显示数目
    ' 打印订单
    Private Sub orderPrintDocument_PrintPage(ByVal sender As System.Object,ByVal e As System.Drawing.Printing.PrintPageEventArgs)
        Dim printFontTitle As New Font("微软雅黑",18)
        Dim printFont As New Font("微软雅黑",14)
        Dim printFontBold As New Font("微软雅黑",14,FontStyle.Bold)
        Dim printFontVerySmall As New Font("微软雅黑",8)
        Dim printFontSmall As New Font("微软雅黑",9)

        Dim printPen As Pen = New Pen(Color.Black,2)


        e.Graphics.DrawString("MUSE CLUB营业部每日订座表",printFontTitle,printPen.Brush,430,20)  '标题

        e.Graphics.DrawLine(Pens.Black,100,60,1050,60) '画线    画表格


        Try
            '表头
            e.Graphics.DrawLine(Pens.Black,745) '画线

            e.Graphics.DrawString("营业人员",printFont,80)

            e.Graphics.DrawLine(Pens.Black,200,745) '画线
            e.Graphics.DrawString("星期一",80)
            e.Graphics.DrawLine(Pens.Black,270,745) '画线
            e.Graphics.DrawString("星期二",275,340,745) '画线
            e.Graphics.DrawString("星期三",345,410,745) '画线
            e.Graphics.DrawString("星期四",415,480,745) '画线
            e.Graphics.DrawString("星期五",485,550,745) '画线
            e.Graphics.DrawString("星期六",555,620,745) '画线
            e.Graphics.DrawString("星期天",625,720,745) '画线
            e.Graphics.DrawString("周总台数",810,745) '画线
            e.Graphics.DrawString("上周总台数",820,940,745) '画线
            e.Graphics.DrawString("两周对比",950,745) '画线

            e.Graphics.DrawLine(Pens.Black,130,130) '画线

            '内容
            Dim detailStartY = 150
            For i = currePage * pageSize To currePage * pageSize + pageSize - 1  '填充数据
                If i > dt.Rows.Count - 1 Then
                    Exit For
                End If

                e.Graphics.DrawString(dt.Rows(i).Item("linkMan"),printFontSmall,105,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Monday"),210,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Tuesday"),280,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Wednesday"),350,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Thursday"),420,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Friday"),490,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Saturday"),560,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Sunday"),630,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("Week"),730,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("PreWeek"),825,detailStartY)
                e.Graphics.DrawString(dt.Rows(i).Item("compare"),955,detailStartY)

                e.Graphics.DrawLine(Pens.Black,detailStartY + 27,detailStartY + 27) '画线
                detailStartY += 30
            Next

            '页尾
            e.Graphics.DrawLine(Pens.Black,745,745) '画线
            Dim saleTip = "* 以上数字单位为台"

            e.Graphics.DrawString(saleTip,printFontVerySmall,790)

            currePage += 1
            If currePage < pageCount Then
                e.HasMorePages = True '多页
            Else
                e.HasMorePages = False  '最后一页
                currePage = 0
                Return
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

    End Sub

    '打印按钮事件
    Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnPrint.Click
        pageCount = 0
        currePage = 0
        pageSize = 20
        Dim orderPrintDocument As New PrintDocument()
        orderPrintPreviewDialog.Document = orderPrintDocument
        orderPrintDocument.DefaultPageSettings.Landscape = True '    //横向打印

        AddHandler orderPrintDocument.PrintPage,AddressOf Me.orderPrintDocument_PrintPage
        'orderPrintPreviewDialog.PrintPreviewControl.Zoom = 0.7     ’显示比率
        orderPrintPreviewDialog.WindowState = FormWindowState.Normal

        pageCount = dt.Rows.Count / pageSize
        orderPrintPreviewDialog.ShowDialog()

    End Sub

猜你在找的VB相关文章