public static void AddFormOfServer(string pPrinterName, string pFormName, double width, double height, PrintSystemUnit unit) { var w = (int)PrintSystemUnitConvert.Convert(width, unit, PrintSystemUnit.ThousandthsOfMillimeter); var h = (int)PrintSystemUnitConvert.Convert(height, unit, PrintSystemUnit.ThousandthsOfMillimeter); AddFormOfServer(pPrinterName, pFormName, w, h); }
/* 逻辑参考: * System.Drawing.Printing.PrinterSettings.PaperSizeFromMode(); */ public static PaperSize GetPaperSize(DevMode mode) { if ((mode.dmFields & DevModeFields.PaperSize) == DevModeFields.PaperSize) { // TODO: 输入打印设备名称 var sizes = PrintSpooler.GetPrinterPapers(""); for (var i = 0; i < sizes.Length; i++) { var s = sizes[i]; if (s.RawKind == mode.dmPaperSize) { return(s); } } } return(new PaperSize("custom", (int)PrintSystemUnitConvert.Convert(mode.dmPaperWidth, PrintSystemUnit.TenthsOfMillimeter, PrintSystemUnit.HundredthsOfInch), (int)PrintSystemUnitConvert.Convert(mode.dmPaperWidth, PrintSystemUnit.TenthsOfMillimeter, PrintSystemUnit.HundredthsOfInch) )); }
static void AddOrUpdateForm(IntPtr hPrinter, string pFormName, double width, double height, PrintSystemUnit unit) { var level = 1; var o = Native.ThunkGetForm(hPrinter, pFormName, level); if (o != null) { var form = (FormInfo1)o; if (form.Flags == FormInfoFlags.Builtin) { throw new ArgumentException("内建规格不可修改"); } var w = (int)PrintSystemUnitConvert.Convert(width, unit, PrintSystemUnit.ThousandthsOfMillimeter); var h = (int)PrintSystemUnitConvert.Convert(height, unit, PrintSystemUnit.ThousandthsOfMillimeter); form.Size = new SIZE(w, h); form.ImageableArea = new RECT(0, 0, w, h); // Update Native.ThunkSetForm(hPrinter, pFormName, form); } else { var w = (int)PrintSystemUnitConvert.Convert(width, unit, PrintSystemUnit.ThousandthsOfMillimeter); var h = (int)PrintSystemUnitConvert.Convert(height, unit, PrintSystemUnit.ThousandthsOfMillimeter); var form = new FormInfo1() { Flags = FormInfoFlags.User, pName = pFormName, Size = new SIZE(w, h), ImageableArea = new RECT(0, 0, w, h), }; // Add Native.ThunkAddForm(hPrinter, form); } }
public double GetHeight(PrintSystemUnit unit) { return(PrintSystemUnitConvert.Convert(this._Height, _Unit, unit)); }
public double GetWidth(PrintSystemUnit unit) { return(PrintSystemUnitConvert.Convert(this._Width, _Unit, unit)); }