My requirement is that I need to print invoice, it may contain 10 line or may contain 20 line. Every thing should be in the one invoice.
For e.g. if you go to any supermarket, if you buy 3 items, you may get small sized bill. If you buy 30 items, you might get big sized bill. I want to implement the same in my vb.NET application.
Exactly I need that how to increase printer page length through program according to the nature of bill.
I am using dot matrix printer and graphic mode printing.
What I have tried:
As of now, I have created text file and print it through Command-line print using below command
Type Printfile.txt > prn
But, the problem is I am not able to format my text file with different font, weight, or size since I am writing it as textfile (notepad).
I am using streamwriter to write the files from VB.NET and as of now I am trying to format it in text files.
I want to format some words to be bold or italic and font size variation but I am not able to do so since I am formatting with text files.
Below are the format:
Store Name
Store Address
----------------------------------------
Gift Receipt
Transaction #: 105
Date: 11/10/2009 Time: 6:10:10
Cashier: 2 Register: 5
----------------------------------------
Item Description Quantity
----------------------------------------
567577 xyz 2
687687 abc 4
– – – – –
----------------------------------------
Net Amount : 6
Thank You for shopping
XYZ StoreName
We hope you’ll come back soon!
You can use a WebBrowser control to print an html formatted invoice instead. You will still need to figure out how to populate the invoice from the text file, according to your needs. This can be automated. For example, make a loop to add each table row. You can even use css.
Add a WebBrowser control to your form, and run this code
Dim html =
"<html>" &
"<head>" &
"<style>" &
"table, th" &
"{" &
"border: 1px solid black;" &
"table-layout: fixed;" &
"width: 100px;" &
"border-collapse: collapse;" &
"}" &
".title" &
"{" &
"color: blue;" &
"}" &
"</style>" &
"</head>" &
"<body>" &
"<p><b><div class=""title"">Store Name</div></b></p>" &
"<p>Store Address</p>" &
"<p><hr/></p>" &
"<p><b>Gift Receipt</b></p>" &
"<p>Transaction #: 105</p>" &
"<p>Date: 11/10/2009 Time: 6:10:10</p>" &
"<p>Cashier: 2 Register: 5</p>" &
"<p><hr/></p>" &
"<table>" &
"<tr>" &
"<th>Item</th>" &
"<th>Description</th>" &
"<th>Quantity</th>" &
"</tr>" &
"<tr>" &
"<th>567577</th>" &
"<th>xyz</th>" &
"<th>2</th>" &
"</tr>" &
"<tr>" &
"<th>687687</th>" &
"<th>abc</th>" &
"<th>4</th>" &
"</tr>" &
"<tr>" &
"<th>- -</th>" &
"<th>- -</th>" &
"<th>-</th>" &
"</tr>" &
"<tr>" &
"<th colspan=""2"">Net Amount</th>" &
"<th>6</th>" &
"</tr>" &
"</table>" &
"<p><hr/></p>" &
"<p>Thank You for shopping</p>" &
"<p>XYZ StoreName</p>" &
"<p>We hope you’ll come back soon!</p>" &
"</body>" &
"</html>"
Me.WebBrowser1.DocumentText = html
You will need a handler for document complete (or a separate print button, but the point is ShowPrintDialog()
can't be called before the document is complete).
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Me.WebBrowser1.ShowPrintDialog()
End Sub
The above code produces this rudimentary, albeit formatted, receipt.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With