Printing using a template

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 should run on a Windows service. Which technology is best used?

EDIT:

I tried using PDF forms. I defined a couple of text fields and populated them with iTextSharp. It worked until I had to print them, which is very difficult, since you must use the program directly for reading.

An alternative that seems to be better integrated into .NET seems to be to use XPS. Does XPS have similar functionality?

+6
source share
6 answers

We use the EPSON TM-Intelligent series format.

-1
source

Create your own receipt template using html or plain text.

An example of 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> 

WITH#

  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(); } } 
+3
source

Use Mustache to create HTML templates and populate them.

. Network interfaces are very easy to use.

Once you have HTML, you can use the WebBrowser control - off-screen - to print. A.

+2
source

There are various ways:

Create a text file and search and replace the keywords with the appropriate values. Save / Print.

Create an html file and find and replace the keywords with the appropriate values. Save / Print.

Create a PDF file with embedded fields and replace them with the appropriate values. Save / Print.

And further...

+1
source

Just for the idea, if you haven’t seen this, you can print the HTML DIV

How to print part of the displayed HTML page in JavaScript?

+1
source

You can try ActiveReports

Link to ComponentOne

It is not free .. but it works for printing as you wish. Just create Templates and paste them into your code.

+1
source

Source: https://habr.com/ru/post/949991/


All Articles