Example #1
0
 private Task GenerateAndCompareBill(Bill bill)
 {
     bill.Format.OutputSize     = OutputSize.A4PortraitSheet;
     bill.Format.GraphicsFormat = GraphicsFormat.SVG;
     byte[] imageData = QRBill.Generate(bill);
     return(VerifyImages.VerifySvg(imageData));
 }
Example #2
0
 private void GenerateAndCompareBill(Bill bill, string expectedFileName)
 {
     bill.Format.OutputSize     = OutputSize.A4PortraitSheet;
     bill.Format.GraphicsFormat = GraphicsFormat.SVG;
     byte[] imageData = QRBill.Generate(bill);
     FileComparison.AssertFileContentsEqual(imageData, expectedFileName);
 }
Example #3
0
 private Task GenerateAndCompareBill(Bill bill, GraphicsFormat graphicsFormat, SeparatorType separatorType)
 {
     bill.Format.GraphicsFormat = graphicsFormat;
     bill.Format.SeparatorType  = separatorType;
     byte[] imageData = QRBill.Generate(bill);
     return(VerifyImages.Verify(imageData, graphicsFormat));
 }
Example #4
0
        /// <summary>
        /// Generates a QR bill and saves it as a SVG file.
        /// </summary>
        static void Main()
        {
            // Setup bill data
            Bill 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",

                // output format
                Format = new BillFormat
                {
                    Language       = Language.DE,
                    GraphicsFormat = GraphicsFormat.SVG,
                    OutputSize     = OutputSize.QrBillOnly
                }
            };

            // Generate QR bill as SVG
            byte[] svg = QRBill.Generate(bill);

            // Save generated SVG file
            const string path = "qrbill.svg";

            File.WriteAllBytes(path, svg);
            Console.WriteLine($"SVG QR bill saved at { Path.GetFullPath(path) }");

            // Generate QR bill as PNG
            bill.Format.GraphicsFormat = GraphicsFormat.PNG;
            byte[] png = QRBill.Generate(bill);

            // Save generated PNG file
            const string pngPath = "qrbill.png";

            File.WriteAllBytes(pngPath, png);
            Console.WriteLine($"PNG QR bill saved at { Path.GetFullPath(pngPath) }");
        }
Example #5
0
 private Task GenerateAndCompareBill(Bill bill, OutputSize outputSize, GraphicsFormat graphicsFormat)
 {
     bill.Format.OutputSize     = outputSize;
     bill.Format.GraphicsFormat = graphicsFormat;
     byte[] imageData = QRBill.Generate(bill);
     return(VerifyImages.Verify(imageData, graphicsFormat));
 }
 private void GenerateAndCompareBill(Bill bill, GraphicsFormat graphicsFormat, SeparatorType separatorType,
                                     string expectedFileName)
 {
     bill.Format.GraphicsFormat = graphicsFormat;
     bill.Format.SeparatorType  = separatorType;
     byte[] imageData = QRBill.Generate(bill);
     FileComparison.AssertFileContentsEqual(imageData, expectedFileName);
 }
Example #7
0
 private void GenerateAndCompareBill(Bill bill, OutputSize outputSize, GraphicsFormat graphicsFormat,
                                     string expectedFileName)
 {
     bill.Format.OutputSize     = outputSize;
     bill.Format.GraphicsFormat = graphicsFormat;
     byte[] imageData = QRBill.Generate(bill);
     FileComparison.AssertFileContentsEqual(imageData, expectedFileName);
 }
Example #8
0
 private Task GenerateAndCompareBill(Bill bill, OutputSize outputSize, GraphicsFormat graphicsFormat)
 {
     bill.Format.OutputSize     = outputSize;
     bill.Format.GraphicsFormat = graphicsFormat;
     bill.Format.FontFamily     = "Arial,\"Liberation Sans\"";
     byte[] imageData = QRBill.Generate(bill);
     return(VerifyImages.VerifyPng(imageData));
 }
Example #9
0
        public Task CreateQrBill5()
        {
            Bill bill = SampleData.CreateExample3();

            bill.Format.OutputSize     = OutputSize.QrBillExtraSpace;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
Example #10
0
        public Task CreateQrBillFrench()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            bill.Format.Language       = Language.FR;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
Example #11
0
        private void QrCodeAsSvg4()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize     = OutputSize.QrCodeOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrcode_ex4.svg");
        }
Example #12
0
        private static void GenerateWithInvalidData1()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Creditor.Name         = " ";
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.PDF;
            QRBill.Generate(bill);
        }
Example #13
0
        public void CreateQrBill5()
        {
            Bill bill = SampleData.CreateExample3();

            bill.Format.OutputSize     = OutputSize.QrBillWithHorizontalLine;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_ex5.svg");
        }
Example #14
0
        public void CreateQrBillFrench()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            bill.Format.Language       = Language.FR;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_fr.svg");
        }
Example #15
0
        public void CreateQrBill4()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_ex4.svg");
        }
Example #16
0
        public Task QrCodeAsSvg4()
        {
            Bill bill = SampleData.CreateExample4();

            bill.Format.OutputSize     = OutputSize.QrCodeOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
Example #17
0
        public Task SvgWithChallengingCharacters()
        {
            Bill bill = SampleData.CreateExample1();

            bill.UnstructuredMessage   = "<h1>&&\"ff\"'t'";
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            return(VerifyImages.VerifySvg(svg));
        }
Example #18
0
        private static void GenerateWithInvalidData3()
        {
            Bill bill = SampleData.CreateExample1();

            bill.Reference             = "RF1234";
            bill.Currency              = "XXX";
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.PDF;
            QRBill.Generate(bill);
        }
Example #19
0
        private static void GenerateWithInvalidData2()
        {
            Bill bill = SampleData.CreateExample1();

            bill.UnstructuredMessage   = null;
            bill.BillInformation       = "//" + new String('X', 150);
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.PDF;
            QRBill.Generate(bill);
        }
Example #20
0
        public void SvgWithChallengingCharacters()
        {
            Bill bill = SampleData.CreateExample1();

            bill.UnstructuredMessage   = "<h1>&&\"ff\"'t'";
            bill.Format.OutputSize     = OutputSize.QrBillOnly;
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_sc1.svg");
        }
Example #21
0
        public void CreateQrBill5b()
        {
            Bill bill = SampleData.CreateExample3();

#pragma warning disable CS0618 // Type or member is obsolete
            bill.Format.OutputSize = OutputSize.QrBillWithHorizontalLine;
#pragma warning restore CS0618 // Type or member is obsolete
            bill.Format.GraphicsFormat = GraphicsFormat.SVG;
            byte[] svg = QRBill.Generate(bill);
            FileComparison.AssertFileContentsEqual(svg, "qrbill_ex5.svg");
        }
Example #22
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));
        }
Example #23
0
        static void Main(string[] args)
        {
            // Setup bill data
            Bill 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"
            };

            // Generate QR bill
            byte[] svg = QRBill.Generate(bill);

            // Save generated SVG file
            const string path = "qrbill.svg";

            File.WriteAllBytes(path, svg);
            Console.WriteLine($"QR bill saved at { Path.GetFullPath(path) }");
        }
Example #24
0
        private void GenerateQRBill(string locale, string expectedFileName)
        {
            CultureInfo savedCurrentCulture   = CultureInfo.CurrentCulture;
            CultureInfo savedCurrentUiCulture = CultureInfo.CurrentUICulture;

            CultureInfo culture = CultureInfo.CreateSpecificCulture(locale);

            try
            {
                CultureInfo.CurrentCulture   = culture;
                CultureInfo.CurrentUICulture = culture;

                Bill bill = SampleData.CreateExample3();
                bill.Format.OutputSize     = OutputSize.QrBillOnly;
                bill.Format.GraphicsFormat = GraphicsFormat.SVG;
                byte[] svg = QRBill.Generate(bill);
                FileComparison.AssertFileContentsEqual(svg, expectedFileName);
            }
            finally
            {
                CultureInfo.CurrentCulture   = savedCurrentCulture;
                CultureInfo.CurrentUICulture = savedCurrentUiCulture;
            }
        }
Example #25
0
        public Task CurrentCulture(string locale)
        {
            CultureInfo savedCurrentCulture   = CultureInfo.CurrentCulture;
            CultureInfo savedCurrentUiCulture = CultureInfo.CurrentUICulture;

            CultureInfo culture = CultureInfo.CreateSpecificCulture(locale);

            try
            {
                CultureInfo.CurrentCulture   = culture;
                CultureInfo.CurrentUICulture = culture;

                Bill bill = SampleData.CreateExample3();
                bill.Format.OutputSize     = OutputSize.QrBillOnly;
                bill.Format.GraphicsFormat = GraphicsFormat.SVG;
                byte[] svg = QRBill.Generate(bill);
                return(VerifyImages.VerifySvg(svg).UseParameters(locale));
            }
            finally
            {
                CultureInfo.CurrentCulture   = savedCurrentCulture;
                CultureInfo.CurrentUICulture = savedCurrentUiCulture;
            }
        }