Example #1
0
        private void PrintReceipt(string receiptStr)
        {
            string[] receiptLines = receiptStr.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth   = Unit.FromInch(3.0);
            doc.DefaultPageSetup.PageHeight  = Unit.FromInch(0.181 * receiptLines.Length + 0.56);     //enough to print receipt text plus 9/16 inch (0.56) extra space at bottom.
            doc.DefaultPageSetup.TopMargin   = Unit.FromInch(0.25);
            doc.DefaultPageSetup.LeftMargin  = Unit.FromInch(0.25);
            doc.DefaultPageSetup.RightMargin = Unit.FromInch(0.25);
            MigraDoc.DocumentObjectModel.Font bodyFontx = MigraDocHelper.CreateFont(8, false);
            bodyFontx.Name = FontFamily.GenericMonospace.Name;
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Left;
            parformat.Font      = bodyFontx;
            par.Format          = parformat;
            par.AddFormattedText(receiptStr, bodyFontx);
            MigraDoc.Rendering.Printing.MigraDocPrintDocument printdoc = new MigraDoc.Rendering.Printing.MigraDocPrintDocument();
            MigraDoc.Rendering.DocumentRenderer renderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            renderer.PrepareDocument();
            printdoc.Renderer = renderer;
#if DEBUG
            FormRpPrintPreview pView = new FormRpPrintPreview(printdoc);
            pView.ShowDialog();
#else
            try {
                ODprintout printout = PrinterL.CreateODprintout(
                    printSit: PrintSituation.Receipt,
                    auditPatNum: _patCur.PatNum,
                    auditDescription: Lans.g(this, "PayConnect receipt printed")
                    );
                if (PrinterL.TrySetPrinter(printout))
                {
                    printdoc.PrinterSettings = printout.PrintDoc.PrinterSettings;
                    printdoc.Print();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(Lan.g(this, "Printer not available.") + "\r\n" + Lan.g(this, "Original error") + ": " + ex.Message);
            }
#endif
        }