Example #1
0
        private static void PrintPageLab(object sender, PrintPageEventArgs e)
        {
            //PrivateFontCollection pfc = new PrivateFontCollection();
            //pfc.AddFontFile(@"Resources\IDAutomationSC128L SymbolEncoded.ttf");
            //pfc.AddFontFile(@"Resources\Verdana-Bold.ttf");
            //generate and add barcode
            iTextSharp.text.pdf.Barcode128 code128 = new iTextSharp.text.pdf.Barcode128();
            code128.CodeType         = iTextSharp.text.pdf.Barcode.CODE128;
            code128.ChecksumText     = true;
            code128.GenerateChecksum = true;
            code128.Code             = "00" + idHsp;
            code128.BarHeight        = 35;
            System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));

            float rxStart = (float)(8 * 3.9 - 3 * 3.9);
            float ryStart = (float)(21 * 3.9 - 3 * 3.9);
            float rWidth  = (float)(48.5 * 3.9);
            float rHeight = (float)(25 * 3.9);

            //float widthStrFio = e.Graphics.MeasureString(strFio, new Font(pfc.Families[1], 7, FontStyle.Bold)).Width;
            //float widthstrIb = e.Graphics.MeasureString(strIb, new Font(pfc.Families[1], 7, FontStyle.Bold)).Width;
            //float widthstrOtd = e.Graphics.MeasureString(strOtd, new Font(pfc.Families[1], 7, FontStyle.Bold)).Width;
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 5; j++)
                {
                    //e.Graphics.DrawRectangle(Pens.Black, rxStart + rWidth * i, ryStart + rHeight * j, rWidth, rHeight);
                    StringFormat strFormat = new StringFormat();
                    strFormat.Alignment     = StringAlignment.Center;
                    strFormat.LineAlignment = StringAlignment.Center;
                    e.Graphics.DrawImage(bm, new PointF(rxStart + rWidth * i + rWidth / 2 - bm.Width / 2, ryStart + rHeight * j + 5));
                    e.Graphics.DrawString("00" + idHsp + "\n" + strFio + " | " + strIb + " | " + strDepart, new Font(pfc.Families[0], 8, FontStyle.Bold), Brushes.Black, Rectangle.Round(new RectangleF(rxStart + rWidth * i, ryStart + rHeight * j + bm.Height, rWidth, rHeight - bm.Height)), strFormat);
                }
            }
        }
Example #2
0
        ///////////////////////////////////////////// TEMPLATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
        public static bool generateImgBareCode(string path, string code)
        {
            try
            {
                iTextSharp.text.pdf.Barcode128 br = new iTextSharp.text.pdf.Barcode128();
                br.Code = code;

                // Configs.Debug(path);

                //iTextSharp.text.Image barcodeImage = iTextSharp.text.Image.GetInstance(br.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), BaseColor.BLACK);
                //barcodeImage.SetAbsolutePosition(0, 0);
                //barcodeImage.ScalePercent(72f / (float)dpi * 100f);

                System.Drawing.Bitmap bm = new System.Drawing.Bitmap(br.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));

                /*
                 * Graphics bmpgraphics = Graphics.FromImage(bm);
                 * bmpgraphics.Clear(Color.White); // Provide this, else the background will be black by default
                 *
                 * // generate the code128 barcode
                 * bmpgraphics.DrawImage(br.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), new Point(0, 0));
                 *
                 * //generate the text below the barcode image. If you want the placement to be dynamic, calculate the point based on size of the image
                 * bmpgraphics.DrawString(br.Code, new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(50 - (br.Code.Length / 2), 30));
                 */
                // Save the output stream as gif. You can also save it to external file
                bm.Save(path, System.Drawing.Imaging.ImageFormat.Gif);
                return(true);
            }
            catch (Exception ex)
            {
                Configs.Debug(ex.Message);
                return(false);
            }
        }
Example #3
0
        private static void PrintPageBracelet(object sender, PrintPageEventArgs e)
        {
            //pfc.AddFontFile(@"Resources\IDAutomationSC128L SymbolEncoded.ttf");
            //pfc.AddFontFile(@"Resources\Verdana-Bold.ttf");
            //pfc.AddFontFile(Properties.Resources.Verdana_Bold)
            //Image logoD = Image.FromFile(@"Resources\logo_kkb2.png");

            e.Graphics.DrawImage(logoD, 0, 4, 28, 88);

            e.Graphics.DrawString(strFirst, new Font(pfc.Families[0], 11, FontStyle.Bold), Brushes.Black, 32, 5);
            e.Graphics.DrawString("ИБ:" + strIb + " " + strDepart + " Тел:" + strPhone, new Font(pfc.Families[0], 11, FontStyle.Bold), Brushes.Black, 32, 74);
            //generate and add barcode
            iTextSharp.text.pdf.Barcode128 code128 = new iTextSharp.text.pdf.Barcode128();
            code128.CodeType         = iTextSharp.text.pdf.Barcode.CODE128;
            code128.ChecksumText     = true;
            code128.GenerateChecksum = true;
            code128.Code             = barCode;
            code128.BarHeight        = 40;
            System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
            //bm.SetResolution(500, 500);
            e.Graphics.DrawImage(bm, new PointF(40, 28));
        }