Esempio n. 1
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);
        }
Esempio n. 2
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));
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
        public void InsertQrBill()
        {
            // 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   = Generator.Language.DE,
                    OutputSize = OutputSize.QrBillExtraSpace
                }
            };

            // create EMF file
            var path = Path.GetTempFileName();

            using (MetafileCanvas canvas = new MetafileCanvas(210, 110, "Arial"))
            {
                QRBill.Draw(bill, canvas);
                File.WriteAllBytes(path, canvas.ToByteArray());
            }

            // insert EMF file into document (at bottom of page)
            var shape = Application.ActiveDocument.Shapes.AddPicture(path,
                                                                     Left: 0, Top: (297 - 110) / 25.4f * 72,
                                                                     Width: 210 / 25.4f * 72, Height: 110 / 25.4f * 72);

            shape.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
            shape.Left = -999998;
            shape.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
            shape.Top = -999997;
            shape.Select(true);

            // delete temporary file
            File.Delete(path);
        }