Printing using Template
Solution 1
We endet up using the format of the EPSON TM-Intelligent series.
Solution 2
Create your own receipt template using html or plain text.
Example using html:
HTML
<html>
<head>
<title>Receipt</title>
</head>
<body>
<div>The price: <%Price%></div>
<div>The time: <%Time%></div>
<div>Payment Method: <%PaymentMethod%></div>
</body>
</html>
C#
static void Main(string[] args)
{
CreateReceipt("€1.50", "09.30", "Cash");
}
private static void CreateReceipt(string price, string time, string paymentMethod)
{
string bodyFile;
string template = System.IO.Directory.GetCurrentDirectory() + "\\template.html";
using (StreamReader reader = new StreamReader(template))
{
bodyFile = reader.ReadToEnd();
bodyFile = bodyFile.Replace("<%Price%>", price);
bodyFile = bodyFile.Replace("<%Time%>", time);
bodyFile = bodyFile.Replace("<%PaymentMethod%>", paymentMethod);
}
FileStream fs = File.OpenWrite(System.IO.Directory.GetCurrentDirectory() + "\\receipt.html");
StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
writer.Write(bodyFile);
writer.Close();
}
}
Solution 3
Use Mustache to create HTML templates and populate them.
The .Net interfaces are very easy to use.
Once you've got the HTML, you can use a WebBrowser control - offscreen - to print.
Solution 4
There are various ways;
Create a text file and search and replace keywords with appropriate values. Save/Print this.
Create a html file and search and replace keywords with appropriate values. Save/Print this.
Create a PDF file with built-in fields and replace these with appropriate values. Save/Print this.
And more...
Solution 5
Just for an Idea if you haven't seen this, You can print HTML DIV
Philippe
Updated on June 15, 2022Comments
-
Philippe almost 2 years
For a simple reciept system I need to somehow define a template document with simple formatting, fill it with data and print it on a standard windows printer. It has to work on a windows service. What technology should I best use?
EDIT:
I tried using PDF-Forms. I defined a couple of text boxes and filled them in with iTextSharp. It worked until the point where I had to print them, which is really hard, as you have to essentially use the reader executable directly.
An alternative which seems to be better integrated into .NET seems to be to use XPS. Does XPS provide a similar functionality?
-
Philippe almost 11 yearsWell I don't really want to write that stuff myself. Also how would I print this afterwards? Is there a way to use something like Razor and then print it out?
-
Naomi Owens almost 11 yearsSee edit. The method will now use the template.html to create a new file called receipt.html with whatever parameters are passed to it. I'm not familiar with Razor.