Exemplo n.º 1
0
        public void TestMethod1()
        {
            var label = new Label()
            {
                Width  = 500,
                Height = 300,
                Name   = "My Label Print"
            };

            //var songtiTypeface = SKTypeface.FromFamilyName("宋体");

            var index = SKFontManager.Default.FontFamilies.ToList().IndexOf("宋体");

            var songtiTypeface = SKFontManager.Default.GetFontStyles(index).CreateTypeface(0);

            var songtiPaint = new SKPaint(new SKFont(songtiTypeface)
            {
                Size = 24
            })
            {
                Color = SKColor.Parse("000000"),
                Style = SKPaintStyle.StrokeAndFill
            };

            var segoeUiPaint = new SKPaint(new SKFont(SKTypeface.FromFamilyName("Algerian")))
            {
                Color = SKColor.Parse("000000"),
                Style = SKPaintStyle.StrokeAndFill
            };


            var titleText = new TextControl()
            {
                X       = 100,
                Y       = 20,
                Paint   = songtiPaint,
                Content = "这里是抬头"
            };

            var qrCodeCntrol = new QrCodeControl()
            {
                X       = 20,
                Y       = 100,
                Height  = 30,
                Width   = 30,
                Content = "er wei ma bu zhi chi zhong wen ma ? 二维码不支持中文吗?",
            };

            var contentText = new TextControl()
            {
                X       = 20,
                Y       = 100,
                Paint   = songtiPaint,
                Content = "物料编码"
            };

            var contentText1 = contentText.Copy() as TextControl;

            contentText1.X       = 200;
            contentText1.Content = "LSKJFDOWIEFW";

            label.Controls.Add(titleText);
            //label.Controls.Add(qrCodeCntrol);
            label.Controls.Add(contentText);
            label.Controls.Add(contentText1);

            //contentText1 = contentText1.Copy() as TextControl;
            //contentText1.X = 10;
            //contentText1.Y = 10;
            //contentText1.Content = "A";
            //label.Controls.Add(contentText1);
            //contentText1 = contentText1.Copy() as TextControl;
            //contentText1.X = 10;
            //contentText1.Y = 290;
            //label.Controls.Add(contentText1);
            //contentText1 = contentText1.Copy() as TextControl;
            //contentText1.X = 490;
            //contentText1.Y = 290;
            //label.Controls.Add(contentText1);
            //contentText1 = contentText1.Copy() as TextControl;
            //contentText1.X = 490;
            //contentText1.Y = 10;
            //label.Controls.Add(contentText1);

            label.Render(Path.Combine(savePath, $"{DateTime.Now.Ticks}.png"), SKEncodedImageFormat.Png, 100);
        }
Exemplo n.º 2
0
        public void TestDotNetPrint()
        {
            var label = new Label()
            {
                Width        = 100,
                Height       = 60,
                GraphicsUnit = GraphicsUnit.Millimeter,
                Name         = "My Label Print"
            };
            Font  titleFont = new Font("黑体", 11, FontStyle.Bold);    //标题字体
            Font  fntTxt    = new Font("宋体", 10, FontStyle.Regular); //正文文字
            Font  fntTxt1   = new Font("宋体", 8, FontStyle.Regular);  //正文文字
            Brush brush     = new SolidBrush(Color.Black);           //画刷
            Pen   pen       = new Pen(Color.Black, 0.2f);            //线条颜色

            var boxControl = new BoxControl()
            {
                X      = 1,
                Y      = 1,
                Width  = 98,
                Height = 58,
                Pen    = pen
            };

            var titleText = new TextControl()
            {
                X       = 35,
                Y       = 2,
                Font    = titleFont,
                Brush   = brush,
                Content = "这里是抬头"
            };

            var horLine = new HorizontalLineControl()
            {
                X      = 2,
                Y      = 8,
                Pen    = pen,
                Length = 96
            };

            var qrCodeCntrol = new QrCodeControl()
            {
                X       = 2,
                Y       = 9,
                Height  = 30,
                Width   = 30,
                Content = "er wei ma bu zhi chi zhong wen ma ? 二维码不支持中文吗?",
            };

            var verLien = new VerticalLineControl()
            {
                X      = 33,
                Y      = 9,
                Pen    = pen,
                Length = 30
            };

            var contentText = new TextControl()
            {
                X       = 34,
                Y       = 9,
                Brush   = brush,
                Font    = fntTxt,
                Content = "物料编码"
            };

            var contentText1 = contentText.Copy() as TextControl;

            contentText1.X       = 51;
            contentText1.Font    = fntTxt1;
            contentText1.Content = "LSKJFDOWIEFW";

            label.Controls.Add(boxControl);
            label.Controls.Add(titleText);
            label.Controls.Add(horLine);
            label.Controls.Add(verLien);
            label.Controls.Add(qrCodeCntrol);
            label.Controls.Add(contentText);
            label.Controls.Add(contentText1);

            horLine        = horLine.Copy() as HorizontalLineControl;
            horLine.Y      = 40;
            horLine.Length = horLine.Length;
            label.Controls.Add(horLine);

            label.Print("Microsoft XPS Document Writer", 1);
        }