public RawPrintSetting DefaultSetting() { if (PrinterSettings.InstalledPrinters.Count < 0) { return(null); } PrinterSettings ps = new PrinterSettings(); ps.PrinterName = new PrintDocument().PrinterSettings.PrinterName; ps.DefaultPageSettings.PaperSize = ps.PaperSizes[0]; ps.DefaultPageSettings.Margins = new Margins { Top = (int)Mm2Inch(Convert.ToDouble(25)), Bottom = (int)Mm2Inch(Convert.ToDouble(25)), Left = (int)Mm2Inch(Convert.ToDouble(15)), Right = (int)Mm2Inch(Convert.ToDouble(15)) }; ps.DefaultPageSettings.Landscape = false; RawPrintSetting rps = new RawPrintSetting(); rps.LandScape = false; rps.PageMargins = ps.DefaultPageSettings.Margins; rps.PaperName = ps.DefaultPageSettings.PaperSize.PaperName; rps.PaperSize = ps.DefaultPageSettings.PaperSize; rps.PrinterName = ps.PrinterName; return(rps); }
/// <summary> /// 读取打印设置 /// </summary> /// <returns></returns> public RawPrintSetting GetRawPrintSettings() { if (string.IsNullOrEmpty(templateName)) { return(null); } var rps = new RawPrintSetting() { LandScape = false }; try { if (File.Exists(FilePath)) { using (var stream = new StreamReader(FilePath, Encoding.UTF8)) { var json = stream.ReadToEnd(); rps = JsonConvert.DeserializeObject <RawPrintSetting>(json); } } else { rps = DefaultSetting(); } } catch (Exception exp) { XMessageBox.Warning(string.Format("加载打印设置出错,您需要重新设置并保存")); } return(rps); }
public string SaveSetting(RawPrintSetting rps) { try { using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { using (var st = new StreamWriter(stream, Encoding.UTF8)) { st.Write(JsonConvert.SerializeObject(rps, new JsonSerializerSettings { PreserveReferencesHandling = PreserveReferencesHandling.Objects, Formatting = Formatting.Indented })); } } return("保存成功"); } catch (Exception ex) { return(ex.Message); } }