I tried printing from HTML and CSS on a printer with the program language vb.net.
Please Guide Me
one more I want to add QR in footer section
This My code :
Public Class Form1
Private Function ToHtml() As String
Dim Pathimageheader As String = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "logo.png")
Dim Pathimagefooter As String = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Qr.png")
Dim html =
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<title>Receipt example</title>
<link rel="stylesheet" href="style.css"/>
</head>
<style>
{
font-size: 12px;
font-family: 'Times New Roman';
}
td,
th,
tr,
table {
border-top: 1px solid black;
border-collapse: collapse;
}
td.description,
th.description {
width: 75px;
max-width: 75px;
}
td.quantity,
th.quantity {
width: 40px;
max-width: 40px;
word-break: break-all;
}
td.price,
th.price {
width: 40px;
max-width: 40px;
word-break: break-all;
}
.centered {
text-align: center;
align-content: center;
}
.ticket {
width: 155px;
max-width: 155px;
}
img {
max-width: inherit;
width: inherit;
}
</style>
<body>
<div class="ticket">
<img src=<%= Pathimageheader %> alt="logo"></img>
<p class="centered">RECEIPT EXAMPLE
<br>Address line 1
</br><br>Address line2</br></p>
<table>
<thead>
<tr>
<th class="quantity">Q.</th>
<th class="description">Description</th>
<th class="price">$$</th>
</tr>
</thead>
<tbody>
<tr>
<td class="quantity">1.00</td>
<td class="description">ARDUINO UNO R3</td>
<td class="price">$25.00</td>
</tr>
<tr>
<td class="quantity">2.00</td>
<td class="description">JAVASCRIPT BOOK</td>
<td class="price">$10.00</td>
</tr>
<tr>
<td class="quantity">1.00</td>
<td class="description">STICKER PACK</td>
<td class="price">$10.00</td>
</tr>
<tr>
<td class="quantity"></td>
<td class="description">TOTAL</td>
<td class="price">$55.00</td>
</tr>
</tbody>
</table>
<p class="centered">Thanks for your purchase!
<br>parzibyte.me/blog</br></p>
<img src=<%= Pathimagefooter %> alt="logo"></img>
</div>
</body>
</html>
Return html.ToString()
End Function
Private Sub BtnPrint_Click(sender As Object, e As EventArgs) Handles BtnPrint.Click
myWebBrowser.DocumentText = ToHtml()
End Sub
Private Sub myWebBrowser_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles myWebBrowser.DocumentCompleted
myWebBrowser.Parent = Me
myWebBrowser.Visible = False
myWebBrowser.ShowPrintPreviewDialog()
End Sub
Desired result (without botton)
sorry I can't post the original html and css code because of an error at the time of posting but below is the link of the html and css code
result after update code
RESULT AFTER UPDATE CODE LATEST
print screen dialog







The WebBrowser control is quite old and may not support some of the newer styling. You may consider using the WebView2 control instead. Also, it appears that you've included style information twice - once as a link to a Style Sheet, and a second time in the HTML.
The following shows how to use JavaScript, CSS, and HTML to create a receipt in VB.NET. It's an implementation of the code referenced in the OP - Print receipt in thermal printer using JavaScript, CSS & HTML. The code below uses NuGet package WebView2 to display the receipt. See the comments throughout the code for more information.
VS 2022:
Create a new Windows Forms App (.NET Framework) project
Open Solution Explorer
Download/install NuGet package: Microsoft.Web.WebView2
Create Templates folder
Open Properties Window
Add logo image to Templates folder: (name: logo.png)
Add QR code image to Templates folder: (name: qrCode.jpg)
Note: If you'd like to generate a QR code programmatically, see this post.
Add Style Sheet to Templates folder: (name: style.css)
style.css:
Add JavaScript file to Templates folder: (name: printReceipt.js)
printReceipt.js:
Add receipt.html to Templates folder:
Note: In the HTML, I've removed the table data, and replaced it with a placeholder ("rowsPlaceHolder"). In VB.NET, we'll generate the HTML that goes here, and replace "rowsPlaceHolder" with the HTML. The paths for the style sheet and JavaScript file are relative to this HTML file, so either change the paths as necessary, or ensure that the HTML file is in the same folder as the style sheet (.css) and JavaScript file (.js).
receipt.html:
In Solution Explorer, you should see the following:
Add a Form to the project (name: FrmReceipt.vb)
Note: This form will host the WebView2 browser control which will display the receipt.
Open the Toolbox
Add WebView2 to FrmReceipt (name: webView21)
FrmReceipt.vb:
Note: In the code below, you'll notice that the async keyword has been added to the Load event handler.
One can use the following to generate the receipt:
Note: The code below will go in the main form (ex: Form1.vb). If desired one can rename Form1.vb to something such as FrmMain.vb.
Usage:
Update:
If one needs to adjust the size of an image, one can use MS Paint to resize the image prior to adding it to the Templates folder or one can use the width and height properties of the img tag in the HTML to specify the desired size. When setting these properties in the HTML, the width and height should be less than or equal to the width and height of the image.