Esempio n. 1
0
        public static void QuitePrint(string layoutPath, string printername, string dataPath)
        {
            string tempdir = Helper.UnitHelper.GetTemplateFolderName();

            Helper.UnitHelper.UnArchiveFiles(layoutPath, tempdir);
            var doc = new System.Xml.XmlDocument();

            doc.Load(System.IO.Path.Combine(tempdir, "layout.xml"));
            var canvas = new wCanvas(doc);
            var pt     = new Helper.PrintHelper(printername, Helper.PrintHelper.DisplayToMm(canvas.Width), Helper.PrintHelper.DisplayToMm(canvas.Height));

            pt.Canvas = canvas;
            pt.Data   = Helper.ExcelHelper.ExcelToTemplateData(dataPath, "Sheet1");

            var CFG = Helper.CommandHelper.Configs;

            if (CFG.ContainsKey("print-offset"))
            {
                var printoffset = CFG["print-offset"].Split("x".ToCharArray());
                pt.OffsetMm = new PointF(float.Parse(printoffset[0]), float.Parse(printoffset[1]));
            }
//			pt.OffsetMm=new PointF(-27,-3);
//			pt.PrinterSettings.PrintToFile=true;
//			pt.PrinterSettings.PrintFileName=@"C:\Users\0115289\Desktop\N7RNAN1LOG00003_0115289.pdf";

            pt.Print();
            pt.Dispose();
            doc = null;
            System.IO.Directory.Delete(tempdir, true);
        }
Esempio n. 2
0
        /// <summary>
        /// 使用JSON数据文件打印
        /// </summary>
        /// <param name="layoutPath"></param>
        /// <param name="printername"></param>
        /// <param name="jsonFile"></param>
        public static void QuitePrintJson(string layoutPath, string printername, string jsonFile)
        {
            string tempdir = Helper.UnitHelper.GetTemplateFolderName();

            Helper.UnitHelper.UnArchiveFiles(layoutPath, tempdir);
            var doc = new System.Xml.XmlDocument();

            doc.Load(System.IO.Path.Combine(tempdir, "layout.xml"));
            var canvas = new wCanvas(doc);
            var pt     = new Helper.PrintHelper(printername, Helper.PrintHelper.DisplayToMm((int)(canvas.SizeF.Width * 100)) / 100.0F, Helper.PrintHelper.DisplayToMm((int)(canvas.SizeF.Height * 100)) / 100.0F);

            pt.Canvas = canvas;

            //以下代码用于支持Demon生成Json
            var bs         = System.IO.File.ReadAllBytes(jsonFile);
            var jsonString = System.Text.Encoding.GetEncoding("gb2312").GetString(bs);

            pt.JsonData = Newtonsoft.Json.Linq.JObject.Parse(jsonString)["data"] as Newtonsoft.Json.Linq.JArray;

            ////默认方式
            //var jo = Newtonsoft.Json.Linq.JObject.Parse(System.IO.File.ReadAllText(jsonFile));
            //pt.JsonData = jo["data"] as Newtonsoft.Json.Linq.JArray;

            var CFG = Helper.CommandHelper.Configs;

            if (CFG.ContainsKey("print-offset"))
            {
                var printoffset = CFG["print-offset"].Split("x".ToCharArray());
                pt.OffsetMm = new PointF(float.Parse(printoffset[0]), float.Parse(printoffset[1]));
            }

            if (CFG.ContainsKey("pdf"))
            {
                pt.PrintToPDF    = bool.Parse(CFG["pdf"]);
                pt.PrintFileName = CFG["outfile"];
                pt.PrinterSettings.PrintToFile = true;
                pt.PrintPDF();
            }
            else
            {
                pt.Print();
            }
            //			pt.OffsetMm=new PointF(-27,-3);
            //			pt.PrinterSettings.PrintToFile=true;
            //			pt.PrinterSettings.PrintFileName=@"C:\Users\0115289\Desktop\N7RNAN1LOG00003_0115289.pdf";

            pt.Dispose();
            doc = null;
            System.IO.Directory.Delete(tempdir, true);
        }