none
Direct print on printer RRS feed

  • Question

  • I want to send direct print on the printer without view, I have applied this if more new information else of these printing option tell me with example.

    Error on this first line (Dim P As New PrinterClass(Application.StartupPath)
    Error Printer class not define ?


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim P As New PrinterClass(Application.StartupPath)
    With P
    'Printing Title
    .FeedPaper(4)
    .AlignCenter()
    .BigFont()
    .Bold = True
    .WriteLine("Invoice")

    'Printing Date
    .GotoSixth(1)
    .NormalFont()
    .WriteChars("Date:")
    .WriteLine(DateTime.Now.ToString)
    .DrawLine()
    .FeedPaper(2)

    'Printing Header
    .GotoSixth(1)
    .WriteChars("#")
    .GotoSixth(2)
    .WriteChars("Description")
    .GotoSixth(5)
    .WriteChars("Count")
    .GotoSixth(6)
    .WriteChars("Total")
    .WriteLine("")
    .DrawLine()

    'Printing Items
    .SmallFont()
    Dim i As Integer
    For i = 1 To 6
    .GotoSixth(1)
    .WriteChars(i)
    .GotoSixth(2)
    .WriteChars("Item# " & (Rnd() * 100) \ 1)
    .GotoSixth(5)
    .WriteChars(Rnd() * 10 \ 1)
    .GotoSixth(6)
    .WriteChars((Rnd() * 50 \ 1) & " JD(s)")
    .WriteLine("")
    Next

    'Printing Totals
    .NormalFont()
    .DrawLine()
    .GotoSixth(1)
    .UnderlineOn()
    .WriteChars("Total")
    .UnderlineOff()
    .GotoSixth(5)
    .WriteChars((Rnd() * 300 \ 1) & " JD(s)")
    .CutPaper()
    .EndDoc()
    End With
    End
    End Sub

    Friday, January 3, 2020 9:57 AM

Answers

All replies

  • What language are you using?

    This forum is for visual basic.net.

    This shows how to use the printer document to print in vb.net:

    https://docs.microsoft.com/en-us/dotnet/api/system.drawing.printing.printdocument?view=netframework-4.8

    • Marked as answer by CompuTechSide Tuesday, January 7, 2020 2:53 PM
    Friday, January 3, 2020 10:56 AM
  • I using vb.net

    Without viewing print 

    Friday, January 3, 2020 11:36 AM
  • I using vb.net

    Without viewing print 

    It does not look like vb.net to me. I don't see how the code you show would work for anything but maybe I don't understand it?

    Try using the example in the link I gave. If you don't want to view first then don't use the print preview features. The example in the link appears not use print preview.

    Are you trying to print raw print data to a POS terminal printer? Where did you get the code you show?

    Friday, January 3, 2020 11:46 AM
  • Yes you saying right print data to a POS terminal printer 

    before this i was using  crystal report. Print is going on printer but i want without view I have applied this 

    CrystalReportViewer1.SelectionFormula = "{Invoice_Table.Invoice_no} = '" &  TxtParticular.Text & "'"

    but have used this line for without viewing see this

    DirectPrint.PrintToPrinter(1, False, 0, 0) ' But all Invoices_no printing on this line i want use where clause for particular record print just.

    you can see in crystal report selection formula


    Friday, January 3, 2020 12:03 PM
  • If you search I think I have seen forum examples of printing like you want without crystal reports (cr) direct from vb.net but I don't have the equipment. So I am not going to try.

    I don't think cr is supported by Microsoft anymore you need to go their forum if no one from this forum can help.

    Friday, January 3, 2020 12:12 PM
  • Hi CompuTechSide, 

    Thank you for posting here.

    According to your description, you need to define ‘PrinterClass’ class in your project.

    I find your code may related to the following reference:

    POS Printing: The Easy Way

    You can download the project in the reference and install ‘Microsoft.VisualBasic.PowerPacks.Vs’ dll.

    Then you can find ‘PrinterClass’ class in the project with no errors.

    Besides, you can also choose to use the PrintDocument object to print.

    Hope it can help you.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 6, 2020 7:59 AM
    Moderator