Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have some code for printing vouchers, working fine. Problem is it's taking 2/3 seconds to start print, but my customer wants fast print. am showing code, please help

here is my code

Private Sub Btn_Print_Test_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Print_Test.Click
        Me.Btn_Print_Test.Enabled = False
        Dim document As New PrintDocument
        AddHandler document.PrintPage, New PrintPageEventHandler(AddressOf Me.TestPrint_PrintPage)
        document.PrintController = New StandardPrintController
        document.Print()
        Me.Btn_Print_Test.Enabled = True
    End Sub

    Private Sub TestPrint_PrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
        e.Graphics.DrawString("* 012345678987654*", New Font("Free 3 of 9 Extended", 17.0!, FontStyle.Regular), Brushes.Black, CSng(2.0!), CSng(0.0!))
        e.Graphics.DrawString("* 012345678987654*", New Font("Free 3 of 9 Extended", 17.0!, FontStyle.Regular), Brushes.Black, CSng(2.0!), CSng(17.5!))
        e.Graphics.DrawString(Strings.Space(10) & "* 012345678987654 *", New Font("Courier", 8.0!, FontStyle.Regular), Brushes.Black, CSng(2.0!), CSng(38))
    End Sub


What I have tried:

I have searched so many tutorials related printing, but nothing helped me
Posted
Updated 29-Apr-18 7:51am

1 solution

The problem is you're dealing with the Windows Print Spooler. The drawing stuff you do gets queued up, not directly printed. The printer driver has to convert your drawing commands into the language the printer understands to describe the page image, then that data has to be sent to the printer. Normally, you're actually sending LOTS of data that describe the page image to the printer.

There is no way to speed this up.

You're only option is to send your text and images to the printer directly, bypassing the spooler, in the language the printer understands. The problem with this is you have to learn the language of the printer and write a ton of code to describe and layout the text and images yourself, converting everything to the language the printer understands. You're code will also only support printers that understand the same language, limiting your printer options.
 
Share this answer
 
Comments
Maciej Los 29-Apr-18 15:36pm    
5ed!
RKS4477 2-May-18 11:13am    
can you share a tutorial regarding direct print bypassing windows spooler ?
Dave Kreskowiak 2-May-18 12:24pm    
Not really a tutorial, but the code pretty much explains what's going:

https://www.c-sharpcorner.com/article/printing-directly-to-the-printer/
RKS4477 4-May-18 13:57pm    
I got this and it helped me to print direct. Direct raw printing is so fast as I was looking for, but here is some problem I am facing, how to change font or font size for printing ? how to print barcode ? seems it looking simple string printing
Dave Kreskowiak 4-May-18 15:12pm    
That's where the "write a ton of code" comes in. You have to figure out how to draw your images and convert them to the data the printer needs. There are probably graphic commands in the printers command reference. You'll need to draw your images to a Bitmap and then convert the bitmap data to the structures the printer requires. That include barcodes as those are just images!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900