使用模板打印

Phi*_*ppe 6 .net c# printing

对于一个简单的收集系统,我需要以某种方式定义一个简单格式的模板文档,用数据填充它并在标准的Windows打印机上打印.它必须在Windows服务上工作.我最好用什么技术?

编辑:

我尝试过使用PDF表格.我定义了几个文本框并用iTextSharp填充它们.它一直工作到我必须打印它们,这真的很难,因为你必须直接使用读者可执行文件.

似乎更好地集成到.NET中的替代方案似乎是使用XPS.XPS是否提供类似的功能?

Nao*_*ens 5

使用 html 或纯文本创建您自己的收据模板。

使用 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>
Run Code Online (Sandbox Code Playgroud)

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();
    }
}
Run Code Online (Sandbox Code Playgroud)


Phi*_*ppe -1

我们最终使用EPSON TM-Intelligent系列的格式。