public void LocaleIndependence()
        {
            CultureInfo savedCurrentCulture   = CultureInfo.CurrentCulture;
            CultureInfo savedCurrentUiCulture = CultureInfo.CurrentUICulture;

            CultureInfo culture = CultureInfo.CreateSpecificCulture("de-DE");

            Bill bill = SampleData.CreateExample4();

            using (PDFCanvas canvas =
                       new PDFCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight))
            {
                try
                {
                    CultureInfo.CurrentCulture   = culture;
                    CultureInfo.CurrentUICulture = culture;

                    QRBill.Draw(bill, canvas);
                    FileComparison.AssertFileContentsEqual(canvas.ToByteArray(), "pdfcanvas-locale-1.pdf");
                }
                finally
                {
                    CultureInfo.CurrentCulture   = savedCurrentCulture;
                    CultureInfo.CurrentUICulture = savedCurrentUiCulture;
                }
            }
        }
Beispiel #2
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);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            // set to QR bill only, i.e. 210 by 105 mm
            OutputSize savedOutputSize = Bill.Format.OutputSize;

            Bill.Format.OutputSize = OutputSize.QrBillOnly;

            // find smaller dimension
            float scale    = MathF.Min(Size.Width / 210f, Size.Height / 105f);
            float xPadding = (Size.Width - scale * 210f) / 2f;
            float yPadding = (Size.Height - scale * 105f) / 2f;

            // draw white background
            RectangleF billBounds = new RectangleF(xPadding, yPadding, scale * 210f, scale * 105f);

            e.Graphics.FillRectangle(Brushes.White, billBounds);

            // draw QR bill
            using SystemDrawingCanvas canvas = new SystemDrawingCanvas(e.Graphics, xPadding, Size.Height - yPadding, scale, "Arial");
            try
            {
                QRBill.Draw(Bill, canvas);
            }
            catch (QRBillValidationException)
            {
                // ignore invalid bill data
            }

            Bill.Format.OutputSize = savedOutputSize;
        }
Beispiel #4
0
        private static void Main(string[] args)
        {
            Bill bill = CreateBillData();

            string destPath = "invoice-with-qr-bill.pdf";

            using (FileStream fs = new FileStream(destPath, FileMode.Create))
                using (IText7Canvas canvas = new IText7Canvas(OpenPdfInvoice("invoice-without-qr-bill.pdf"), fs, IText7Canvas.LastPage))
                {
                    QRBill.Draw(bill, canvas);
                }

            Console.WriteLine($"QR bill saved at {Path.GetFullPath(destPath)}");

            // Generate QR bill in new file
            string path = "qrbill.pdf";

            bill.Format.SeparatorType = SeparatorType.DottedLineWithScissors;
            using (IText7Canvas canvas = new IText7Canvas(path, 210, 297))
            {
                QRBill.Draw(bill, canvas);
            }

            Console.WriteLine($"QR bill saved at {Path.GetFullPath(path)}");
        }
        public Task LocaleIndependence()
        {
            CultureInfo savedCurrentCulture   = CultureInfo.CurrentCulture;
            CultureInfo savedCurrentUiCulture = CultureInfo.CurrentUICulture;

            CultureInfo culture = CultureInfo.CreateSpecificCulture("de-DE");

            Bill bill = SampleData.CreateExample4();

            using PDFCanvas canvas =
                      new PDFCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight);
            try
            {
                CultureInfo.CurrentCulture   = culture;
                CultureInfo.CurrentUICulture = culture;

                QRBill.Draw(bill, canvas);
                return(VerifyImages.VerifyPdf(canvas.ToByteArray()));
            }
            finally
            {
                CultureInfo.CurrentCulture   = savedCurrentCulture;
                CultureInfo.CurrentUICulture = savedCurrentUiCulture;
            }
        }
Beispiel #6
0
        public void ToByteArray_CorrectFrame()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize      = OutputSize.A4PortraitSheet;
            using MetafileCanvas canvas = new MetafileCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Helvetica, Arial, \"Liberation Sans\"");
            QRBill.Draw(bill, canvas);

            EmfMetaInfo metaInfo = new EmfMetaInfo(canvas.ToByteArray());

            Assert.Equal(257, metaInfo.NumRecords);

            var scale = metaInfo.Dpi / 25.4f;
            // Returns the frame in pixels
            var frame = metaInfo.GetFrame();

            Assert.Equal(0, frame.Left);
            Assert.Equal(0, frame.Top);
            int expectedWidth = (int)(QRBill.A4PortraitWidth * scale);

            Assert.InRange(frame.Right, expectedWidth - 2, expectedWidth + 2);
            int expectedHeight = (int)(QRBill.A4PortraitHeight * scale);

            Assert.InRange(frame.Bottom, expectedHeight - 2, expectedHeight + 2);
        }
 private static Task GenerateAndComparePngBill(Bill bill, SeparatorType separatorType)
 {
     bill.Format.SeparatorType = separatorType;
     using PNGCanvas canvas    =
               new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 288, "Arial,Helvetica");
     QRBill.Draw(bill, canvas);
     return(VerifyImages.VerifyPng(canvas.ToByteArray()));
 }
Beispiel #8
0
 private Metafile CreateMetafile()
 {
     // ouput size for QR bill only: 210 x 110mm
     bill.Format.OutputSize      = OutputSize.QrBillExtraSpace;
     using MetafileCanvas canvas = new MetafileCanvas(210, 110, "Arial");
     QRBill.Draw(bill, canvas);
     return(canvas.ToMetafile());
 }
Beispiel #9
0
        private void GenerateWithFailingCanvas()
        {
            Bill          bill   = SampleData.CreateExample1();
            FailingCanvas canvas = new FailingCanvas();

            bill.Format.OutputSize = OutputSize.QrBillOnly;
            QRBill.Draw(bill, canvas);
        }
Beispiel #10
0
        public void SvgSaveAs()
        {
            Bill bill = SampleData.CreateExample2();

            using SVGCanvas canvas =
                      new SVGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Helvetica, Arial, Sans");
            QRBill.Draw(bill, canvas);
            canvas.SaveAs("qrbill.svg");
        }
        public void PngSaveAs()
        {
            Bill bill = SampleData.CreateExample6();

            using PNGCanvas canvas =
                      new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Helvetica, Arial, \"Liberation Sans\"");
            QRBill.Draw(bill, canvas);
            canvas.SaveAs("qrbill.png");
        }
        public void PdfSaveAs()
        {
            Bill bill = SampleData.CreateExample4();

            using PDFCanvas canvas =
                      new PDFCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight);
            QRBill.Draw(bill, canvas);
            canvas.SaveAs("qrbill.pdf");
        }
Beispiel #13
0
        private void PrintQRBill(PrintPageEventArgs e)
        {
            // ouput size for QR bill: 210 x 297mm
            bill.Format.OutputSize = OutputSize.A4PortraitSheet;

            // print QR bill at bottom of page
            e.Graphics.PageUnit = GraphicsUnit.Millimeter;
            using SystemDrawingCanvas canvas = new SystemDrawingCanvas(e.Graphics, 0, 297, 1, "Arial");
            QRBill.Draw(bill, canvas);
        }
Beispiel #14
0
        public void SvgWriteTo()
        {
            Bill bill = SampleData.CreateExample1();

            using SVGCanvas canvas =
                      new SVGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Helvetica, Arial, Sans");
            QRBill.Draw(bill, canvas);
            MemoryStream ms = new MemoryStream();

            canvas.WriteTo(ms);
        }
        public void PdfWriteTo()
        {
            Bill bill = SampleData.CreateExample3();

            using PDFCanvas canvas =
                      new PDFCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight);
            QRBill.Draw(bill, canvas);
            MemoryStream ms = new MemoryStream();

            canvas.WriteTo(ms);
        }
        private void PngSaveAs()
        {
            Bill bill = SampleData.CreateExample6();

            using (PNGCanvas canvas =
                       new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Helvetica, Arial, Sans"))
            {
                QRBill.Draw(bill, canvas);
                canvas.SaveAs("qrbill.png");
            }
        }
Beispiel #17
0
        public void ToStream_RunsSuccessfully()
        {
            Bill bill = SampleData.CreateExample5();

            bill.Format.OutputSize      = OutputSize.A4PortraitSheet;
            using MetafileCanvas canvas = new MetafileCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Helvetica, Arial, \"Liberation Sans\"");
            QRBill.Draw(bill, canvas);
            MemoryStream ms = new MemoryStream();

            canvas.WriteTo(ms);
        }
 private void GenerateAndComparePngBill(Bill bill, SeparatorType separatorType,
                                        string expectedFileName)
 {
     bill.Format.SeparatorType = separatorType;
     using (PNGCanvas canvas =
                new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 288, "Arial,Helvetica"))
     {
         QRBill.Draw(bill, canvas);
         FileComparison.AssertGrayscaleImageContentsEqual(canvas.ToByteArray(), expectedFileName);
     }
 }
        public void PngWriteTo()
        {
            Bill bill = SampleData.CreateExample5();

            using PNGCanvas canvas =
                      new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Helvetica, Arial, \"Liberation Sans\"");
            QRBill.Draw(bill, canvas);
            MemoryStream ms = new MemoryStream();

            canvas.WriteTo(ms);
        }
Beispiel #20
0
        private Bitmap CreateBitmap()
        {
            // ouput size for QR bill only: 210 x 110mm
            bill.Format.OutputSize = OutputSize.QrBillExtraSpace;
            const int dpi = 192;

            using BitmapCanvas canvas = new BitmapCanvas((int)Math.Round(210 / 25.4 * dpi),
                                                         (int)Math.Round(110 / 25.4 * dpi), dpi, "Arial");
            QRBill.Draw(bill, canvas);
            return(canvas.ToBitmap());
        }
        private void PngWriteTo()
        {
            Bill bill = SampleData.CreateExample5();

            using (PNGCanvas canvas =
                       new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Helvetica, Arial, Sans"))
            {
                QRBill.Draw(bill, canvas);
                MemoryStream ms = new MemoryStream();
                canvas.WriteTo(ms);
            }
        }
        public Task PngBillQrBill()
        {
            Bill bill = SampleData.CreateExample1();

            byte[] png;
            using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 300, "\"Liberation Sans\",Arial, Helvetica"))
            {
                bill.Format.OutputSize = OutputSize.QrBillOnly;
                QRBill.Draw(bill, canvas);
                png = canvas.ToByteArray();
            }

            return(VerifyImages.VerifyPng(png));
        }
        private void PngBillQrBill()
        {
            Bill bill = SampleData.CreateExample1();

            byte[] svg;
            using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 300, "Arial"))
            {
                bill.Format.OutputSize = OutputSize.QrBillOnly;
                QRBill.Draw(bill, canvas);
                svg = canvas.ToByteArray();
            }

            FileComparison.AssertGrayscaleImageContentsEqual(svg, "qrbill_ex1.png");
        }
        public Task PngBillA4()
        {
            Bill bill = SampleData.CreateExample3();

            byte[] png;
            using (PNGCanvas canvas =
                       new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Arial,\"Liberation Sans\",Helvetica"))
            {
                bill.Format.OutputSize = OutputSize.A4PortraitSheet;
                QRBill.Draw(bill, canvas);
                png = canvas.ToByteArray();
            }

            return(VerifyImages.VerifyPng(png));
        }
Beispiel #25
0
        public Task QrBillA4_ComparePng()
        {
            Bill bill = SampleData.CreateExample3();

            bill.Format.OutputSize = OutputSize.A4PortraitSheet;

            byte[] png;
            using (MetafileCanvas canvas = new MetafileCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, "Arial,\"Liberation Sans\",Helvetica"))
            {
                QRBill.Draw(bill, canvas);
                png = canvas.ToByteArray();
            }

            return(VerifyImages.VerifyEmf(png));
        }
        private void PngBillA4()
        {
            Bill bill = SampleData.CreateExample3();

            byte[] png;
            using (PNGCanvas canvas =
                       new PNGCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight, 144, "Arial,Helvetica"))
            {
                bill.Format.OutputSize = OutputSize.A4PortraitSheet;
                QRBill.Draw(bill, canvas);
                png = canvas.ToByteArray();
            }

            FileComparison.AssertGrayscaleImageContentsEqual(png, "a4bill_ex3.png");
        }
Beispiel #27
0
        public Task QrBillExtraSpace_ComparePng()
        {
            Bill bill = SampleData.CreateExample5();

            bill.Format.OutputSize = OutputSize.QrBillExtraSpace;

            byte[] emf;
            using (MetafileCanvas canvas = new MetafileCanvas(QRBill.QrBillWithHoriLineWidth, QRBill.QrBillWithHoriLineHeight, "\"Liberation Sans\",Arial, Helvetica"))
            {
                QRBill.Draw(bill, canvas);
                emf = canvas.ToByteArray();
            }

            return(VerifyImages.VerifyEmf(emf));
        }
        public static byte[] generateQRcode(
            string account,
            string creditorName,
            string creditorAddressLine1,
            string creditorAddressLine2,
            string creditorCountryCode,
            decimal amount,
            string currency,
            string debtorName,
            string debtorAddressLine1,
            string debtorAddressLine2,
            string debtorCountryCode,
            string reference,
            string unstructuredMessage)
        {
            Bill bill = new Bill
            {
                Account  = account,
                Creditor = new Address
                {
                    Name         = creditorName,
                    AddressLine1 = creditorAddressLine1,
                    AddressLine2 = creditorAddressLine2,
                    CountryCode  = creditorCountryCode
                },
                Amount   = amount,
                Currency = currency,
                Debtor   = new Address
                {
                    Name         = debtorName,
                    AddressLine1 = debtorAddressLine1,
                    AddressLine2 = debtorAddressLine2,
                    CountryCode  = debtorCountryCode
                },
                Reference           = reference,
                UnstructuredMessage = unstructuredMessage
            };
            string path = "qrbill.png";

            using (PNGCanvas canvas = new PNGCanvas(QRBill.QrBillWidth, QRBill.QrBillHeight, 144, "Arial"))
            {
                QRBill.Draw(bill, canvas);
                canvas.SaveAs(path);
            }

            return(svg);
        }
        public Task AddVerticalSeparator()
        {
            var bill = SampleData.CreateExample1();

            bill.Format.SeparatorType = SeparatorType.None;
            using PDFCanvas canvas    =
                      new PDFCanvas(QRBill.A4PortraitWidth, QRBill.A4PortraitHeight);
            QRBill.Draw(bill, canvas);

            QRBill.DrawSeparators(SeparatorType.DashedLineWithScissors, false, canvas);

            MemoryStream ms = new MemoryStream();

            canvas.WriteTo(ms);

            return(VerifyImages.VerifyPdf(ms.ToArray()));
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            using (var doc = new PdfDocument())
            {
                var page = doc.AddPage();
                using (var graphic = XGraphics.FromPdfPage(page, XGraphicsUnit.Millimeter))
                {
                    graphic.DrawString("Test Invoice", new XFont("Arial", 20.0), XBrushes.Black, 20.0, 150.0);
                }
                using (var canvas = new PdfSharpCanvas(page, "Arial"))
                {
                    QRBill.Draw(Bill, canvas);
                }
                doc.Save("Output.pdf");
            }

            File.WriteAllBytes("OutputOriginal.pdf", QRBill.Generate(Bill));
        }