Пример #1
0
        /// <summary>
        /// Creates an image for the specified QR bill.
        /// <para>
        /// The image will only comprise the QR bill itself and have a size of 210 by 105 mm.
        /// </para>
        /// <para>
        /// If the QR bill contains invalid data, the resulting image will be empty
        /// except for the white background.
        /// </para>
        /// </summary>
        /// <param name="bill">QR bill</param>
        /// <returns></returns>
        public static DrawingImage CreateImage(Bill bill)
        {
            var bounds = new Rect(0, 0, 210 * mmToDip, 105 * mmToDip);

            DrawingGroup group = new DrawingGroup();

            using (DrawingContext dc = group.Open())
            {
                // draw white background
                dc.DrawRectangle(Brushes.White, null, bounds);

                using var canvas = new QrBillImage(dc, 105);
                var savedOutputSize = bill.Format.OutputSize;
                bill.Format.OutputSize = OutputSize.QrBillOnly;
                try
                {
                    QRBill.Draw(bill, canvas);
                }
                catch (QRBillValidationException)
                {
                    // ignore
                }
                bill.Format.OutputSize = savedOutputSize;
            }

            var image = new DrawingImage(group);

            image.Freeze();
            return(image);
        }
Пример #2
0
        /// <summary>
        /// Print sample document with the specified QR bill
        /// </summary>
        /// <param name="bill">QR bill to print</param>
        internal static void Print(Bill bill)
        {
            // show print dialog
            var pd = new PrintDialog();

            pd.PrintTicket.PageMediaSize   = new PageMediaSize(PageMediaSizeName.ISOA4);
            pd.PrintTicket.PageOrientation = PageOrientation.Portrait;
            if (pd.ShowDialog() != true)
            {
                return;
            }

            // create page
            var pageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);
            var page     = new FixedPage
            {
                Width  = pageSize.Width,
                Height = pageSize.Height
            };

            // add title
            var text = new TextBlock
            {
                Text       = "Swiss QR Bill",
                FontSize   = 40,
                FontWeight = FontWeights.Bold,
                Margin     = new Thickness(20 / 25.4 * 96)
            };

            page.Children.Add(text);

            // add QR bill to the bottom
            var qrBill = new Image
            {
                Source = QrBillImage.CreateImage(bill)
            };

            FixedPage.SetBottom(qrBill, 0);
            page.Children.Add(qrBill);

            // create document
            var document = new FixedDocument();

            document.DocumentPaginator.PageSize = pageSize;
            PageContent pageContent = new PageContent();

            ((IAddChild)pageContent).AddChild(page);
            document.Pages.Add(pageContent);

            // print document
            pd.PrintDocument(document.DocumentPaginator, "Invoice");
        }
Пример #3
0
        public MainWindow()
        {
            InitializeComponent();

            // create bill data
            bill = new Bill
            {
                // creditor data
                Account  = "CH4431999123000889012",
                Creditor = new Address
                {
                    Name         = "Robert Schneider AG",
                    AddressLine1 = "Rue du Lac 1268/2/22",
                    AddressLine2 = "2501 Biel",
                    CountryCode  = "CH"
                },

                // payment data
                //Amount = 199.95m,
                Currency = "CHF",

                // debtor data
                Debtor = new Address
                {
                    Name         = "Pia-Maria Rutschmann-Schnyder",
                    AddressLine1 = "Grosse Marktgasse 28",
                    AddressLine2 = "9400 Rorschach",
                    CountryCode  = "CH"
                },

                // more payment data
                Reference           = "210000000003139471430009017",
                UnstructuredMessage = "Abonnement für 2020"
            };

            billImage.Source = QrBillImage.CreateImage(bill);
        }