在VB.NET中使用PrintDocument打印检查

时间:2016-10-28 06:30:35

标签: vb.net printdocument

我在VB.NET 4.0中使用以下代码来打印支票。

在printpreview对话框中,打印正确显示但实际打印时, 打印从支票底部开始

我希望打印从检查的起点开始。

检查是垂直插入打印机托盘的中间位置。

Private print_document As PrintDocument
Private FIRST_TO_PRINT As String = "CHEQUE"
Private fontsize As Integer = 12
Private _ID As Integer = 0
Private CHEQUE_DATE As Date
Private CLIENT_NAME As String
Private CLIENT_NAME_ON_CHEQUE As String
Private AMOUNT As Decimal
Private AMOUNT_IN_WORDS As String

Public Sub New(ID As Integer)
    _ID = ID
End Sub

Public Function PreparePrintDocument() As PrintDocument
    ' Make the PrintDocument object.
    print_document = New PrintDocument




    print_document.DefaultPageSettings.PaperSize = New PaperSize("Custom", 336, 768)

    'print_document.OriginAtMargins = True
    'print_document.DefaultPageSettings.Margins.Left = 200
    'print_document.DefaultPageSettings.Margins.Right = 10
    'print_document.DefaultPageSettings.Margins.Bottom = 10
    'print_document.DefaultPageSettings.Margins.Top = 200
    AddHandler print_document.BeginPrint, AddressOf Print_BeginPrint
    ' Install the PrintPage event handler.
    AddHandler print_document.PrintPage, AddressOf Print_PrintPage

    ' Return the object.
    Return print_document
End Function
Protected Sub Print_BeginPrint(sender As Object, e As PrintEventArgs)

    GetVoucherDetails()
End Sub

Private Sub GetVoucherDetails()
    Dim objVOUCHER_BLL As VOUCHER_BLL
    Try
        objVOUCHER_BLL = New VOUCHER_BLL
        Dim temps As VOUCHERDataTable = objVOUCHER_BLL.GetVoucherByID(_ID)
        If temps.Count > 0 Then
            Dim temp As VOUCHERRow = temps(0)
            CHEQUE_DATE = temp.CHEQUE_DATE
            CLIENT_NAME = temp.CLIENT_NAME
            CLIENT_NAME_ON_CHEQUE = temp.CLIENT_NAME_ON_CHEQUE
            AMOUNT = temp.AMOUNT
            AMOUNT_IN_WORDS = numToWords.AmtInWord(temp.AMOUNT)
        End If
    Catch ex As Exception
    Finally
        objVOUCHER_BLL = Nothing
    End Try
End Sub

' Print the next page.
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e _
    As System.Drawing.Printing.PrintPageEventArgs)


    Dim our_brush As Brush = Brushes.Black
    Dim font As New Font("Verdana", fontsize)
    If FIRST_TO_PRINT = "CHEQUE" Then


        e.PageSettings.PaperSize = New PaperSize("Custom", 336, 768)
        e.Graphics.ResetTransform()
        e.Graphics.TranslateTransform(306, 580)
        e.Graphics.RotateTransform(90)
        e.Graphics.DrawString(CHEQUE_DATE.ToString("dd MM yyyy"), font, our_brush, New Point(0, 0))

        e.Graphics.ResetTransform()
        e.Graphics.TranslateTransform(262, 20)
        e.Graphics.RotateTransform(90)
        e.Graphics.DrawString(CLIENT_NAME_ON_CHEQUE, font, our_brush, New Point(70, 0))

        e.Graphics.ResetTransform()
        e.Graphics.TranslateTransform(232, 140)
        e.Graphics.RotateTransform(90)
        e.Graphics.DrawString(AMOUNT_IN_WORDS.Replace("Rupees ", String.Empty).ToUpper, font, our_brush, New Point(0, 0))

        e.Graphics.ResetTransform()
        e.Graphics.TranslateTransform(206, 600)
        e.Graphics.RotateTransform(90)
        e.Graphics.DrawString(AMOUNT.ToString("F2") & " /-", font, our_brush, New Point(0, 0))

        '    e.HasMorePages = True
        '    e.Graphics.ResetTransform()
        '    FIRST_TO_PRINT = "VOUCHER"
        'Else
        '    e.PageSettings.PaperSize = New PaperSize("Custom", 612, 792)

        '    e.Graphics.DrawString("VOUCHER", font, our_brush, New Point(200, 200))
        '    FIRST_TO_PRINT = "CHEQUE"
        e.Graphics.ResetTransform()
        e.HasMorePages = False
    End If

End Sub

PRINT PREVIEW OF CHEQUE

0 个答案:

没有答案