Rails - 将HTML打印到打印机

时间:2018-04-28 17:15:39

标签: ruby-on-rails ruby

如何在Rails中将HTML格式的文本打印到选定的打印机?是否有宝石或红宝石代码允许这个?

例如:

1-我在linux上安装了3台打印机:' printer_a',' printer_b'和' printer_c'。

2-我有一个布局<?xml version="1.0" encoding="utf-8"?> <log> <logData id="Alpha"> <data><index>100</index><value>150</value></data> <data><index>110</index><value>750</value></data> <data><index>120</index><value>750</value></data> <data><index>130</index><value>150</value></data> <data><index>140</index><value>0</value></data> <data><index>150</index><value>222</value></data> </logData> <logData id="Bravo"> <data> <index>100</index> <value>25</value> </data> <data> <index>110</index> <value>11</value> </data> <data> <index>120</index> <value>1</value> </data> <data> <index>130</index> <value>25</value></data> <data> <index>140</index> <value>0</value> </data> <data> <index>150</index> <value>1</value> </data> </logData> </log>

3-我希望Rails不是将static void Main(string[] args) { List<LogData> logDatas = GetLogDatasFromFile("singleVersusMultLine.xml"); Debug.WriteLine("Main"); Debug.WriteLine("logData"); foreach (LogData logData in logDatas) { Debug.WriteLine($" logData.ID {logData.ID}"); foreach(LogPoint logPoint in logData.LogPoints) { Debug.WriteLine($" logData.Index {logPoint.Index} logData.Value {logPoint.Value}"); } } Debug.WriteLine("end"); } public static List<LogData> GetLogDatasFromFile(string xmlFile) { List<LogData> logDatas = new List<LogData>(); using (XmlReader reader = XmlReader.Create(xmlFile)) { // move to next "logData" while (reader.ReadToFollowing("logData")) { var logData = new LogData(reader.GetAttribute("id")); using (var logDataReader = reader.ReadSubtree()) { // inside "logData" subtree, move to next "data" while (logDataReader.ReadToFollowing("data")) { // move to index logDataReader.ReadToFollowing("index"); // read index var index = int.Parse(logDataReader.ReadElementContentAsString()); // move to value logDataReader.ReadToFollowing("value"); // read value var value = double.Parse(logDataReader.ReadElementContentAsString(), CultureInfo.InvariantCulture); logData.LogPoints.Add(new LogPoint(index, value)); } } logDatas.Add(logData); } } return logDatas; } public class LogData { public string ID { get; } public List<LogPoint> LogPoints { get; } = new List<LogPoint>(); public LogData (string id) { ID = id; } } public class LogPoint { public int Index { get; } public double Value { get; } public LogPoint ( int index, double value) { Index = index; Value = value; } } 呈现给客户端的浏览器,而是通过toprint.html.erb发送要打印的HTML页面。

问题在于我无法找到Rails为我这样做的方式

0 个答案:

没有答案