Пример #1
0
        /// <summary>
        /// 打印账单
        /// </summary>
        /// <param name="str"></param>
        public static void PrintBill(string doc)
        {
            string printer = Tools.IniRead(App.CurrentDir + "main.ini", "Options", "printer_of_jzd", "");

            if (string.IsNullOrEmpty(printer))
            {
                return;
            }
            PrintDialog dialog = new PrintDialog();

            dialog.SetPrinter(printer);
            Run       run    = new Run(doc);
            TextBlock visual = new TextBlock();

            visual.FontSize   = 14;
            visual.FontFamily = new FontFamily("微软雅黑");
            visual.Inlines.Add(run);
            visual.Margin          = new Thickness(20, 1, 1, 1);
            visual.TextWrapping    = TextWrapping.Wrap;
            visual.LayoutTransform = new ScaleTransform(1, 1);
            Size pageSize = new System.Windows.Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);

            visual.Measure(pageSize);
            visual.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));
            dialog.PrintVisual(visual, "结账单");
        }