Esempio n. 1
0
        public void Barcode(string text, bool showText, System.Drawing.Rectangle rect)
        {
            var barcode = new Barcode128();

            barcode.CodeType = Barcode128.CODE128;
            if (!showText)
            {
                barcode.AltText = "";           //显示文本
            }
            //barcode.AltText = "qqq";
            barcode.Code = text;

            //计算X值
            if (barcode.X * (11 * text.Length + 35) < rect.Width)
            {
                barcode.X = 1.0F * rect.Width / (11 * text.Length + 35);
            }
            barcode.BarHeight = rect.Height - barcode.BarHeight;
            var rect2 = Transform2(rect);
            //System.Diagnostics.Debug.WriteLine(barcode.X);
            //System.Diagnostics.Debug.WriteLine(barcode.N);
            //barcode.X = 2; //像素单位 单个字母宽度为X的11倍
            //barcode.N = 20;
            //System.Diagnostics.Debug.WriteLine(barcode.BarcodeSize.Width);
            var img = barcode.CreateImageWithBarcode(Canvas, BaseColor.BLACK, BaseColor.BLUE);

            img.SetAbsolutePosition(rect2.Left, rect2.Top);
            Canvas.AddImage(img);
        }
Esempio n. 2
0
        protected void PrintBarcodes(PdfWriter pdfWriter, Document doc, Purchase purchase)
        {
            PdfPTable table         = new PdfPTable(1);
            var       query         = _purchaseItemRepository.Table;
            var       purchaseItems = query.Where(x => x.PurchaseId == purchase.Id).ToList();

            foreach (var purchaseItem in purchaseItems)
            {
                iTextSharp.text.pdf.PdfContentByte cb = pdfWriter.DirectContent;
                iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                bc.TextAlignment = Element.ALIGN_LEFT;
                bc.Code          = purchaseItem.EAN; // CommonUtils.GenerateBarCodeEAN13(purchaseItem.Id);
                bc.StartStopText = false;
                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                bc.Extended      = true;

                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                      iTextSharp.text.BaseColor.Black, iTextSharp.text.BaseColor.Black);

                cb.SetTextMatrix(1.5f, 3.0f);
                img.ScaleToFit(60, 5);
                img.SetAbsolutePosition(1.5f, 1);
                cb.AddImage(img);
                table.AddCell(img);
            }
            doc.Add(table);
        }
Esempio n. 3
0
        public Image GenerateBarCode()
        {
            iTextSharp.text.pdf.Barcode128 bc = new Barcode128();
            bc.TextAlignment = Element.ALIGN_CENTER;
            bc.Code          = "anything";
            bc.StartStopText = false;
            bc.CodeType      = iTextSharp.text.pdf.Barcode128.CODE128;
            bc.Extended      = true;
            //bc.Font = null;

            var            outputStream = new MemoryStream();
            var            pdfWriter    = PdfWriter.GetInstance(_document, outputStream);
            PdfContentByte cb           = new PdfContentByte(pdfWriter);

            iTextSharp.text.Image PatImage1 = bc.CreateImageWithBarcode(null, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

            return(PatImage1);
            //PatImage1.ScaleToFit(160, 20);


            //PdfPTable p_detail1 = new PdfPTable(1);
            //p_detail1.WidthPercentage = 100;

            //PdfPCell barcideimage = new PdfPCell(PatImage1);
            ////barcideimage.Colspan = 2;
            //barcideimage.HorizontalAlignment = 2;
            //barcideimage.Border = 0;
            //p_detail1.AddCell(barcideimage);

            //l1.Add(p_detail1);
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            iTextSharp.text.Rectangle pageSize = new iTextSharp.text.Rectangle(300, 720);
            Document  pdfToCreate = new Document(pageSize, 0, 0, 0, 0);
            PdfWriter writer      = PdfWriter.GetInstance(pdfToCreate, new FileStream(@"D:\\testfile.pdf", FileMode.Create));

            pdfToCreate.Open();

            PdfPTable table    = new PdfPTable(1);
            PdfPTable tableout = new PdfPTable(1);

            WriteLineToPdf("This is first row. Below is image generated using SystemDrawing.", table, out tableout);
            table = tableout;

            // Create bar code
            Barcode128 code128 = new Barcode128();

            code128.CodeType         = Barcode.CODE128;
            code128.ChecksumText     = true;
            code128.GenerateChecksum = true;
            code128.Code             = "00100370006756555316";

            // Create a new PdfWrite object, writing the output to a MemoryStream
            var            outputStream = new MemoryStream();
            var            pdfWriter    = PdfWriter.GetInstance(pdfToCreate, outputStream);
            PdfContentByte cb           = new PdfContentByte(writer);

            // Image generated using System.Drawing and rendering
            System.Drawing.Bitmap bm         = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
            iTextSharp.text.Image bmCoverted = iTextSharp.text.Image.GetInstance(bm, System.Drawing.Imaging.ImageFormat.Bmp);
            table.AddCell(bmCoverted);

            pdfToCreate.Open();

            // Image generated using iTextSharp.text.Image
            WriteLineToPdf("This is third row. Below is image generated using code128.CreateImageWithBarcode.", table, out tableout);
            table = tableout;
            iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(cb, null, null);
            table.AddCell(image128);
            table = tableout;

            WriteLineToPdf("This is fifth row.", table, out tableout);
            pdfToCreate.Add(tableout);

            // Create new document with height that depends on number of lines in document.
            iTextSharp.text.Rectangle psFinal = new iTextSharp.text.Rectangle(200, 300);
            Document  pdfFinal = new Document(psFinal, 0, 0, 0, 0);
            PdfWriter writer1  = PdfWriter.GetInstance(pdfFinal, new FileStream(@"D:\\finalfile.pdf", FileMode.Create));

            pdfFinal.Open();
            pdfFinal.Add(tableout);

            cb = null;

            pdfToCreate.Close();
            pdfFinal.Close();
        }
Esempio n. 5
0
        /// <summary>
        /// Adiconar um código de barra no formate 128
        /// </summary>
        /// <param name="value">Valor do código de barra</param>
        /// <param name="height">Altura</param>
        /// <param name="positionX">Posição X</param>
        /// <param name="positionY">Posição Y</param>
        /// <param name="valueBarCode">Mostrar o valor do códgio de barra</param>
        public void CodeBar(string value, double height, double positionX, double positionY, bool valueBarCode)
        {
            Barcode128 bar = new Barcode128();

            bar.Code = value;
            bar.Size = 1;
            iTextSharp.text.Image img128 = bar.CreateImageWithBarcode(contentByte, BaseColor.BLACK, (valueBarCode ? BaseColor.BLACK : BaseColor.WHITE));
            var positions = CalculatePositions(positionX, positionY, height);

            img128.SetAbsolutePosition((float)positions.Item1, (float)positions.Item2);
            contentByte.AddImage(img128);
        }
Esempio n. 6
0
        private Image GetImage(string text, CodeType codeType, PdfContentByte pcb)
        {
            switch (codeType)
            {
            case CodeType.Code128:
                Barcode128 barcode128 = new Barcode128 {
                    AltText = text, Code = text
                };
                return(barcode128.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK));

            case CodeType.Code39:
                Barcode39 barcode39 = new Barcode39 {
                    Code = text, AltText = text
                };
                return(barcode39.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK));

            case CodeType.Codabar:
                BarcodeCodabar barcodeCodabar = new BarcodeCodabar {
                    Code = text, AltText = text
                };
                return(barcodeCodabar.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK));

            case CodeType.Datamatrix:
                BarcodeDatamatrix barcodeDatamatrix = new BarcodeDatamatrix();
                barcodeDatamatrix.Generate(text);
                return(barcodeDatamatrix.CreateImage());

            case CodeType.EAN:
                BarcodeEAN barcodeEAN = new BarcodeEAN {
                    CodeType = Barcode.EAN13, Code = text, AltText = text
                };
                return(barcodeEAN.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK));

            case CodeType.Inter25:
                BarcodeInter25 barcodeInter25 = new BarcodeInter25
                {
                    AltText = text, Code = text, GenerateChecksum = true
                };
                return(barcodeInter25.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK));

            case CodeType.PDF417:
                BarcodePDF417 barcodePDF417 = new BarcodePDF417();
                barcodePDF417.SetText(text);
                return(barcodePDF417.GetImage());

            case CodeType.Postnet:
                BarcodePostnet barcodePostnet = new BarcodePostnet {
                    AltText = text, Code = text
                };
                return(barcodePostnet.CreateImageWithBarcode(pcb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK));
            }
            return(null);
        }
Esempio n. 7
0
        public void Label(string order_id, string code, string filePath)
        {
            string         pdf_url = string.Format("{0}/orders/{1}/labels/cropped.pdf", Endpoint, order_id);
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(pdf_url);

            request.Accept          = "application/pdf";
            request.Credentials     = new NetworkCredential(Sendle_ID, Api_Key);
            request.PreAuthenticate = true;
            request.Headers.Add("Idempotency-Key", Guid.NewGuid().ToString());

            if (File.Exists(Path.Combine(filePath, "AirWaybill.pdf")))
            {
                File.Delete(Path.Combine(filePath, "AirWaybill.pdf"));
            }
            using (HttpWebResponse httpResponse = (HttpWebResponse)request.GetResponse())
            {
                var response       = (HttpWebResponse)request.GetResponse();
                var responseStream = response.GetResponseStream();
                var fileStream     = File.Create(Path.Combine(filePath, "AirWaybill.pdf"));
                responseStream.CopyTo(fileStream);
                responseStream.Close();
                fileStream.Close();
                response.Close();
            }

            if (File.Exists(Path.Combine(filePath, "Label.pdf")))
            {
                File.Delete(Path.Combine(filePath, "Label.pdf"));
            }
            Document  document = new Document();
            PdfWriter writer   = PdfWriter.GetInstance(document, new FileStream(Path.Combine(filePath, "Label.pdf"), FileMode.Create));

            document.Open();
            PdfContentByte cb     = writer.DirectContent;
            PdfReader      reader = new PdfReader(Path.Combine(filePath, "AirWaybill.pdf"));

            document.SetPageSize(reader.GetPageSizeWithRotation(1));
            document.NewPage();

            Paragraph  pp      = new Paragraph();
            Barcode128 barcode = new Barcode128 {
                CodeType = Barcode.CODE128_UCC, Code = code
            };
            Image barcodeImage = barcode.CreateImageWithBarcode(cb, null, null);

            barcodeImage.Alignment = Element.ALIGN_CENTER;
            pp.Add(barcodeImage);
            document.Add(pp);

            document.Close();
            writer.Close();
        }
Esempio n. 8
0
        void AgregarCodigoBarras(PdfWriter wri)
        {
            PdfContentByte cb          = wri.DirectContent;
            Barcode128     bar128      = new Barcode128();
            int            codigoBarra = Convert.ToInt32(string.Format("{0}{1}", this.EventoId * 10000, this.PersonaId));

            bar128.Code = codigoBarra.ToString("X");
            Image img128 = bar128.CreateImageWithBarcode(cb, null, null);

            img128.ScaleToFit(70, 100);
            img128.SetAbsolutePosition(198f, 90f);
            doc.Add(img128);
        }
        private static void doit()
        {
            string savepath    = "M:\\StackOverflowQuestionsAndAnswers\\iTextBarcodes_58190058\\iTextBarcodes_58190058\\bin\\Debug\\codes.pdf";
            string barcode     = "blahlblahblah";
            string price       = "12.95";
            string description = "more blah blah";
            //Document doc = new Document(new iTextSharp.text.Rectangle(25, 11), 5, 8, 1, 1);
            Document  doc    = new Document();
            int       count  = 10;
            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(savepath, FileMode.Create));

            doc.Open();
            DataTable dt = new DataTable();

            dt.Columns.Add("ID");
            dt.Columns.Add("Price");
            dt.Columns.Add("Des");
            for (int i = 0; i < count; i++)
            {
                DataRow row = dt.NewRow();
                row["ID"]    = barcode;
                row["Price"] = price;
                row["Des"]   = description;
                dt.Rows.Add(row);
            }

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Paragraph p = new Paragraph();
                p.Add("Aaraiz");
                p.Add("Description: " + dt.Rows[i]["Price"].ToString());
                doc.Add(p);

                PdfContentByte cb = writer.DirectContent;
                Barcode128     bc = new Barcode128();
                bc.TextAlignment = Element.ALIGN_CENTER;
                bc.Font          = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                bc.Code          = dt.Rows[i]["ID"].ToString();
                bc.AltText       = "Code: " + dt.Rows[i]["ID"].ToString() + "  Price: " + dt.Rows[i]["Price"].ToString();
                bc.StartStopText = false;
                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                bc.Extended      = true;
                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb, iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);
                cb.SetTextMatrix(1.5f, 3.0f);
                img.ScaleToFit(60, 5);
                doc.Add(img);
            }
            doc.Close();
            System.Diagnostics.Process.Start(savepath);
        }
        public Image GetBarcodeCell(string Code, PdfWriter writer)
        {
            PdfContentByte cb      = writer.DirectContent;
            Barcode128     code128 = new Barcode128();

            code128.Font          = null;
            code128.Size          = 12;
            code128.BarHeight     = 20;
            code128.Code          = Code;
            code128.StartStopText = true;
            Image image39 = code128.CreateImageWithBarcode(cb, null, null);

            return(image39);
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            using (MemoryStream myMemoryStream = new MemoryStream())
            {
                PdfPTable tableIn;
                Document  pdfDocument = new Document();
                PdfWriter writer      = PdfWriter.GetInstance(pdfDocument, myMemoryStream);
                PdfPTable tableOut    = new PdfPTable(new float[] { 200 });
                tableIn = new PdfPTable(new float[] { 200 });
                pdfDocument.Open();

                for (int i = 0; i < 5; i++)
                {
                    WriteLineToPdf("This is row no. " + i.ToString(), tableIn, out tableOut);
                    tableIn = tableOut;
                }

                // Create bar code
                PdfContentByte cb      = writer.DirectContent;
                Barcode128     code128 = new Barcode128();
                code128.CodeType         = Barcode.CODE128;
                code128.ChecksumText     = true;
                code128.GenerateChecksum = true;
                code128.Code             = "00100370006756555316";
                Image    barCodeImage = code128.CreateImageWithBarcode(cb, null, null);
                PdfPCell cell1        = new PdfPCell(barCodeImage);
                tableOut.AddCell(cell1);
                tableIn = tableOut;
                WriteLineToPdf("This is a last row.", tableIn, out tableOut);

                pdfDocument.Add(tableOut);
                pdfDocument.Close();

                // Create final PDF document.
                Document  pdfDocument1 = new Document(new Rectangle(200, 250));
                PdfWriter writer1      = PdfWriter.GetInstance(pdfDocument1, new FileStream(@"D:\\result.pdf", FileMode.Create));
                pdfDocument1.Open();
                pdfDocument1.Add(new Chunk());
                pdfDocument1.Close();

                byte[] content = myMemoryStream.ToArray();

                // Write out PDF from memory stream.
                using (FileStream fs = File.OpenWrite(@"D:\\nikola bd - final\\out\\dummy22.pdf"))
                {
                    fs.Write(content, 0, (int)content.Length);
                }
            }
        }
Esempio n. 12
0
        private static Image GetBarcodeImage(PdfContentByte pdfContentByte)
        {
            var now  = DateTime.Now;
            var code =
                $"{now:yy}{now.Month:00}{now.Day:00}{now.Hour:00}{now.Minute:00}{now.Second:00}{now.Millisecond:0000}";

            var code128 = new Barcode128
            {
                CodeType         = Barcode.CODE128,
                ChecksumText     = true,
                GenerateChecksum = true,
                StartStopText    = true,
                Code             = code
            };

            return(code128.CreateImageWithBarcode(pdfContentByte, null, null));
        }
Esempio n. 13
0
        public static iTextSharp.text.Image GetBarcodeImage(PdfContentByte cb, string barcodeText, int width, int height)
        {
            if (string.IsNullOrWhiteSpace(barcodeText))
            {
                barcodeText = "123123123";
            }

            Barcode128 code128 = new Barcode128();

            code128.CodeType         = iTextSharp.text.pdf.Barcode.CODE128;
            code128.ChecksumText     = true;
            code128.GenerateChecksum = true;
            code128.StartStopText    = true;
            code128.Code             = barcodeText;
            iTextSharp.text.Image image = code128.CreateImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLACK);
            image.ScaleAbsoluteWidth(width);
            image.ScaleAbsoluteHeight(height);
            return(image);
        }
Esempio n. 14
0
        private static void AddHeader(Document doc, Order order, PdfWriter writer)
        {
            // Escribimos el encabezamiento en el documento
            string    tittleString = $"Order N° {order.Id}";
            Paragraph tittle       = new Paragraph(tittleString);

            //tittle.SpacingAfter = 5;
            doc.Add(tittle);

            // Add the header anchor to the page


            //OnStartPage(writer, doc, tittleString);


            Barcode128 code128 = new Barcode128();

            code128.Code = order.Id.ToString();
            PdfContentByte cb = writer.DirectContent;

            cb.Rectangle(doc.PageSize.Width - 90f, 830f, 100f, 100f);
            cb.Stroke();
            Image img = code128.CreateImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLACK);

            doc.Add(img);

            doc.Add(Chunk.NEWLINE);
            Paragraph excelName = new Paragraph($"{GetProyectName(order.ExcelPath)}");

            //tittle.SpacingAfter = 5;
            doc.Add(excelName);


            // Creamos una tabla que contendrá el nombre, apellido y país
            // de nuestros visitante.
            doc.Add(Chunk.NEWLINE);
        }
Esempio n. 15
0
        /// <summary>
        /// Generates the new page with barcode128.
        /// </summary>
        /// <param name="number">
        /// The string with code.
        /// </param>
        public void BarCodeGenerate(string number)
        {
            this.document.NewPage();

            PdfContentByte cb = this.writer.DirectContent;
            var            bc = new Barcode128
            {
                Code          = number,
                TextAlignment = Element.ALIGN_CENTER,
                StartStopText = true,
                CodeType      = Barcode.CODE128,
                Extended      = false
            };

            Rectangle rect        = this.document.PageSize;
            Image     img         = bc.CreateImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLACK);
            var       barCodeRect = new Rectangle(bc.BarcodeSize);
            var       widthScale  = rect.Width / barCodeRect.Width;
            var       heightScale = rect.Height / barCodeRect.Height;

            Rectangle tempRect;

            if (heightScale <= widthScale)
            {
                tempRect = new Rectangle(barCodeRect.Width * heightScale - 2 * hMargin, rect.Height - 2 * vMargin);
                img.ScaleAbsolute(tempRect);
            }
            else
            {
                tempRect = new Rectangle(rect.Width - 2 * hMargin, barCodeRect.Height * widthScale - 2 * vMargin);
                img.ScaleAbsolute(tempRect);
            }

            img.SetAbsolutePosition((rect.Width - tempRect.Width) / 2, (rect.Height - tempRect.Height) / 2);
            cb.AddImage(img);
        }
Esempio n. 16
0
// ===========================================================================
        public void Write(Stream stream)
        {
            // step 1
            using (Document document = new Document(new Rectangle(340, 842))) {
                // step 2
                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                // step 3
                document.Open();
                // step 4
                PdfContentByte cb = writer.DirectContent;

                // EAN 13
                document.Add(new Paragraph("Barcode EAN.UCC-13"));
                BarcodeEAN codeEAN = new BarcodeEAN();
                codeEAN.Code = "4512345678906";
                document.Add(new Paragraph("default:"));
                document.Add(codeEAN.CreateImageWithBarcode(cb, null, null));
                codeEAN.GuardBars = false;
                document.Add(new Paragraph("without guard bars:"));
                document.Add(codeEAN.CreateImageWithBarcode(cb, null, null));
                codeEAN.Baseline  = -1f;
                codeEAN.GuardBars = true;
                document.Add(new Paragraph("text above:"));
                document.Add(codeEAN.CreateImageWithBarcode(cb, null, null));
                codeEAN.Baseline = codeEAN.Size;

                // UPC A
                document.Add(new Paragraph("Barcode UCC-12 (UPC-A)"));
                codeEAN.CodeType = Barcode.UPCA;
                codeEAN.Code     = "785342304749";
                document.Add(codeEAN.CreateImageWithBarcode(cb, null, null));

                // EAN 8
                document.Add(new Paragraph("Barcode EAN.UCC-8"));
                codeEAN.CodeType  = Barcode.EAN8;
                codeEAN.BarHeight = codeEAN.Size * 1.5f;
                codeEAN.Code      = "34569870";
                document.Add(codeEAN.CreateImageWithBarcode(cb, null, null));

                // UPC E
                document.Add(new Paragraph("Barcode UPC-E"));
                codeEAN.CodeType = Barcode.UPCE;
                codeEAN.Code     = "03456781";
                document.Add(codeEAN.CreateImageWithBarcode(cb, null, null));
                codeEAN.BarHeight = codeEAN.Size * 3f;

                // EANSUPP
                document.Add(new Paragraph("Bookland"));
                document.Add(new Paragraph("ISBN 0-321-30474-8"));
                codeEAN.CodeType = Barcode.EAN13;
                codeEAN.Code     = "9781935182610";
                BarcodeEAN codeSUPP = new BarcodeEAN();
                codeSUPP.CodeType = Barcode.SUPP5;
                codeSUPP.Code     = "55999";
                codeSUPP.Baseline = -2;
                BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
                document.Add(eanSupp.CreateImageWithBarcode(cb, null, BaseColor.BLUE));

                // CODE 128
                document.Add(new Paragraph("Barcode 128"));
                Barcode128 code128 = new Barcode128();
                code128.Code = "0123456789 hello";
                document.Add(code128.CreateImageWithBarcode(cb, null, null));
                code128.Code     = "0123456789\uffffMy Raw Barcode (0 - 9)";
                code128.CodeType = Barcode.CODE128_RAW;
                document.Add(code128.CreateImageWithBarcode(cb, null, null));

                // Data for the barcode :
                String        code402 = "24132399420058289";
                String        code90  = "3700000050";
                String        code421 = "422356";
                StringBuilder data    = new StringBuilder(code402);
                data.Append(Barcode128.FNC1);
                data.Append(code90);
                data.Append(Barcode128.FNC1);
                data.Append(code421);
                Barcode128 shipBarCode = new Barcode128();
                shipBarCode.X             = 0.75f;
                shipBarCode.N             = 1.5f;
                shipBarCode.Size          = 10f;
                shipBarCode.TextAlignment = Element.ALIGN_CENTER;
                shipBarCode.Baseline      = 10f;
                shipBarCode.BarHeight     = 50f;
                shipBarCode.Code          = data.ToString();
                document.Add(shipBarCode.CreateImageWithBarcode(
                                 cb, BaseColor.BLACK, BaseColor.BLUE
                                 ));

                // it is composed of 3 blocks whith AI 01, 3101 and 10
                Barcode128 uccEan128 = new Barcode128();
                uccEan128.CodeType = Barcode.CODE128_UCC;
                uccEan128.Code     = "(01)00000090311314(10)ABC123(15)060916";
                document.Add(uccEan128.CreateImageWithBarcode(
                                 cb, BaseColor.BLUE, BaseColor.BLACK
                                 ));
                uccEan128.Code = "0191234567890121310100035510ABC123";
                document.Add(uccEan128.CreateImageWithBarcode(
                                 cb, BaseColor.BLUE, BaseColor.RED
                                 ));
                uccEan128.Code = "(01)28880123456788";
                document.Add(uccEan128.CreateImageWithBarcode(
                                 cb, BaseColor.BLUE, BaseColor.BLACK
                                 ));

                // INTER25
                document.Add(new Paragraph("Barcode Interleaved 2 of 5"));
                BarcodeInter25 code25 = new BarcodeInter25();
                code25.GenerateChecksum = true;
                code25.Code             = "41-1200076041-001";
                document.Add(code25.CreateImageWithBarcode(cb, null, null));
                code25.Code = "411200076041001";
                document.Add(code25.CreateImageWithBarcode(cb, null, null));
                code25.Code         = "0611012345678";
                code25.ChecksumText = true;
                document.Add(code25.CreateImageWithBarcode(cb, null, null));

                // POSTNET
                document.Add(new Paragraph("Barcode Postnet"));
                BarcodePostnet codePost = new BarcodePostnet();
                document.Add(new Paragraph("ZIP"));
                codePost.Code = "01234";
                document.Add(codePost.CreateImageWithBarcode(cb, null, null));
                document.Add(new Paragraph("ZIP+4"));
                codePost.Code = "012345678";
                document.Add(codePost.CreateImageWithBarcode(cb, null, null));
                document.Add(new Paragraph("ZIP+4 and dp"));
                codePost.Code = "01234567890";
                document.Add(codePost.CreateImageWithBarcode(cb, null, null));

                document.Add(new Paragraph("Barcode Planet"));
                BarcodePostnet codePlanet = new BarcodePostnet();
                codePlanet.Code     = "01234567890";
                codePlanet.CodeType = Barcode.PLANET;
                document.Add(codePlanet.CreateImageWithBarcode(cb, null, null));

                // CODE 39
                document.Add(new Paragraph("Barcode 3 of 9"));
                Barcode39 code39 = new Barcode39();
                code39.Code = "ITEXT IN ACTION";
                document.Add(code39.CreateImageWithBarcode(cb, null, null));

                document.Add(new Paragraph("Barcode 3 of 9 extended"));
                Barcode39 code39ext = new Barcode39();
                code39ext.Code          = "iText in Action";
                code39ext.StartStopText = false;
                code39ext.Extended      = true;
                document.Add(code39ext.CreateImageWithBarcode(cb, null, null));

                // CODABAR
                document.Add(new Paragraph("Codabar"));
                BarcodeCodabar codabar = new BarcodeCodabar();
                codabar.Code          = "A123A";
                codabar.StartStopText = true;
                document.Add(codabar.CreateImageWithBarcode(cb, null, null));

                // PDF417
                document.Add(new Paragraph("Barcode PDF417"));
                BarcodePDF417 pdf417 = new BarcodePDF417();
                String        text   = "Call me Ishmael. Some years ago--never mind how long "
                                       + "precisely --having little or no money in my purse, and nothing "
                                       + "particular to interest me on shore, I thought I would sail about "
                                       + "a little and see the watery part of the world."
                ;
                pdf417.SetText(text);
                Image img = pdf417.GetImage();
                img.ScalePercent(50, 50 * pdf417.YHeight);
                document.Add(img);

                document.Add(new Paragraph("Barcode Datamatrix"));
                BarcodeDatamatrix datamatrix = new BarcodeDatamatrix();
                datamatrix.Generate(text);
                img = datamatrix.CreateImage();
                document.Add(img);

                document.Add(new Paragraph("Barcode QRCode"));
                BarcodeQRCode qrcode = new BarcodeQRCode(
                    "Moby Dick by Herman Melville", 1, 1, null
                    );
                img = qrcode.GetImage();
                document.Add(img);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            conn.Open();

            string query = ("select eru.emp_ru_name,eru.emp_ru_idcard,eru.emp_ru_birthday,eru.emp_ru_age,eru.emp_ru_telwork,eru.emp_ru_telmobile,eru.emp_ru_telhome,eru.emp_ru_telparent,eru.emp_ru_nameparent,eru.em_ru_addressparent,eru.emp_ru_namedad,eru.emp_ru_namemom,eru.emp_ru_namehusband_and_wife,eru.emp_ru_address,workplace.workplace,position.pos_id,eru.emp_ru_id ,privilege.privil_status from employee_ru eru left join workplace  on workplace.workplace_id = eru.workplace_id left join position on position.pos_id = eru.pos_id left join privilege on privilege.emp_ru_id = eru.emp_ru_id where eru.emp_ru_idcard ='" + tb1.Text + "'");

            cmd = new SqlCommand(query, conn);
            sdr = cmd.ExecuteReader();
            if (sdr.Read())
            {
                string privil_status = sdr["privil_status"].ToString();
                if (privil_status != "ได้รับสิทธิการรักษา")
                {
                    string   emp_ru_name                 = sdr["emp_ru_name"].ToString();
                    string   emp_ru_idcard               = sdr["emp_ru_idcard"].ToString();
                    DateTime birthday                    = Convert.ToDateTime(sdr["emp_ru_birthday"].ToString());
                    string   date_birth                  = String.Format("{0:yyyy-MM-dd}", birthday);
                    string   emp_ru_birthday             = date_birth;
                    string   emp_ru_age                  = sdr["emp_ru_age"].ToString();
                    string   emp_ru_telwork              = sdr["emp_ru_telwork"].ToString();
                    string   emp_ru_telmobile            = sdr["emp_ru_telmobile"].ToString();
                    string   emp_ru_telhome              = sdr["emp_ru_telhome"].ToString();
                    string   emp_ru_telparent            = sdr["emp_ru_telparent"].ToString();
                    string   emp_ru_nameparent           = sdr["emp_ru_nameparent"].ToString();
                    string   em_ru_addressparent         = sdr["em_ru_addressparent"].ToString();
                    string   emp_ru_namedad              = sdr["emp_ru_namedad"].ToString();
                    string   emp_ru_namemom              = sdr["emp_ru_namemom"].ToString();
                    string   emp_ru_namehusband_and_wife = sdr["emp_ru_namehusband_and_wife"].ToString();
                    string   emp_ru_address              = sdr["emp_ru_address"].ToString();
                    string   workplace                   = sdr["workplace"].ToString();

                    int    emp_ru_id = Convert.ToInt32(sdr["emp_ru_id"].ToString());
                    string pos_id    = sdr["pos_id"].ToString();

                    /*     query = ("insert into opd (emp_ru_id,pos_id)" +
                     * "values('" + emp_ru_id + "','" + pos_id + "')");
                     *   cmd = new SqlCommand(query, conn);
                     *   sda = new SqlDataAdapter(cmd);
                     *   dt = new DataTable();
                     *   sda.Fill(dt);*/

                    query = ("insert into opd (opd_name,opd_idcard,opd_birthday,opd_age,opd_telwork,opd_telmobile ,opd_telhome,opd_workplace,opd_telparent,opd_nameparent,opd_addressparent,opd_namedad,opd_namemom,opd_namehusband_and_wife,opd_address,emp_ru_id,pos_id)" +
                             "values('" + emp_ru_name + " ','" + emp_ru_idcard + " ','" + emp_ru_birthday + "','" + emp_ru_age + " '," +
                             "'" + emp_ru_telwork + " ','" + emp_ru_telmobile + " ','" + emp_ru_telhome + " ','" + workplace + "','" + emp_ru_telparent + " '," +
                             "'" + emp_ru_nameparent + "','" + em_ru_addressparent + " ','" + emp_ru_namedad + " '" +
                             ",'" + emp_ru_namemom + "','" + emp_ru_namehusband_and_wife + " ','" + emp_ru_address + " ','" + emp_ru_id + "','" + pos_id + "')");
                    cmd = new SqlCommand(query, conn);
                    sda = new SqlDataAdapter(cmd);
                    dt  = new DataTable();
                    sda.Fill(dt);
                    query = ("select opd_id from opd where emp_ru_id ='" + emp_ru_id + "'");
                    cmd   = new SqlCommand(query, conn);
                    sdr   = cmd.ExecuteReader();
                    if (sdr.Read())
                    {
                        int id = Convert.ToInt32(sdr["opd_id"].ToString());

                        query = ("select count(*) from privilege where emp_ru_id = '" + emp_ru_id + "'");
                        cmd   = new SqlCommand(query, conn);
                        sda   = new SqlDataAdapter(cmd);
                        dt    = new DataTable();
                        sda.Fill(dt);
                        //  sdr = cmd.ExecuteReader();
                        int count_par = (int)cmd.ExecuteScalar();
                        if (count_par == 1)
                        {
                            query = ("update privilege set privil_status = 'ได้รับสิทธิการรักษา', opd_id = '" + id + "' , date = SYSDATETIME() , time = SYSDATETIME() where emp_ru_id = '" + emp_ru_id + "'");
                            cmd   = new SqlCommand(query, conn);
                            sda   = new SqlDataAdapter(cmd);
                            dt    = new DataTable();
                            sda.Fill(dt);
                            query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                            cmd   = new SqlCommand(query, conn);
                            sdr   = cmd.ExecuteReader();
                            if (sdr.Read())
                            {
                                int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                                query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                                cmd   = new SqlCommand(query, conn);
                                sda   = new SqlDataAdapter(cmd);
                                dt    = new DataTable();
                                sda.Fill(dt);



                                query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");


                                cmd = new SqlCommand(query, conn);
                                sda = new SqlDataAdapter(cmd);
                                dt  = new DataTable();
                                sda.Fill(dt);



                                string               fontpath   = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                                BaseFont             basefont   = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                                iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                                var el = new Chunk();
                                iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                                                                                   el.Font.Style, el.Font.Color);
                                el.Font = f2;

                                Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

                                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                                doc.Open();
                                iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                                iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                                bc.TextAlignment = Element.ALIGN_LEFT;
                                bc.Code          = S1.Text;
                                bc.StartStopText = false;
                                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                                bc.Extended      = true;

                                iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                                ru.ScalePercent(15f);



                                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                                      iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

                                cb.SetTextMatrix(100f, 150.5f);
                                img.ScaleToFit(150, 159);
                                img.SetAbsolutePosition(100f, 150f);
                                //     doc.Add(ru);
                                PdfPTable headerTable = new PdfPTable(2);
                                headerTable.TotalWidth          = 530f;
                                headerTable.HorizontalAlignment = 0;
                                headerTable.SpacingAfter        = 20;
                                //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;

                                float[] headerTableColWidth = new float[2];
                                headerTableColWidth[0] = 220f;
                                headerTableColWidth[1] = 310f;

                                headerTable.SetWidths(headerTableColWidth);
                                headerTable.LockedWidth = true;

                                PdfPCell headerTableCell_0 = new PdfPCell(ru);
                                headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                                headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                headerTable.AddCell(headerTableCell_0);

                                PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));

                                head.HorizontalAlignment = Element.ALIGN_LEFT;
                                head.VerticalAlignment   = Element.ALIGN_BOTTOM;
                                head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                //       headerTable.AddCell(new PdfPCell(ru));
                                headerTable.AddCell(head);

                                doc.Add(headerTable);
                                //   Paragraph pa = new Paragraph(""+head+"");
                                //   doc.Add(pa);
                                PdfPTable table = new PdfPTable(1);
                                //  table.AddCell(new PdfPCell(ru));
                                table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ             " + S2.Text + "\nวันเดือนปีเกิด            " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ        " + S4.Text + "\n เบอร์โทรศัพท์บ้าน             " + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง           " + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง           " + em_ru_addressparent + "\nชื่อบิดา            " + emp_ru_namedad + "\nชื่อมารดา            " + emp_ru_namemom + "\nชื่อสามีหรือภรรยา            " + emp_ru_namehusband_and_wife + "\nที่อยู่           " + emp_ru_address + "\nสังกัด      " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้            " + S1.Text + "\nรหัสผ่าน              " + S3.Text + "", el.Font)));
                                table.AddCell(new PdfPCell(img));
                                //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                                // table.AddCell(img);
                                // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                                //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                                //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                                doc.Add(table);
                                doc.Close();
                                System.Diagnostics.Process.Start("" + S2.Text + ".pdf");

                                clinic_approve_step2 appr2 = new clinic_approve_step2();
                                appr2.Show();
                                clinic_approve approve = new clinic_approve();
                                approve.Close();
                                Visible = false;
                            }
                        }
                        else
                        {
                            query = ("insert into privilege (privil_status,emp_ru_idcard,date,time,opd_id,emp_ru_id) values('ได้รับสิทธิการรักษา','" + emp_ru_idcard + "',SYSDATETIME(), SYSDATETIME(),'" + id + "','" + emp_ru_id + "');");
                            cmd   = new SqlCommand(query, conn);
                            sda   = new SqlDataAdapter(cmd);
                            dt    = new DataTable();
                            sda.Fill(dt);
                            query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                            cmd   = new SqlCommand(query, conn);
                            sdr   = cmd.ExecuteReader();
                            if (sdr.Read())
                            {
                                int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                                query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                                cmd   = new SqlCommand(query, conn);
                                sda   = new SqlDataAdapter(cmd);
                                dt    = new DataTable();
                                sda.Fill(dt);



                                query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");


                                cmd = new SqlCommand(query, conn);
                                sda = new SqlDataAdapter(cmd);
                                dt  = new DataTable();
                                sda.Fill(dt);



                                string               fontpath   = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                                BaseFont             basefont   = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                                iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                                var el = new Chunk();
                                iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                                                                                   el.Font.Style, el.Font.Color);
                                el.Font = f2;

                                Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);

                                PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                                doc.Open();
                                iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                                iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                                bc.TextAlignment = Element.ALIGN_LEFT;
                                bc.Code          = S1.Text;
                                bc.StartStopText = false;
                                bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                                bc.Extended      = true;

                                iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                                ru.ScalePercent(15f);



                                iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                                      iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

                                cb.SetTextMatrix(100f, 150.5f);
                                img.ScaleToFit(150, 159);
                                img.SetAbsolutePosition(100f, 150f);
                                //     doc.Add(ru);
                                PdfPTable headerTable = new PdfPTable(2);
                                headerTable.TotalWidth          = 530f;
                                headerTable.HorizontalAlignment = 0;
                                headerTable.SpacingAfter        = 20;
                                //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;

                                float[] headerTableColWidth = new float[2];
                                headerTableColWidth[0] = 220f;
                                headerTableColWidth[1] = 310f;

                                headerTable.SetWidths(headerTableColWidth);
                                headerTable.LockedWidth = true;

                                PdfPCell headerTableCell_0 = new PdfPCell(ru);
                                headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                                headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                headerTable.AddCell(headerTableCell_0);

                                PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));

                                head.HorizontalAlignment = Element.ALIGN_LEFT;
                                head.VerticalAlignment   = Element.ALIGN_BOTTOM;
                                head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                //       headerTable.AddCell(new PdfPCell(ru));
                                headerTable.AddCell(head);

                                doc.Add(headerTable);
                                //   Paragraph pa = new Paragraph(""+head+"");
                                //   doc.Add(pa);
                                PdfPTable table = new PdfPTable(1);
                                //  table.AddCell(new PdfPCell(ru));
                                table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ " + S2.Text + "\nวันเดือนปีเกิด " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ " + S4.Text + "\n เบอร์โทรศัพท์บ้าน" + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง" + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง" + em_ru_addressparent + "\nชื่อบิดา" + emp_ru_namedad + "\nชื่อมารดา" + emp_ru_namemom + "\nชื่อสามีหรือภรรยา" + emp_ru_namehusband_and_wife + "\nที่อยู่" + emp_ru_address + "\nสังกัด  " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้ " + S1.Text + "\nรหัสผ่าน " + S3.Text + "", el.Font)));
                                table.AddCell(new PdfPCell(img));
                                //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                                // table.AddCell(img);
                                // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                                //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                                //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                                doc.Add(table);
                                doc.Close();
                                System.Diagnostics.Process.Start("" + S2.Text + ".pdf");



                                clinic_approve_step2 appr2 = new clinic_approve_step2();
                                appr2.Show();
                                clinic_approve approve = new clinic_approve();
                                approve.Close();
                                Visible = false;
                            }
                        }

                        /*
                         * if (count_par == 1)
                         * {
                         *
                         *  query = ("update privilege set privil_status = 'ได้รับสิทธิการรักษา', opd_id = '" + id + "' , date = SYSDATETIME() , time = SYSDATETIME() where emp_ru_id = '" + emp_ru_id + "'");
                         *  cmd = new SqlCommand(query, conn);
                         *  sda = new SqlDataAdapter(cmd);
                         *  dt = new DataTable();
                         *  sda.Fill(dt);
                         *  query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                         *  cmd = new SqlCommand(query, conn);
                         *  sdr = cmd.ExecuteReader();
                         *  if (sdr.Read())
                         *  {
                         *      int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                         *      query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *      query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");
                         *
                         *
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *
                         *      string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                         *      BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                         *      iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                         *      var el = new Chunk();
                         *      iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                         *                                      el.Font.Style, el.Font.Color);
                         *      el.Font = f2;
                         *
                         *      Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
                         *
                         *      PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                         *      doc.Open();
                         *      iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                         *      iTextSharp.text.pdf.Barcode128 bc = new Barcode128();
                         *      bc.TextAlignment = Element.ALIGN_LEFT;
                         *      bc.Code = S1.Text;
                         *      bc.StartStopText = false;
                         *      bc.CodeType = iTextSharp.text.pdf.Barcode128.EAN13;
                         *      bc.Extended = true;
                         *
                         *      iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                         *      ru.ScalePercent(15f);
                         *
                         *
                         *
                         *
                         *      iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                         *        iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);
                         *
                         *      cb.SetTextMatrix(100f, 150.5f);
                         *      img.ScaleToFit(150, 159);
                         *      img.SetAbsolutePosition(100f, 150f);
                         *      //     doc.Add(ru);
                         *      PdfPTable headerTable = new PdfPTable(2);
                         *      headerTable.TotalWidth = 530f;
                         *      headerTable.HorizontalAlignment = 0;
                         *      headerTable.SpacingAfter = 20;
                         *      //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
                         *
                         *      float[] headerTableColWidth = new float[2];
                         *      headerTableColWidth[0] = 220f;
                         *      headerTableColWidth[1] = 310f;
                         *
                         *      headerTable.SetWidths(headerTableColWidth);
                         *      headerTable.LockedWidth = true;
                         *
                         *      PdfPCell headerTableCell_0 = new PdfPCell(ru);
                         *      headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      headerTable.AddCell(headerTableCell_0);
                         *
                         *      PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));
                         *
                         *      head.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      head.VerticalAlignment = Element.ALIGN_BOTTOM;
                         *      head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      //       headerTable.AddCell(new PdfPCell(ru));
                         *      headerTable.AddCell(head);
                         *
                         *      doc.Add(headerTable);
                         *      //   Paragraph pa = new Paragraph(""+head+"");
                         *      //   doc.Add(pa);
                         *      PdfPTable table = new PdfPTable(1);
                         *      //  table.AddCell(new PdfPCell(ru));
                         *      table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ " + S2.Text + "\nวันเดือนปีเกิด " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ " + S4.Text + "\n เบอร์โทรศัพท์บ้าน" + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง" + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง" + em_ru_addressparent + "\nชื่อบิดา" + emp_ru_namedad + "\nชื่อมารดา" + emp_ru_namemom + "\nชื่อสามีหรือภรรยา" + emp_ru_namehusband_and_wife + "\nที่อยู่" + emp_ru_address + "\nสังกัด  " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้ " + S1.Text + "\nรหัสผ่าน " + S3.Text + "", el.Font)));
                         *      table.AddCell(new PdfPCell(img));
                         *      //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                         *      // table.AddCell(img);
                         *      // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                         *      //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                         *      //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                         *      doc.Add(table);
                         *      doc.Close();
                         *      System.Diagnostics.Process.Start("" + S2.Text + ".pdf");
                         *
                         *      clinic_approve_step2 appr2 = new clinic_approve_step2();
                         *      appr2.Show();
                         *      clinic_approve approve = new clinic_approve();
                         *      approve.Close();
                         *      Visible = false;
                         *
                         *
                         *  }
                         *  else
                         *  {
                         */
                        /*
                         *  query = ("insert into privilege (privil_status,emp_ru_idcard,date,time,opd_id,emp_ru_id) values('ได้รับสิทธิการรักษา','" + emp_ru_idcard + "',SYSDATETIME(), SYSDATETIME(),'" + id + "','" + emp_ru_id + "');");
                         *  cmd = new SqlCommand(query, conn);
                         *  sda = new SqlDataAdapter(cmd);
                         *  dt = new DataTable();
                         *  sda.Fill(dt);
                         *  query = ("select privil_id from privilege where emp_ru_idcard = '" + emp_ru_idcard + "'");
                         *  cmd = new SqlCommand(query, conn);
                         *  sdr = cmd.ExecuteReader();
                         *  if (sdr.Read())
                         *  {
                         *      int privil_id = Convert.ToInt32(sdr["privil_id"].ToString());
                         *      query = ("update opd set privil_id = '" + privil_id + "' where opd_idcard = '" + emp_ru_idcard + "'");
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *      query = ("insert into user_control (uct_user,uct_password,emp_ru_id,opd_id)values ('" + emp_ru_idcard + "','" + emp_ru_birthday + "','" + emp_ru_id + "','" + id + "');");
                         *
                         *
                         *      cmd = new SqlCommand(query, conn);
                         *      sda = new SqlDataAdapter(cmd);
                         *      dt = new DataTable();
                         *      sda.Fill(dt);
                         *
                         *
                         *
                         *
                         *      string fontpath = Environment.GetEnvironmentVariable("SystemRoot") + "../fonts/THSarabun.ttf";
                         *      BaseFont basefont = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, true);
                         *      iTextSharp.text.Font arabicFont = new iTextSharp.text.Font(basefont, 30, iTextSharp.text.Font.NORMAL);
                         *      var el = new Chunk();
                         *      iTextSharp.text.Font f2 = new iTextSharp.text.Font(basefont, el.Font.Size,
                         *                                      el.Font.Style, el.Font.Color);
                         *      el.Font = f2;
                         *
                         *      Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35);
                         *
                         *      PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("" + S2.Text + ".pdf", FileMode.Create));
                         *      doc.Open();
                         *      iTextSharp.text.pdf.PdfContentByte cb = wri.DirectContent;
                         *      iTextSharp.text.pdf.Barcode128 bc = new Barcode128();
                         *      bc.TextAlignment = Element.ALIGN_LEFT;
                         *      bc.Code = S1.Text;
                         *      bc.StartStopText = false;
                         *      bc.CodeType = iTextSharp.text.pdf.Barcode128.EAN13;
                         *      bc.Extended = true;
                         *
                         *      iTextSharp.text.Image ru = iTextSharp.text.Image.GetInstance("ru.png");
                         *      ru.ScalePercent(15f);
                         *
                         *
                         *
                         *
                         *      iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                         *        iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);
                         *
                         *      cb.SetTextMatrix(100f, 150.5f);
                         *      img.ScaleToFit(150, 159);
                         *      img.SetAbsolutePosition(100f, 150f);
                         *      //     doc.Add(ru);
                         *      PdfPTable headerTable = new PdfPTable(2);
                         *      headerTable.TotalWidth = 530f;
                         *      headerTable.HorizontalAlignment = 0;
                         *      headerTable.SpacingAfter = 20;
                         *      //headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
                         *
                         *      float[] headerTableColWidth = new float[2];
                         *      headerTableColWidth[0] = 220f;
                         *      headerTableColWidth[1] = 310f;
                         *
                         *      headerTable.SetWidths(headerTableColWidth);
                         *      headerTable.LockedWidth = true;
                         *
                         *      PdfPCell headerTableCell_0 = new PdfPCell(ru);
                         *      headerTableCell_0.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      headerTableCell_0.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      headerTable.AddCell(headerTableCell_0);
                         *
                         *      PdfPCell head = new PdfPCell(new Phrase(70, "งานแพทย์และอนามัย มหาวิทยาลัยรามคำแหง\nบัตรประวัติผู้ป่วย", el.Font));
                         *
                         *      head.HorizontalAlignment = Element.ALIGN_LEFT;
                         *      head.VerticalAlignment = Element.ALIGN_BOTTOM;
                         *      head.Border = iTextSharp.text.Rectangle.NO_BORDER;
                         *      //       headerTable.AddCell(new PdfPCell(ru));
                         *      headerTable.AddCell(head);
                         *
                         *      doc.Add(headerTable);
                         *      //   Paragraph pa = new Paragraph(""+head+"");
                         *      //   doc.Add(pa);
                         *      PdfPTable table = new PdfPTable(1);
                         *      //  table.AddCell(new PdfPCell(ru));
                         *      table.AddCell(new PdfPCell(new Phrase(70, "ชื่อ " + S2.Text + "\nวันเดือนปีเกิด " + S3.Text + "\nอายุ" + emp_ru_age + " \nโทรศัพท์มือถือ " + S4.Text + "\n เบอร์โทรศัพท์บ้าน" + emp_ru_telhome + "\nเบอร์โทรผู้ปกครอง" + emp_ru_telparent + "\nที่อยู่ผู้ปกครอง" + em_ru_addressparent + "\nชื่อบิดา" + emp_ru_namedad + "\nชื่อมารดา" + emp_ru_namemom + "\nชื่อสามีหรือภรรยา" + emp_ru_namehusband_and_wife + "\nที่อยู่" + emp_ru_address + "\nสังกัด  " + S5.Text + "\nรหัสเข้าสู่ระบบ\nรหัสชื่อผู้ใช้ " + S1.Text + "\nรหัสผ่าน " + S3.Text + "", el.Font)));
                         *      table.AddCell(new PdfPCell(img));
                         *      //   table.AddCell(new Phrase(10, "" + S2.Text + "", el.Font));
                         *      // table.AddCell(img);
                         *      // table.AddCell(new Phrase(70, "รหัสเข้าสู่ระบบ", el.Font));
                         *      //  table.AddCell(new Phrase(70, "รหัสชื่อผู้ใช้ " + S1.Text + "", el.Font));
                         *      //  table.AddCell(new Phrase(10, "รหัสผ่าน" + S3.Text + "", el.Font));
                         *      doc.Add(table);
                         *      doc.Close();
                         *      System.Diagnostics.Process.Start("" + S2.Text + ".pdf");
                         *
                         *      clinic_approve_step2 appr2 = new clinic_approve_step2();
                         *      appr2.Show();
                         *      clinic_approve approve = new clinic_approve();
                         *      approve.Close();
                         *      Visible = false;
                         *
                         *  }
                         */
                    }


                    /*
                     * query = ("insert into opd (opd_name,opd_idcard,opd_birthday,opd_age,opd_telwork,opd_telmobile ,opd_telhome,emp_ru_telparent,emp_ru_nameparent,em_ru_addressparent,emp_ru_namedad,eru.emp_ru_namemom,emp_ru_namehusband_and_wife,emp_ru_address)"+
                     *  "values('"+emp_ru_name+" ','"+emp_ru_idcard+" ','"+emp_ru_birthday+" ','"+emp_ru_age+" ',"+
                     *  "'"+emp_ru_age+" ','"+emp_ru_telwork+" ','"+emp_ru_telmobile+" ','"+emp_ru_telhome+" ',"+
                     *  "'"+emp_ru_telparent+"','"+emp_ru_nameparent+" ','"+ em_ru_addressparent + " '"+
                     *  ",'"+ emp_ru_namedad + "','"+emp_ru_namemom+" ','"+ emp_ru_namehusband_and_wife + " ',"+
                     *  "'"+ emp_ru_address + "')");
                     * cmd = new SqlCommand(query, conn);
                     * sda = new SqlDataAdapter(cmd);
                     * dt = new DataTable();
                     * sda.Fill(dt);
                     *
                     */
                }
            }



            conn.Close();
        }
        public void Verify_Barcodes_CanBeCreated()
        {
            var pdfFilePath = TestUtils.GetOutputFileName();
            var stream      = new FileStream(pdfFilePath, FileMode.Create);

            // step 1
            var document = new Document(new Rectangle(340, 842));

            // step 2
            PdfWriter writer = PdfWriter.GetInstance(document, stream);

            // step 3
            document.AddAuthor(TestUtils.Author);
            document.Open();
            // step 4
            PdfContentByte cb = writer.DirectContent;

            // EAN 13
            document.Add(new Paragraph("Barcode EAN.UCC-13"));
            BarcodeEan codeEan = new BarcodeEan {
                Code = "4512345678906"
            };

            document.Add(new Paragraph("default:"));
            document.Add(codeEan.CreateImageWithBarcode(cb, null, null));
            codeEan.GuardBars = false;
            document.Add(new Paragraph("without guard bars:"));
            document.Add(codeEan.CreateImageWithBarcode(cb, null, null));
            codeEan.Baseline  = -1f;
            codeEan.GuardBars = true;
            document.Add(new Paragraph("text above:"));
            document.Add(codeEan.CreateImageWithBarcode(cb, null, null));
            codeEan.Baseline = codeEan.Size;

            // UPC A
            document.Add(new Paragraph("Barcode UCC-12 (UPC-A)"));
            codeEan.CodeType = Barcode.UPCA;
            codeEan.Code     = "785342304749";
            document.Add(codeEan.CreateImageWithBarcode(cb, null, null));

            // EAN 8
            document.Add(new Paragraph("Barcode EAN.UCC-8"));
            codeEan.CodeType  = Barcode.EAN8;
            codeEan.BarHeight = codeEan.Size * 1.5f;
            codeEan.Code      = "34569870";
            document.Add(codeEan.CreateImageWithBarcode(cb, null, null));

            // UPC E
            document.Add(new Paragraph("Barcode UPC-E"));
            codeEan.CodeType = Barcode.UPCE;
            codeEan.Code     = "03456781";
            document.Add(codeEan.CreateImageWithBarcode(cb, null, null));
            codeEan.BarHeight = codeEan.Size * 3f;

            // EANSUPP
            document.Add(new Paragraph("Bookland"));
            document.Add(new Paragraph("ISBN 0-321-30474-8"));
            codeEan.CodeType = Barcode.EAN13;
            codeEan.Code     = "9781935182610";
            BarcodeEan codeSupp = new BarcodeEan
            {
                CodeType = Barcode.SUPP5,
                Code     = "55999",
                Baseline = -2
            };
            BarcodeEansupp eanSupp = new BarcodeEansupp(codeEan, codeSupp);

            document.Add(eanSupp.CreateImageWithBarcode(cb, null, BaseColor.Blue));

            // CODE 128
            document.Add(new Paragraph("Barcode 128"));
            Barcode128 code128 = new Barcode128 {
                Code = "0123456789 hello"
            };

            document.Add(code128.CreateImageWithBarcode(cb, null, null));
            code128.Code     = "0123456789\uffffMy Raw Barcode (0 - 9)";
            code128.CodeType = Barcode.CODE128_RAW;
            document.Add(code128.CreateImageWithBarcode(cb, null, null));

            // Data for the barcode :
            string        code402 = "24132399420058289";
            string        code90  = "3700000050";
            string        code421 = "422356";
            StringBuilder data    = new StringBuilder(code402);

            data.Append(Barcode128.FNC1);
            data.Append(code90);
            data.Append(Barcode128.FNC1);
            data.Append(code421);
            Barcode128 shipBarCode = new Barcode128
            {
                X             = 0.75f,
                N             = 1.5f,
                Size          = 10f,
                TextAlignment = Element.ALIGN_CENTER,
                Baseline      = 10f,
                BarHeight     = 50f,
                Code          = data.ToString()
            };

            document.Add(shipBarCode.CreateImageWithBarcode(
                             cb, BaseColor.Black, BaseColor.Blue
                             ));

            // it is composed of 3 blocks whith AI 01, 3101 and 10
            Barcode128 uccEan128 = new Barcode128
            {
                CodeType = Barcode.CODE128_UCC,
                Code     = "(01)00000090311314(10)ABC123(15)060916"
            };

            document.Add(uccEan128.CreateImageWithBarcode(
                             cb, BaseColor.Blue, BaseColor.Black
                             ));
            uccEan128.Code = "0191234567890121310100035510ABC123";
            document.Add(uccEan128.CreateImageWithBarcode(
                             cb, BaseColor.Blue, BaseColor.Red
                             ));
            uccEan128.Code = "(01)28880123456788";
            document.Add(uccEan128.CreateImageWithBarcode(
                             cb, BaseColor.Blue, BaseColor.Black
                             ));

            // INTER25
            document.Add(new Paragraph("Barcode Interleaved 2 of 5"));
            BarcodeInter25 code25 = new BarcodeInter25
            {
                GenerateChecksum = true,
                Code             = "41-1200076041-001"
            };

            document.Add(code25.CreateImageWithBarcode(cb, null, null));
            code25.Code = "411200076041001";
            document.Add(code25.CreateImageWithBarcode(cb, null, null));
            code25.Code         = "0611012345678";
            code25.ChecksumText = true;
            document.Add(code25.CreateImageWithBarcode(cb, null, null));

            // POSTNET
            document.Add(new Paragraph("Barcode Postnet"));
            BarcodePostnet codePost = new BarcodePostnet();

            document.Add(new Paragraph("ZIP"));
            codePost.Code = "01234";
            document.Add(codePost.CreateImageWithBarcode(cb, null, null));
            document.Add(new Paragraph("ZIP+4"));
            codePost.Code = "012345678";
            document.Add(codePost.CreateImageWithBarcode(cb, null, null));
            document.Add(new Paragraph("ZIP+4 and dp"));
            codePost.Code = "01234567890";
            document.Add(codePost.CreateImageWithBarcode(cb, null, null));

            document.Add(new Paragraph("Barcode Planet"));
            BarcodePostnet codePlanet = new BarcodePostnet
            {
                Code     = "01234567890",
                CodeType = Barcode.PLANET
            };

            document.Add(codePlanet.CreateImageWithBarcode(cb, null, null));

            // CODE 39
            document.Add(new Paragraph("Barcode 3 of 9"));
            Barcode39 code39 = new Barcode39 {
                Code = "ITEXT IN ACTION"
            };

            document.Add(code39.CreateImageWithBarcode(cb, null, null));

            document.Add(new Paragraph("Barcode 3 of 9 extended"));
            Barcode39 code39Ext = new Barcode39
            {
                Code          = "iText in Action",
                StartStopText = false,
                Extended      = true
            };

            document.Add(code39Ext.CreateImageWithBarcode(cb, null, null));

            // CODABAR
            document.Add(new Paragraph("Codabar"));
            BarcodeCodabar codabar = new BarcodeCodabar
            {
                Code          = "A123A",
                StartStopText = true
            };

            document.Add(codabar.CreateImageWithBarcode(cb, null, null));

            // PDF417
            document.Add(new Paragraph("Barcode PDF417"));
            BarcodePdf417 pdf417 = new BarcodePdf417();
            string        text   = "Call me Ishmael. Some years ago--never mind how long "
                                   + "precisely --having little or no money in my purse, and nothing "
                                   + "particular to interest me on shore, I thought I would sail about "
                                   + "a little and see the watery part of the world."
            ;

            pdf417.SetText(text);
            Image img = pdf417.GetImage();

            img.ScalePercent(50, 50 * pdf417.YHeight);
            document.Add(img);

            document.Add(new Paragraph("Barcode Datamatrix"));
            BarcodeDatamatrix datamatrix = new BarcodeDatamatrix();

            datamatrix.Generate(text);
            img = datamatrix.CreateImage();
            document.Add(img);

            document.Close();
            stream.Dispose();

            TestUtils.VerifyPdfFileIsReadable(pdfFilePath);
        }
    public void createTable_NEW(string FileName, int spl_id, string id_1)
    {
        var r = new Rectangle(220, 144)
        {
            //BackgroundColor=new BaseColor(179,227,238), remove this in original code
            Border = 0
        };
        Document dc = new Document(r, 0, 0, 0, 0);
        // PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + spl_id + ".pdf", FileMode.Create));

        PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create));

        dc.Open();
        // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
        BaseFont customfont = BaseFont.CreateFont();
        int      a          = spl_id;
        //string connectionString = "Data Source=ALRAR;Persist Security Info=True;User ID=AMOGH;Password=ALRAR2020;Unicode=True";
        OracleConnection conn = WebTools.GetIpmsConnection();
        // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id;

        string query = "SELECT mat_code1,heat_no,nvl(paint_code,'NA')  as paint_code,wall_thk,joint_thk,size1,nvl(mat_type,'XXX') as mat_type,substr(mat_descr,1,100) AS mat_descr, SubStr(mat_descr,101,100) AS mat_descr2, SubStr(mat_descr,201,100) AS mat_descr3 FROM  view_bulk_paint_barcode WHERE spl_id=" + spl_id;


        OracleCommand cmd = new OracleCommand(query, conn);

        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        OracleDataReader rdr = cmd.ExecuteReader();
        // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL);
        Font bigFont      = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 8, Font.BOLD, BaseColor.BLACK);
        Font smallFont    = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK);
        Font mediumFont   = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 6, Font.BOLD, BaseColor.BLACK);
        Font mediumFont_a = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 4, Font.BOLD, BaseColor.BLACK);
        Font headfont     = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD);

        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
        Barcode128 bc = new Barcode128();

        bc.ChecksumText = true;
        bc.Code         = a.ToString().PadLeft(16, '0');
        bc.Size         = 4;
        bc.BarHeight    = 15;
        bc.Baseline     = 4;
        PdfPTable table = new PdfPTable(2);

        // table.SetWidths(new float[]{158,68});
        table.SetWidthPercentage(new float[] { 100, 100 }, r);
        table.SetWidths(new float[] { 145, 80 });
        table.DefaultCell.Border = Rectangle.NO_BORDER;
        table.DefaultCell.NoWrap = true;
        // PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh"));
        PdfPCell cell = new PdfPCell(new Paragraph("Job: PSJV/JI-2037", headfont));

        cell.Colspan             = 2;
        cell.Rowspan             = 4;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        cell.Border  = 0;
        cell.Padding = 4;
        table.AddCell(cell);
        cell                     = new PdfPCell();
        cell.Image               = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null));
        cell.Colspan             = 2;
        cell.Border              = 0;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell);
        rdr.Read();

        //table.AddCell(new Paragraph("Item code:" + rdr[0].ToString(), smallFont));
        //table.AddCell(new Paragraph("Paint Code:" + rdr[2].ToString(), bigFont));
        //table.AddCell(new Paragraph("Heat No:" + rdr[1].ToString(), bigFont));
        //table.AddCell(new Paragraph("Sch & Thk:" + rdr[3].ToString() + " & " + rdr[4].ToString(), bigFont));
        //table.AddCell(new Paragraph("Pipe-Size:" + rdr[5].ToString(), bigFont));
        //table.AddCell(new Paragraph("Main-Mat:" + rdr[6].ToString(), bigFont));
        //table.AddCell(new Paragraph("Pipe-Description:" + rdr[7].ToString(), bigFont));

        table.AddCell(new Paragraph("Item code:" + rdr[0].ToString(), mediumFont));
        table.AddCell(new Paragraph("Paint Code:" + rdr[2].ToString(), mediumFont));
        table.AddCell(new Paragraph("Heat No:" + rdr[1].ToString(), mediumFont));
        table.AddCell(new Paragraph("Sch & Thk:" + rdr[3].ToString() + " & " + rdr[4].ToString(), mediumFont));
        table.AddCell(new Paragraph("Pipe-Size:" + rdr[5].ToString(), mediumFont));
        table.AddCell(new Paragraph("Main-Mat:" + rdr[6].ToString(), mediumFont));
        table.AddCell(new Paragraph("Pipe-Description:" + rdr[7].ToString(), mediumFont_a));
        table.AddCell(new Paragraph(rdr[8].ToString(), mediumFont_a));
        table.AddCell(new Paragraph(rdr[9].ToString(), mediumFont_a));



        //table.AddCell(new Paragraph("Mat:" + rdr[7].ToString(), bigFont));
        //table.AddCell(new Paragraph("Line:" + rdr[8].ToString(), bigFont));
        table.AddCell("");
        //NEW  CONDITION
        rdr.Close();
        //END
        conn.Close();
        dc.Add(table);
        dc.Close();
    }
    public void createTable(string FileName, int mat_id, string id_1)
    {
        //72 point =1 inch
        //
        // var r = new iTextSharp.text.Rectangle(220, 144)
        var r = new iTextSharp.text.Rectangle(144, 72)
        {
            //BackgroundColor=new BaseColor(179,227,238), remove this in original code
            Border = 0
        };
        Document dc = new Document(r, 0, 0, 0, 0);
        // PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + spl_id + ".pdf", FileMode.Create));

        PdfWriter writer = PdfWriter.GetInstance(dc, new FileStream(HttpContext.Current.Request.PhysicalApplicationPath + FileName + "/" + id_1 + ".pdf", FileMode.Create));

        dc.Open();
        // BaseFont customfont = BaseFont.CreateFont("d:\\ss.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
        BaseFont customfont = BaseFont.CreateFont();
        int      a          = mat_id;
        //string connectionString = "Data Source=ALRAR;Persist Security Info=True;User ID=AMOGH;Password=ALRAR2020;Unicode=True";
        OracleConnection conn = WebTools.GetIpmsConnection();
        // string query = "SELECT iso_title1,spl_rev,spool,round(spl_size,2) as spl_size ,area_l1,round(weight,2),mat_type,line_no,unit FROM view_total_spool_list WHERE spl_id=" + spl_id;
        string        query = "SELECT mat_code1,mat_code2,size_desc,THK1, ITEM_NAM FROM view_stock WHERE mat_id=" + mat_id;
        OracleCommand cmd   = new OracleCommand(query, conn);

        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        OracleDataReader rdr = cmd.ExecuteReader();
        // Font bigFont = new Font(Font.FontFamily.TIMES_ROMAN, 6.5f, Font.NORMAL);
        Font bigFont   = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 8, Font.BOLD, BaseColor.BLACK);
        Font smallFont = FontFactory.GetFont("Calibri", BaseFont.CP1252, BaseFont.EMBEDDED, 7, Font.BOLD, BaseColor.BLACK);
        Font headfont  = new Font(Font.FontFamily.COURIER, 14f, Font.BOLD);

        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
        Barcode128 bc = new Barcode128();

        bc.ChecksumText = true;
        bc.Code         = a.ToString().PadLeft(16, '0');
        bc.Size         = 4;
        bc.BarHeight    = 25;

        bc.Baseline = 4;



        PdfPTable table = new PdfPTable(2);

        // table.SetWidths(new float[]{158,68});
        table.SetWidthPercentage(new float[] { 100, 100 }, r);
        table.SetWidths(new float[] { 144, 72 });
        table.DefaultCell.Border = Rectangle.NO_BORDER;
        table.DefaultCell.NoWrap = true;

        // PdfPCell cell = new PdfPCell(new Paragraph("Petrofac / Rabigh"));
        PdfPCell cell = new PdfPCell(new Paragraph());

        cell.Colspan             = 2;
        cell.Rowspan             = 4;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        cell.Border  = 0;
        cell.Padding = 4;
        table.AddCell(cell);
        cell = new PdfPCell();
        //cell.Image = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null));
        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bc.CreateImageWithBarcode(cb, null, null));
        img.ScaleToFit(r);
        cell.Colspan             = 2;
        cell.Border              = 0;
        cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
        table.AddCell(cell);
        rdr.Read();
        table.AddCell(new Paragraph("Mat Code1:" + rdr[0].ToString(), smallFont));
        //    table.AddCell(new Paragraph("MESC Code:" + rdr[1].ToString(), bigFont));
        //    table.AddCell(new Paragraph("Size:" + rdr[2].ToString(), bigFont));
        //    table.AddCell(new Paragraph("Thk/Sch:" + rdr[3].ToString(), bigFont));
        //    table.AddCell(new Paragraph("Description:" + rdr[4].ToString(), bigFont));
        table.AddCell("");
        //NEW  CONDITION
        rdr.Close();
        //END
        conn.Close();
        dc.Add(img);
        dc.Close();

        Response.Write(bc.BarcodeSize.ToString());
    }
Esempio n. 21
0
        /// <summary>
        /// ExportToThermalPrinter
        /// </summary>
        public void ExportToPDFforThermalPrinter()
        {
            iTextSharp.text.Document pdfdoc = new iTextSharp.text.Document();
            try
            {
                DirectoryInfo dir1 = new DirectoryInfo(Application.StartupPath + "\\Barcode");
                if (!Directory.Exists(Application.StartupPath + "\\Barcode"))
                {
                    dir1.Create();
                }
                if (File.Exists(Application.StartupPath + "\\Barcode\\Barcode.pdf"))
                {
                    File.Delete(Application.StartupPath + "\\Barcode\\Barcode.pdf");
                }
                iTextSharp.text.Rectangle pgSize = new iTextSharp.text.Rectangle(227, 65);
                pdfdoc = new Document(pgSize, 6, 6, 0, 0);
                PdfWriter writer         = PdfWriter.GetInstance(pdfdoc, new FileStream(Application.StartupPath + "\\Barcode\\Barcode.pdf", FileMode.Create));
                PdfPTable tbl            = new PdfPTable(2);
                float[]   fltParentWidth = new float[] { 108f, 108f };
                tbl.TotalWidth  = 216;
                tbl.LockedWidth = true;
                tbl.SetWidths(fltParentWidth);
                tbl.DefaultCell.FixedHeight         = 57;
                tbl.DefaultCell.Border              = iTextSharp.text.Rectangle.NO_BORDER;
                tbl.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                tbl.DefaultCell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                pdfdoc.Open();
                int intotalCount         = 0;
                BarcodeSettingsInfo Info = new BarcodeSettingsInfo();
                SettingsSP          Sp   = new SettingsSP();
                Info = spBarcodeSettings.BarcodeSettingsViewForBarCodePrinting();
                for (int i = 0; i < dgvBarcodePrinting.Rows.Count; i++)
                {
                    if (dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value != null && dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value.ToString() != string.Empty)
                    {
                        int inCopies = 0;
                        if (dgvBarcodePrinting.Rows[i].Cells["dgvCopies"].Value != null)
                        {
                            int.TryParse(dgvBarcodePrinting.Rows[i].Cells["dgvCopies"].Value.ToString(), out inCopies);
                        }
                        for (int j = 0; j < inCopies; j++)
                        {
                            string strCode        = dgvBarcodePrinting.Rows[i].Cells["dgvProductCode"].Value.ToString();
                            string strCompanyName = string.Empty;
                            if (Info.ShowCompanyName)
                            {
                                strCompanyName = Info.CompanyName;
                            }
                            string strProductCode = string.Empty;
                            if (Info.ShowProductCode)
                            {
                                strProductCode = strCode;
                            }
                            else
                            {
                                strProductCode = dgvBarcodePrinting.Rows[i].Cells["dgvproductName"].Value.ToString();
                            }

                            string strMRP = string.Empty;
                            if (Info.ShowMRP)
                            {
                                strMRP = new CurrencySP().CurrencyView(PublicVariables._decCurrencyId).CurrencySymbol + ": " + dgvBarcodePrinting.Rows[i].Cells["dgvMRP"].Value.ToString();
                            }

                            string strSecretPurchaseRateCode = string.Empty;
                            if (Info.ShowPurchaseRate)
                            {
                                string strPurchaseRate = dgvBarcodePrinting.Rows[i].Cells["dgvPurchaseRate"].Value.ToString();

                                if (strPurchaseRate.Contains("."))
                                {
                                    strPurchaseRate = strPurchaseRate.TrimEnd('0');
                                    if (strPurchaseRate[strPurchaseRate.Length - 1] == '.')
                                    {
                                        strPurchaseRate = strPurchaseRate.Replace(".", "");
                                    }
                                }
                                for (int k = 0; k < strPurchaseRate.Length; k++)
                                {
                                    switch (strPurchaseRate[k])
                                    {
                                    case '0':
                                        strSecretPurchaseRateCode += Info.Zero;
                                        break;

                                    case '1':
                                        strSecretPurchaseRateCode += Info.One;
                                        break;

                                    case '2':
                                        strSecretPurchaseRateCode += Info.Two;
                                        break;

                                    case '3':
                                        strSecretPurchaseRateCode += Info.Three;
                                        break;

                                    case '4':
                                        strSecretPurchaseRateCode += Info.Four;
                                        break;

                                    case '5':
                                        strSecretPurchaseRateCode += Info.Five;
                                        break;

                                    case '6':
                                        strSecretPurchaseRateCode += Info.Six;
                                        break;

                                    case '7':
                                        strSecretPurchaseRateCode += Info.Seven;
                                        break;

                                    case '8':
                                        strSecretPurchaseRateCode += Info.Eight;
                                        break;

                                    case '9':
                                        strSecretPurchaseRateCode += Info.Nine;
                                        break;

                                    case '.':
                                        strSecretPurchaseRateCode += Info.Point;
                                        break;
                                    }
                                }
                            }

                            PdfContentByte pdfcb   = writer.DirectContent;
                            Barcode128     code128 = new Barcode128();
                            code128.Code          = strCode;
                            code128.Extended      = false;
                            code128.CodeType      = iTextSharp.text.pdf.Barcode.CODE128;
                            code128.AltText       = strProductCode;
                            code128.BarHeight     = 16;
                            code128.Size          = 9;
                            code128.Baseline      = 9;
                            code128.TextAlignment = Element.ALIGN_CENTER;
                            iTextSharp.text.Image image128 = code128.CreateImageWithBarcode(pdfcb, null, null);
                            Phrase phrase = new Phrase();

                            phrase.Add(new Chunk(strCompanyName, new iTextSharp.text.Font(-1, 9, iTextSharp.text.Font.BOLD)));
                            phrase.Add(new Chunk(Environment.NewLine + Environment.NewLine, new iTextSharp.text.Font(-1, 4)));
                            PdfPCell cell = new PdfPCell(phrase);
                            cell.HorizontalAlignment = Element.ALIGN_CENTER;
                            cell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            cell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                            phrase.Add(new Chunk(image128, 0, 0));
                            phrase.Add(new Chunk(Environment.NewLine, new iTextSharp.text.Font(-1, 4)));
                            phrase.Add(new Chunk(strMRP, new iTextSharp.text.Font(-1, 8)));
                            phrase.Add(new Chunk(Environment.NewLine + strSecretPurchaseRateCode, new iTextSharp.text.Font(-1, 7)));
                            phrase.Add(new Chunk(Environment.NewLine + Environment.NewLine, new iTextSharp.text.Font(-1, 1.2f)));
                            tbl.AddCell(cell);
                            intotalCount++;
                        }
                    }
                }
                int reminder = intotalCount % 2;
                if (reminder != 0)
                {
                    for (int i = reminder; i < 2; ++i)
                    {
                        tbl.AddCell("");
                    }
                }
                if (tbl.Rows.Count != 0)
                {
                    pdfdoc.Add(tbl);
                    pdfdoc.Close();
                    System.Diagnostics.Process.Start(Application.StartupPath + "\\Barcode\\Barcode.pdf");
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("The process cannot access the file") && ex.Message.Contains("Barcode.pdf' because it is being used by another process."))
                {
                    MessageBox.Show("Close the PDF file and try again", "Oneaccount", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    formMDI.infoError.ErrorString = "BCP5:" + ex.Message;
                }
            }
            finally
            {
                try
                {
                    pdfdoc.Close();
                }
                catch
                {
                }
            }
        }
Esempio n. 22
0
        private void btnPrintSticker_Click(object sender, EventArgs e)
        {
            if (ExamVedId == null)
            {
                return;
            }

            if (MainClass.IsOwner() || MainClass.IsCrypto() || MainClass.IsPasha() || MainClass.IsCryptoMain())
            {
                FileStream fileS    = null;
                string     savePath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Sticker.pdf";

                float fontsize = 8;

                try
                {
                    using (PriemEntities context = new PriemEntities())
                    {
                        Document document = new Document(PageSize.A4, 50, 50, 50, 50);
                        document.SetMargins(18, 18, 36, 5);

                        using (fileS = new FileStream(savePath, FileMode.Create))
                        {
                            BaseFont             bfTimes = BaseFont.CreateFont(string.Format(@"{0}\times.ttf", MainClass.dirTemplates), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                            iTextSharp.text.Font font    = new iTextSharp.text.Font(bfTimes, 10);

                            PdfWriter pw = PdfWriter.GetInstance(document, fileS);
                            document.Open();

                            int cntCells = 2;
                            int.TryParse(tbCountCell.Text.Trim(), out cntCells);

                            string examId;
                            string examName;
                            string examDate;
                            string facId;
                            string vedNumber;

                            extExamsVed ved = (from ev in context.extExamsVed
                                               where ev.Id == ExamVedId
                                               select ev).FirstOrDefault();

                            examId    = ved.ExamId.ToString();
                            examName  = ved.ExamName.ToString();
                            examDate  = ved.Date.ToShortDateString();
                            vedNumber = ved.Number.ToString();
                            facId     = FacultyId.ToString();

                            DataSet dsPersons = bdc.GetDataSet(string.Format("SELECT DISTINCT ed.extPerson.Id, ed.extPerson.PersonNum as RegNum, ed.extPerson.FIO, ed.ExamsVedHistory.PersonVedNumber " +
                                                                             "FROM ed.extPerson LEFT JOIN ed.ExamsVedHistory ON ed.ExamsVedHistory.PersonId = ed.extPerson.Id WHERE ed.ExamsVedHistory.ExamsVedId = '{0}' ORDER BY FIO ", ExamVedId.ToString()));

                            PdfPTable t            = new PdfPTable(3);
                            float     pgW          = (PageSize.A4.Width - 36) / 3;
                            float[]   headerwidths = { pgW, pgW, pgW };
                            t.SetWidths(headerwidths);
                            t.WidthPercentage           = 100f;
                            t.SpacingBefore             = 10f;
                            t.SpacingAfter              = 10f;
                            t.DefaultCell.MinimumHeight = 120;

                            int cellsNum = (dsPersons.Tables[0].Rows.Count) * (cntCells + 1);
                            int ost      = cellsNum % 3;

                            foreach (DataRow drr in dsPersons.Tables[0].Rows)
                            {
                                string text = drr["FIO"].ToString() + "\n" + drr["RegNum"].ToString() + " " + facId + "\n";
                                text += examDate + " " + examName;

                                Barcode128 barcode1 = new Barcode128();
                                barcode1.Code = vedNumber + "==" + drr["PersonVedNumber"].ToString() + "-";

                                Barcode128 barcode2 = new Barcode128();
                                barcode2.Code = vedNumber + "==" + drr["PersonVedNumber"].ToString() + "-";

                                PdfContentByte        cb   = pw.DirectContent;
                                iTextSharp.text.Image img1 = barcode1.CreateImageWithBarcode(cb, null, null);
                                img1.ScaleAbsolute(80f, 60f);

                                iTextSharp.text.Image img2 = barcode2.CreateImageWithBarcode(cb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.WHITE);
                                img2.ScaleAbsolute(80f, 60f);


                                PdfPTable ptPl = new PdfPTable(1);
                                float[]   hwh  = { pgW };
                                ptPl.SetWidthPercentage(hwh, PageSize.A4);

                                PdfPCell clPlText = new PdfPCell(new Phrase(text, new iTextSharp.text.Font(bfTimes, fontsize)));
                                clPlText.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_CENTER;
                                clPlText.PaddingBottom       = 2;
                                clPlText.PaddingTop          = 2;
                                clPlText.Border = iTextSharp.text.Rectangle.NO_BORDER;

                                PdfPCell clPlBarc = new PdfPCell();
                                clPlBarc.AddElement(img1);
                                clPlBarc.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_CENTER;
                                clPlBarc.PaddingTop          = 1;
                                clPlBarc.PaddingLeft         = 40;
                                clPlBarc.Border = iTextSharp.text.Rectangle.NO_BORDER;

                                ptPl.AddCell(clPlText);
                                ptPl.AddCell(clPlBarc);

                                PdfPCell pcell = new PdfPCell(ptPl);
                                pcell.PaddingTop    = 6;
                                pcell.PaddingBottom = 6;
                                pcell.PaddingLeft   = 6;
                                pcell.PaddingRight  = 6;
                                pcell.FixedHeight   = 100;
                                pcell.Border        = iTextSharp.text.Rectangle.NO_BORDER;

                                t.AddCell(pcell);

                                PdfPCell pcell1;
                                for (int i = 0; i < cntCells; i++)
                                {
                                    ptPl = new PdfPTable(1);
                                    ptPl.SetWidthPercentage(hwh, PageSize.A4);

                                    clPlText = new PdfPCell();
                                    clPlText.AddElement(img2);
                                    clPlText.PaddingLeft  = 40;
                                    clPlText.PaddingRight = 40;
                                    clPlText.PaddingTop   = 20;
                                    clPlText.Border       = iTextSharp.text.Rectangle.NO_BORDER;

                                    clPlBarc = new PdfPCell(new Phrase((i + 1).ToString(), new iTextSharp.text.Font(bfTimes, fontsize)));
                                    clPlBarc.HorizontalAlignment = iTextSharp.text.Rectangle.ALIGN_CENTER;
                                    clPlBarc.PaddingTop          = 1;
                                    clPlBarc.Border = iTextSharp.text.Rectangle.NO_BORDER;

                                    ptPl.AddCell(clPlText);
                                    ptPl.AddCell(clPlBarc);

                                    pcell1             = new PdfPCell(ptPl);
                                    pcell1.FixedHeight = 100;
                                    pcell1.Border      = iTextSharp.text.Rectangle.NO_BORDER;
                                    t.AddCell(pcell1);
                                }
                            }

                            for (int i = 0; i < 3 - ost; i++)
                            {
                                PdfPCell pc = new PdfPCell();
                                pc.Border = iTextSharp.text.Rectangle.NO_BORDER;
                                t.AddCell(pc);
                            }

                            if (t != null)
                            {
                                document.Add(t);
                            }

                            document.Close();

                            Process pr = new Process();

                            pr.StartInfo.Verb     = "Print";
                            pr.StartInfo.FileName = string.Format(savePath);
                            pr.Start();

                            pr.Close();
                        }
                    }
                }

                catch (Exception exc)
                {
                    WinFormsServ.Error(exc.Message);
                }
                finally
                {
                    if (fileS != null)
                    {
                        fileS.Dispose();
                    }
                }
            }

            else
            {
                WinFormsServ.Error("Невозможно создание наклеек, недостаточно прав");
            }
        }
Esempio n. 23
0
        public byte[] Build()
        {
            Validate();

            Document  document = new Document(_pageSize, _sheetMargin.Left, _sheetMargin.Right, _sheetMargin.Top, _sheetMargin.Bottom);
            PdfPTable table    = new PdfPTable(_column);

            table.TotalWidth          = _pageSize.Width;
            table.LockedWidth         = true;
            table.HorizontalAlignment = 1;

            table.SetWidths(_columnPercentWidth);

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                PdfWriter writer = PdfWriter.GetInstance(document, ms);
                document.Open();

                float rowHeight = ((_pageSize.Height - (_sheetMargin.Top + _sheetMargin.Bottom)) / (float)_row) - 0.001f;
                float barHeight = ((rowHeight - (_callPadding * 2)) * (_barcodeHeight / 100f)) / 2f;

                foreach (string code in _codes)
                {
                    Barcode128 code128 = new Barcode128();
                    code128.GenerateChecksum = true;
                    if (!_withBarcodeText)
                    {
                        code128.Font = null;
                    }

                    PdfPCell cell = new PdfPCell();
                    cell.FixedHeight = rowHeight;
                    if (!_withBorder)
                    {
                        cell.Border = PdfPCell.NO_BORDER;
                    }

                    cell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;
                    cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
                    cell.Padding             = _callPadding;

                    if (!code.Equals(""))
                    {
                        code128.Code = code;
                        if (_barcodeHeight > 0)
                        {
                            code128.BarHeight = barHeight;
                        }
                        code128.X = 1;
                        Image img = code128.CreateImageWithBarcode(writer.DirectContent, null, null);
                        cell.AddElement(img);
                    }

                    table.AddCell(cell);
                }

                document.Add(table);
                document.Close();

                byte[] pdf = ms.ToArray();
                if (_filePath != null)
                {
                    SaveToFile(_filePath, pdf);
                }

                return(pdf);
            }
        }
Esempio n. 24
0
    public byte[] AgregarImagenAPDF(byte[] bytes, String codigoBarras)
    {
        PdfReader    reader  = null;
        FileStream   fs      = null;
        MemoryStream ms      = null;
        PdfStamper   stamper = null;

        try
        {
            // agrego la imagen en una capa separada
            //creo el objeto reader para leer el documento pdf
            reader = new PdfReader(bytes);
            ms     = new MemoryStream();
            //creo el objeto stamper para escribir datos desde el objeto pdfreader al objeto memorystream/filestream
            stamper = new PdfStamper(reader, ms);


            // creo una nueva capa
            PdfLayer layer = new PdfLayer("Foto", stamper.Writer);

            // Getting the Page Size
            //Rectangle rect = reader.GetPageSize(i);

            // obtengo el objeto ContentByte de la pagina i
            //          int i = 1;

            int total = reader.NumberOfPages + 1;
            for (int i = 1; i < total; i++)
            {
                //PdfContentByte cb = stamper.GetOverContent(i);//;GetUnderContent(i);
                PdfContentByte cb = stamper.GetOverContent(i);

                //Le indico al cb que los proximos comandos  seran ligados a esta nueva capa
                cb.BeginLayer(layer);
                //           cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 50);

                /* esto es para que aparezca ser una marca de agua
                 */
                /* PdfGState gState = new PdfGState();
                 * gState.FillOpacity = 0.25f;
                 * cb.SetGState(gState);*/

                // cb.SetColorFill(BaseColor.BLACK);

                /* cb.BeginText();
                 * cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, watermarkText, rect.Width / 2, rect.Height / 2, 45f);
                 * cb.EndText();*/

                // Creamos la imagen y le ajustamos el tamaño
                //iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(rutaFoto);
                //iTextSharp.text.Image imagen = iTextSharp.text.Image.GetInstance(bytes_img);

                Barcode128 bc128 = new Barcode128();
                bc128.Code = codigoBarras;
                bc128.Font = null;
                Image imagen = bc128.CreateImageWithBarcode(cb, null, null);


                imagen.BorderWidth = 0;
                imagen.Alignment   = Element.ALIGN_TOP;
                float percentage = 0.0f;
                percentage = 150 / imagen.Width;
                imagen.ScaleAbsolute(1.0f, 1.0f);     //mismo tamaño
                imagen.ScalePercent(percentage * 85); //escalo a un 85%
                //imagen.ScalePercent(100.0f); // 100.0f == same size
                imagen.SetAbsolutePosition(360, 690);

                cb.AddImage(imagen);
                ///aggrego la capa que hace la imagen redonda
                //                   iTextSharp.text.Image imagen2 = iTextSharp.text.Image.GetInstance("c:/oie_trans_redim.gif");
                //iTextSharp.text.Image imagen2 = iTextSharp.text.Image.GetInstance("c:/oie_trans2.gif");
                //                   imagen2.BorderWidth = 0;
                //                   imagen2.Alignment = Element.ALIGN_TOP;
                //                   float percentage2 = 0.0f;
                //                   percentage2 = 150 / imagen2.Width;
                //                   imagen2.ScaleAbsolute(1.0f, 1.0f);//mismo tamaño
                //imagen.ScalePercent(percentage2 * 100);
                //                   imagen2.ScalePercent(100.0f); // 100.0f == same size
                //                   imagen2.SetAbsolutePosition(483, 708);

                // cb.AddImage(imagen2);

                // Close the layer
                cb.EndLayer();
                //               }
            }
            int    length = Convert.ToInt32(ms.Length);
            byte[] data   = new byte[length];
            ms.Read(data, 0, length);

            //                stamper.FormFlattening = true;//para que no se pueda editar el pdf generado
            stamper.Close(); //cierro el pdf
            reader.Close();
            ms.Close();

            byte[] Bytes = ms.ToArray();

            return(Bytes);
        }
        finally
        {
            // Garantizamos que aunque falle se cierran los objetos

            // alternativa:usar using

            reader.Close();

            if (stamper != null)
            {
                stamper.Close();
            }

            if (fs != null)
            {
                fs.Close();
            }

            /* if (document != null) document.Close();*/
        }
    }
    /// <summary>
    /// output barcodes for asn
    /// </summary>
    /// <param name="consignmentid"></param>
    /// <returns></returns>
    public static string output_barcodes_pdf(string consignmentref, int consignmentid)
    {
        //for a custom httphandler make sure it's referenced in web.config in httpHandlers
        //<add verb="GET" path="*barcode.gif" type="barcode_handler" validate ="false" />
        //
        string   _msg  = "";             //message returned blank if successful else error message
        float    _ypos = 0;              //horizontal position
        int      _ppg  = 4;              //items per page
        Document _doc  = new Document(); //itextsharp document

        try
        {
            //get all pallet identifiers for this consignment
            string[]  _cols = { "despatch_note_id", "publiship_ref", "title", "sscc" };
            DataTable _dt   = DAL.Logistics.DB.Select(_cols).From(DAL.Logistics.Tables.DespatchNotePalletId).
                              LeftOuterJoin(DAL.Logistics.DespatchNoteItem.ItemIdColumn, DAL.Logistics.DespatchNotePalletId.DespatchItemIdColumn).
                              Where(DAL.Logistics.DespatchNoteItem.DespatchNoteIdColumn).IsEqualTo(consignmentid).ExecuteDataSet().Tables[0];

            //open memeroary stream
            System.IO.MemoryStream _mem = new System.IO.MemoryStream();
            //create instance of itextsharp pdf writer
            PdfWriter _pdf = PdfWriter.GetInstance(_doc, _mem);
            _doc.Open();
            _pdf.Open();

            //build table
            //PdfPTable _tbl = new PdfPTable(1);
            //_tbl.DefaultCell.Border  = iTextSharp.text.Rectangle.NO_BORDER;
            //hide all borders except bottom which acts as line seperator
            //_tbl.DefaultCell.BorderWidthTop = 0;
            //_tbl.DefaultCell.BorderWidthLeft = 0;
            //_tbl.DefaultCell.BorderWidthRight = 0;
            //_tbl.DefaultCell.BorderColorBottom  = BaseColor.LIGHT_GRAY;
            //_tbl.DefaultCell.PaddingTop = 10;
            //_tbl.DefaultCell.PaddingBottom = 5;
            //make sure to force split if we reun over page
            //_tbl.SplitRows = true;

            for (int _ix = 0; _ix < _dt.Rows.Count; _ix++)
            {
                //generate barcodes
                //int _wd = 120; //context.Request["wd"] != null ? wwi_func.vint(context.Request["wd"].ToString()) : 120; //width
                //int _ht = 30; //context.Request["ht"] != null ? wwi_func.vint(context.Request["ht"].ToString()) : 30; //height
                string _code  = _dt.Rows[_ix]["sscc"] != null ? _dt.Rows[_ix]["sscc"].ToString() : "";
                string _title = _dt.Rows[_ix]["title"] != null ? _dt.Rows[_ix]["title"].ToString() : "";
                string _ref   = _dt.Rows[_ix]["publiship_ref"] != null ? _dt.Rows[_ix]["publiship_ref"].ToString() : "";

                if (!string.IsNullOrEmpty(_code))
                {
                    Barcode128 _bc = new Barcode128();
                    _bc.CodeType         = Barcode.CODE128;
                    _bc.ChecksumText     = true;
                    _bc.GenerateChecksum = true;
                    _bc.Code             = _code;

                    //add barcode to to pdf
                    PdfContentByte        _cb  = _pdf.DirectContent;
                    iTextSharp.text.Image _img = _bc.CreateImageWithBarcode(_cb, BaseColor.BLACK, BaseColor.BLACK);

                    PdfPTable _tbl = new PdfPTable(1);
                    _tbl.DefaultCell.Border     = iTextSharp.text.Rectangle.NO_BORDER;
                    _tbl.DefaultCell.PaddingTop = 10;
                    _tbl.SplitLate = true;
                    _tbl.AddCell(_ref + " " + _title);
                    _tbl.AddCell(_img);
                    //don't need to add to doc if we use writeselectedrows
                    _doc.Add(_tbl);
                    //_ypos = _pdf.GetVerticalPosition(false);
                    //_tbl.WriteSelectedRows(0, _tbl.Rows.Count, _doc.LeftMargin, _ypos, _pdf.DirectContent);
                    //4 bacodes per page?
                    bool _new = (_ix + 1) % _ppg == 0 ? true : false;
                    if (_new)
                    {
                        _doc.NewPage();
                    }
                    else
                    {
                        // seperator between items
                        _pdf.DirectContent.SetColorStroke(BaseColor.LIGHT_GRAY);
                        _ypos = _pdf.GetVerticalPosition(false);
                        _pdf.DirectContent.MoveTo(_doc.LeftMargin, _ypos);
                        _pdf.DirectContent.LineTo(_doc.PageSize.Width - _doc.RightMargin, _ypos);
                        _pdf.DirectContent.Stroke();
                    } //end if new
                }     //end if code not empty
            }

            //pushes to output stream
            _doc.Close();
            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + consignmentref + ".pdf");
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.BinaryWrite(_mem.ToArray());
        }
        catch (DocumentException dex)
        {
            _msg = dex.Message.ToString();
            //throw (dex);
            //this.dxlblerr.Text = dex.Message.ToString();
            //this.dxpageorder.ActiveTabIndex = 4; //error page
        }
        catch (IOException ioex)
        {
            _msg = ioex.Message.ToString();
            //throw (ioex);
            //this.dxlblerr.Text = ioex.Message.ToString();
            //this.dxpageorder.ActiveTabIndex = 4; //error page
        }
        finally
        {
            _doc.Close();
        }

        return(_msg);
    }
Esempio n. 26
0
        private void imprimirDNI()
        {
            try
            {
                var num_dni = Request.QueryString["numIdentify"];

                EMascota objE = new EMascota();
                objE.DNI = num_dni;
                //EUsuario eSession = (EUsuario)HttpContext.Current.Session["UserData"];
                objE = NMascota.ObtenerMascotaxDNI(objE);

                using (MemoryStream ms = new MemoryStream())
                {
                    var doc = new Document(PageSize.LETTER, 25, 20, 25, 20);
                    //using (var doc = new Document(PageSize.LETTER, 25, 20, 20, 20))
                    //{
                    iTextSharp.text.pdf.PdfWriter w = iTextSharp.text.pdf.PdfWriter.GetInstance(doc, ms);
                    //using (PdfWriter w = PdfWriter.GetInstance(doc, ms))
                    //{
                    doc.Open();
                    doc.NewPage();
                    //Estilos
                    var titleHeader    = FontFactory.GetFont("Arial", 7, Font.BOLD, new BaseColor(76, 76, 76));
                    var titleRUMP      = FontFactory.GetFont("Arial", 7, Font.BOLD, new BaseColor(0, 0, 0));
                    var titleSmall7B   = FontFactory.GetFont("Courier", 7, Font.BOLD, new BaseColor(0, 0, 0));
                    var titleSmall6    = FontFactory.GetFont("Arial", 6, Font.NORMAL, new BaseColor(0, 0, 0));
                    var titleSmall6B   = FontFactory.GetFont("Arial", 6, Font.BOLD, new BaseColor(0, 0, 0));
                    var titleSmall5    = FontFactory.GetFont("Arial", 5, Font.NORMAL, new BaseColor(0, 0, 0));
                    var titleSmall5B   = FontFactory.GetFont("Arial", 5, Font.BOLD, new BaseColor(0, 0, 0));
                    var fechaCaducidad = FontFactory.GetFont("Arial", 5, Font.BOLD, new BaseColor(228, 141, 25));
                    var numDNI         = FontFactory.GetFont("Arial", 11, Font.BOLD, new BaseColor(255, 131, 5));

                    //Fondo
                    var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/img/dni/fondo.jpg"));
                    logo.ScaleAbsolute(263, 358);
                    logo.SetAbsolutePosition(10, 423);
                    doc.Add(logo);

                    //Tabla Header
                    PdfPTable table  = new PdfPTable(2);
                    float[]   widths = new float[] { 1f, 2f };
                    table.SetWidths(widths);
                    table.HorizontalAlignment = 0;

                    PdfPCell cell = new PdfPCell(new Phrase("REPUBLICA DEL PERU", titleHeader));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    table.AddCell(cell);

                    cell                   = new PdfPCell(new Phrase("RUMP - " + objE.DNI + "-" + (objE.SEXO == "Macho" ? "1" : "2"), titleRUMP));
                    cell.Border            = 0;
                    cell.Rowspan           = 2;
                    cell.PaddingTop        = 8;
                    cell.VerticalAlignment = 1;
                    table.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("REGISTRO UNICO DE MASCOTAS", titleHeader));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    table.AddCell(cell);

                    //Tabla Body
                    PdfPTable tbody = new PdfPTable(4);
                    tbody.TotalWidth  = 237f;
                    tbody.LockedWidth = true;
                    float[] widths2 = new float[] { 17f, 65f, 75f, 80f };
                    tbody.SetWidths(widths2);
                    tbody.HorizontalAlignment = 0;
                    tbody.SpacingBefore       = 5f;
                    //DNI VERTICAL SEPARADO
                    var dniSeparado = "";

                    for (int i = 0; i < objE.DNI.Length; i++)
                    {
                        dniSeparado += objE.DNI.Substring(i, 1) + " ";
                    }

                    cell                     = new PdfPCell(new Phrase(dniSeparado.Trim(), numDNI));
                    cell.Border              = 0;
                    cell.Rotation            = -90;
                    cell.HorizontalAlignment = 1;
                    tbody.AddCell(cell);
                    //Foto Mascota
                    string url_img_mascota = Server.MapPath("~/img/mascota/" + objE.lMASCOTA[0].FOTO);
                    iTextSharp.text.Image imgMascota;
                    if (File.Exists(url_img_mascota))
                    {
                        imgMascota = iTextSharp.text.Image.GetInstance(url_img_mascota);
                    }
                    else
                    {
                        imgMascota = iTextSharp.text.Image.GetInstance(Server.MapPath("~/img/noPets.png"));
                    }
                    imgMascota.ScaleAbsolute(65, 85);
                    imgMascota.SpacingBefore = 5f;
                    cell        = new PdfPCell(imgMascota);
                    cell.Border = 0;
                    tbody.AddCell(cell);

                    //*******************************************************
                    //************* INICIO NOMBRES Y DATOS ******************
                    //*******************************************************
                    PdfPTable tdatos = new PdfPTable(1);

                    cell        = new PdfPCell(new Phrase("Nombre", titleSmall6));
                    cell.Border = 0;
                    tdatos.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.NOMBRE.ToUpper(), titleSmall6B));
                    cell.Border = 0;
                    tdatos.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("Apellidos", titleSmall6));
                    cell.Border = 0;
                    tdatos.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.APELLIDO.ToUpper(), titleSmall6B));
                    cell.Border = 0;
                    tdatos.AddCell(cell);

                    cell            = new PdfPCell(new Phrase("Fecha de Nacimiento", titleSmall6));
                    cell.Border     = 0;
                    cell.PaddingTop = 20;
                    tdatos.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.FEC_NAC.Value.ToString("dd MM yyyy"), titleSmall6B));
                    cell.Border = 0;
                    tdatos.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("Sexo " + objE.SEXO.Substring(0, 1), titleSmall6B));
                    cell.Border = 0;
                    tdatos.AddCell(cell);

                    cell        = new PdfPCell(tdatos);
                    cell.Border = 0;
                    tbody.AddCell(cell);
                    //*******************************************************
                    //**************** FIN NOMBRES Y DATOS ******************
                    //*******************************************************

                    //*******************************************************
                    //******* INICIO FECHAS DE INSCRIPCION ******************
                    //*******************************************************
                    PdfPTable tFechas = new PdfPTable(1);

                    cell        = new PdfPCell(new Phrase("Fecha de Inscripción", titleSmall5));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    tFechas.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.FEC_CREA.Value.ToString("dd MM yyyy"), titleSmall5B));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    cell.PaddingTop          = -2;
                    tFechas.AddCell(cell);

                    cell                     = new PdfPCell(new Phrase("Fecha de Emisión", titleSmall5));
                    cell.Border              = 0;
                    cell.PaddingTop          = 5;
                    cell.HorizontalAlignment = 1;
                    tFechas.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.FEC_EMI.Value.ToString("dd MM yyyy"), titleSmall5B));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    cell.PaddingTop          = -2;
                    tFechas.AddCell(cell);

                    cell                     = new PdfPCell(new Phrase("Fecha de Caducidad", titleSmall5));
                    cell.Border              = 0;
                    cell.PaddingTop          = 5;
                    cell.HorizontalAlignment = 1;
                    tFechas.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.FEC_CAD.Value.ToString("dd MM yyyy"), fechaCaducidad));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    cell.PaddingTop          = -2;
                    tFechas.AddCell(cell);
                    //Imagen Pequeña
                    iTextSharp.text.Image imgMascotaSmall;
                    if (File.Exists(url_img_mascota))
                    {
                        imgMascotaSmall = iTextSharp.text.Image.GetInstance(url_img_mascota);
                    }
                    else
                    {
                        imgMascotaSmall = iTextSharp.text.Image.GetInstance(Server.MapPath("~/img/noPets.png"));
                    }

                    imgMascotaSmall.ScaleAbsolute(30, 38);
                    imgMascotaSmall.SpacingBefore = 7f;
                    cell        = new PdfPCell(imgMascotaSmall);
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    tFechas.AddCell(cell);

                    cell        = new PdfPCell(tFechas);
                    cell.Border = 0;
                    cell.HorizontalAlignment = 0;
                    tbody.AddCell(cell);
                    //*******************************************************
                    //******* FIN FECHAS DE INSCRIPCION *********************
                    //*******************************************************
                    PdfPTable tmayor = new PdfPTable(1);
                    tmayor.TotalWidth          = 237f;
                    tmayor.LockedWidth         = true;
                    tmayor.HorizontalAlignment = 0;

                    int cant_str_nom = 0;
                    cant_str_nom += (objE.TIPO.Substring(0, 1) + "<PER" + objE.NOMBRE.ToUpper() + "<<").Length;
                    if (46 - cant_str_nom < 0)
                    {
                        cant_str_nom = 0;
                    }
                    else
                    {
                        cant_str_nom = 46 - cant_str_nom;
                    }
                    cell             = new PdfPCell(new Phrase(objE.TIPO.Substring(0, 1) + "<PER" + objE.APELLIDO.Replace(" ", "").PadRight(cant_str_nom, Convert.ToChar("<")) + objE.NOMBRE.ToUpper() + "<<", titleSmall7B));
                    cell.Border      = 0;
                    cell.PaddingTop  = 0;
                    cell.PaddingLeft = 18;
                    tmayor.AddCell(cell);

                    cell             = new PdfPCell(new Phrase(objE.DNI + "<1<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<", titleSmall7B));
                    cell.Border      = 0;
                    cell.PaddingLeft = 18;
                    cell.PaddingTop  = -2;
                    tmayor.AddCell(cell);
                    //*******************************************************
                    //********** INICIO PARTE POSTERIOR *********************
                    //*******************************************************
                    PdfPTable tposterior = new PdfPTable(4);
                    tposterior.TotalWidth = 250f;
                    float[] widthsPosterior = new float[] { 60f, 15f, 100f, 90f };
                    tposterior.SetWidths(widthsPosterior);
                    tposterior.LockedWidth         = true;
                    tposterior.HorizontalAlignment = 0;
                    tposterior.SpacingBefore       = 60f;

                    cell             = new PdfPCell(new Phrase("Responsable 1", titleSmall6));
                    cell.Border      = 0;
                    cell.PaddingLeft = 12;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("-", titleSmall6));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.FAMILIARP.ToUpper(), titleSmall6B));
                    cell.Border = 0;
                    tposterior.AddCell(cell);

                    PdfContentByte cb    = w.DirectContent;
                    Barcode128     bc128 = new Barcode128();
                    bc128.Code = objE.DNI;
                    bc128.Font = null;
                    iTextSharp.text.Image imgCodeBar = bc128.CreateImageWithBarcode(cb, null, null);
                    imgCodeBar.ScaleAbsolute(70, 30);
                    cell                     = new PdfPCell(imgCodeBar);
                    cell.Border              = 0;
                    cell.Rotation            = 90;
                    cell.PaddingLeft         = 30;
                    cell.HorizontalAlignment = 2;
                    cell.Rowspan             = 7;
                    tposterior.AddCell(cell);

                    cell             = new PdfPCell(new Phrase("Responsable 2", titleSmall6));
                    cell.Border      = 0;
                    cell.PaddingLeft = 12;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("-", titleSmall6));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.FAMILIARM.ToUpper(), titleSmall6B));
                    cell.Border = 0;
                    tposterior.AddCell(cell);

                    cell               = new PdfPCell(new Phrase("Caracteristicas", titleSmall6B));
                    cell.Border        = 0;
                    cell.Colspan       = 3;
                    cell.PaddingTop    = 5;
                    cell.PaddingBottom = 5;
                    cell.PaddingLeft   = 12;
                    tposterior.AddCell(cell);

                    cell             = new PdfPCell(new Phrase("Raza", titleSmall6));
                    cell.Border      = 0;
                    cell.PaddingLeft = 12;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("-", titleSmall6));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.RAZA.ToUpper(), titleSmall6B));
                    cell.Border = 0;
                    tposterior.AddCell(cell);

                    cell             = new PdfPCell(new Phrase("Calificación", titleSmall6));
                    cell.Border      = 0;
                    cell.PaddingLeft = 12;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("-", titleSmall6));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    tposterior.AddCell(cell);

                    var calificacion = objE.CALIFICACION;
                    switch (calificacion)
                    {
                    case "Rojo":
                        calificacion = "AGRESIVO"; break;

                    case "Verde":
                        calificacion = "AMISTOSO"; break;

                    case "Blanco":
                        calificacion = "DISCAPACITADO"; break;

                    case "Azul":
                        calificacion = "ENTRENADO"; break;

                    case "Amarillo":
                        calificacion = "MIEDOSO"; break;

                    case "Naranja":
                        calificacion = "PELEADOR"; break;
                    }

                    cell        = new PdfPCell(new Phrase(calificacion.ToUpper(), titleSmall6B));
                    cell.Border = 0;
                    tposterior.AddCell(cell);

                    cell             = new PdfPCell(new Phrase("Pelaje", titleSmall6));
                    cell.Border      = 0;
                    cell.PaddingLeft = 12;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("-", titleSmall6));
                    cell.Border = 0;
                    cell.HorizontalAlignment = 1;
                    tposterior.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.COLOR, titleSmall6B));
                    cell.Border = 0;
                    tposterior.AddCell(cell);

                    cell             = new PdfPCell(new Phrase("Domicilio", titleSmall6));
                    cell.Border      = 0;
                    cell.Colspan     = 4;
                    cell.PaddingLeft = 12;
                    tposterior.AddCell(cell);

                    cell             = new PdfPCell(new Phrase(objE.DIRECCION, titleSmall6B));
                    cell.Border      = 0;
                    cell.Colspan     = 4;
                    cell.PaddingLeft = 20;
                    tposterior.AddCell(cell);

                    //*******************************************************
                    //********** INICIO DIRECCION POSTERIOR *****************
                    //*******************************************************
                    PdfPTable tdireccion = new PdfPTable(3);
                    tdireccion.TotalWidth = 200f;
                    float[] widthsDireccion = new float[] { 100f, 50f, 50f };
                    tdireccion.SetWidths(widthsDireccion);
                    tdireccion.LockedWidth         = true;
                    tdireccion.HorizontalAlignment = 0;
                    //tdireccion.SpacingBefore = 10f;

                    cell             = new PdfPCell(new Phrase("Distrito", titleSmall6));
                    cell.Border      = 0;
                    cell.PaddingLeft = 12;
                    tdireccion.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("Provincia", titleSmall6));
                    cell.Border = 0;
                    tdireccion.AddCell(cell);

                    cell        = new PdfPCell(new Phrase("Departamento", titleSmall6));
                    cell.Border = 0;
                    tdireccion.AddCell(cell);

                    cell             = new PdfPCell(new Phrase(objE.DISTRITO, titleSmall6B));
                    cell.Border      = 0;
                    cell.PaddingLeft = 12;
                    tdireccion.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.PROVINCIA, titleSmall6B));
                    cell.Border = 0;
                    tdireccion.AddCell(cell);

                    cell        = new PdfPCell(new Phrase(objE.DEPARTAMENTO, titleSmall6B));
                    cell.Border = 0;
                    tdireccion.AddCell(cell);


                    doc.Add(table);
                    doc.Add(tbody);
                    doc.Add(tmayor);
                    doc.Add(tposterior);
                    doc.Add(tdireccion);

                    doc.Close();
                    //}
                    //}

                    Response.ContentType = "application/pdf";
                    Response.OutputStream.Write(ms.GetBuffer(), 0, ms.GetBuffer().Length);
                    Response.OutputStream.Flush();
                    Response.OutputStream.Close();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Esempio n. 27
0
        /* a method that save the packing slip pdf */
        public static void CreatePackingSlip(SearsValues value, int[] cancelIndex, bool preview)
        {
            // the case if all of the items in the order are cancelled -> don't need to print the packing slip
            if (cancelIndex.Length >= value.LineCount)
            {
                return;
            }

            // first check if the save directory exist -> if not create it
            if (!File.Exists(SavePath))
            {
                Directory.CreateDirectory(SavePath);
            }

            // print each item for packing slip
            for (int i = 0; i < value.LineCount; i++)
            {
                // check if the item is in cancel list
                bool cancelled = cancelIndex.Any(j => i == j);

                // the case if the item is not cancelled -> generate and export it
                if (!cancelled)
                {
                    // initialize PdfWriter object
                    Document  doc    = new Document(PageSize.LETTER, 0, 0, 0, 35);
                    string    file   = SavePath + "\\" + value.TransactionId + '_' + (i + 1) + ".pdf";
                    PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(file, FileMode.Create));

                    // open the document
                    doc.Open();
                    PdfContentByte contentByte = writer.DirectContent;

                    #region Draw Line - Divided Half
                    // drawline
                    PdfContentByte draw = writer.DirectContent;
                    draw.MoveTo(doc.PageSize.Width / 2, 0);
                    draw.LineTo(doc.PageSize.Width / 2, doc.PageSize.Height);
                    draw.Stroke();
                    #endregion

                    // initialize local fields for text
                    BaseFont   baseFont = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, false);
                    BaseFont   boldFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false);
                    ColumnText ct       = new ColumnText(draw);

                    #region Shipping Address and Schedule
                    // set bill to
                    // title
                    Phrase text = new Phrase("BILL TO/FACTURER A:", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 10f, 753f, 150f, 773f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // bill recipient and address
                    text = new Phrase(value.BillTo.Name + '\n' + value.BillTo.Address1 + '\n' + value.BillTo.Address2 + '\n' + value.BillTo.City, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 726f, 150f, 771f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.BillTo.State + '\n' + value.BillTo.PostalCode, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 120f, 704f, 170f, 744f, 9f, Element.ALIGN_LEFT);
                    ct.Go();

                    // set ship to
                    // title
                    text = new Phrase("RECIPIENT/DESTINATAIRA:", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 10f, 693f, 150f, 713f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // ship recipient and address
                    text = new Phrase(value.Recipient.Name + '\n' + value.Recipient.Address1 + '\n' + value.Recipient.Address2 + '\n' + value.Recipient.City, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 666f, 150f, 711f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.Recipient.State + '\n' + value.Recipient.PostalCode, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 120f, 643f, 170f, 683f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.Recipient.DayPhone, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 645f, 150f, 655f, 0f, Element.ALIGN_LEFT);
                    ct.Go();


                    // arrival date
                    // title
                    text = new Phrase("ARRIVAL DATE/D'ARRIVEE", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 208f, 745f, 308f, 765f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    text = new Phrase(value.OrderDate.ToString("MM/dd/yy"), new Font(baseFont, 10));
                    ct.SetSimpleColumn(text, 226f, 745f, 276f, 755f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // schedule
                    text = new Phrase("SCHEDULE", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 227f, 727f, 312f, 737f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy"), new Font(baseFont, 10));
                    ct.SetSimpleColumn(text, 226f, 717f, 279f, 727f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    // sku description
                    text = new Phrase(value.Description[i] + '\n' + value.Description2[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 616f, 150f, 646f, 10f, Element.ALIGN_LEFT);
                    ct.Go();

                    #region Top Left Boxes
                    #region First Box
                    // upper and lower line for sku box
                    draw.MoveTo(15, 616);
                    draw.LineTo(118, 616);
                    draw.Stroke();
                    draw.MoveTo(15, 594);
                    draw.LineTo(118, 594);
                    draw.Stroke();

                    // straight lines for sku box
                    draw.MoveTo(15, 616);
                    draw.LineTo(15, 594);
                    draw.Stroke();
                    draw.MoveTo(38, 616);
                    draw.LineTo(38, 594);
                    draw.Stroke();
                    draw.MoveTo(61, 616);
                    draw.LineTo(61, 594);
                    draw.Stroke();
                    draw.MoveTo(95, 616);
                    draw.LineTo(95, 594);
                    draw.Stroke();
                    draw.MoveTo(118, 616);
                    draw.LineTo(118, 594);
                    draw.Stroke();

                    // title in the first box
                    text = new Phrase("D         M             I          SKU", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 23f, 599f, 173f, 609f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // data in the first box
                    string merchantSku = value.TrxMerchantSku[i];
                    text = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 23f, 587f, 38f, 597f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("", new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 46f, 587f, 61f, 597f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    int index = 2;
                    if (merchantSku[2] == ' ')
                    {
                        index = 3;
                    }
                    text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 65f, 587f, 118f, 597f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    index = index + 5;
                    if (merchantSku.Length <= index)
                    {
                        merchantSku = "";
                    }
                    else if (merchantSku[index] == ' ')
                    {
                        index++;
                        merchantSku = merchantSku.Substring(index);
                    }
                    else
                    {
                        merchantSku = merchantSku.Substring(index);
                    }
                    text = new Phrase(merchantSku, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 99f, 587f, 118f, 597f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Second Box
                    // upper and lower line for second box
                    draw.MoveTo(15, 589);
                    draw.LineTo(130, 589);
                    draw.Stroke();
                    draw.MoveTo(15, 558);
                    draw.LineTo(130, 558);
                    draw.Stroke();

                    // straight lines for sku box
                    draw.MoveTo(15, 589);
                    draw.LineTo(15, 558);
                    draw.Stroke();
                    draw.MoveTo(55, 589);
                    draw.LineTo(55, 558);
                    draw.Stroke();
                    draw.MoveTo(90, 589);
                    draw.LineTo(90, 558);
                    draw.Stroke();
                    draw.MoveTo(130, 589);
                    draw.LineTo(130, 558);
                    draw.Stroke();

                    // title in the second box
                    text = new Phrase("  D             REASON       DATE\nM.U.C        RAISON", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 24f, 553.5f, 174f, 603.5f, 21.5f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion
                    #endregion

                    #region Price
                    // price titles
                    text = new Phrase("MERCH. PRICE\nPRIX DE MARCH", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 622f, 247f, 637f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("DISCOUNT\nESCOMPTE", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 610f, 247f, 625f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("G.S.T./H.S.T.\nT.P.S./T.V.H.", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 598f, 247f, 613f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("P.S.T.\nT.V.P.", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 586f, 247f, 601f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("Total", new Font(boldFont, 7));
                    ct.SetSimpleColumn(text, 197f, 567f, 247f, 582f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("PRICE\nPRIX", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 546f, 247f, 561f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("DISCOUNT\nESCOMPTE", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 534f, 247f, 549f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("HANDLING\nMANUTENTION", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 522f, 247f, 537f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("ELEVY\nTAXE ENVIRO", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 510f, 247f, 525f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("DELIVERY\nLIVRAISON", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 498f, 247f, 513f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("G.S.T./H.S.T.\nT.P.S./T.V.H.", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 486f, 247f, 501f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("P.S.T.\nT.V.P.", new Font(baseFont, 5));
                    ct.SetSimpleColumn(text, 197f, 474f, 247f, 489f, 5f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("Total", new Font(boldFont, 7));
                    ct.SetSimpleColumn(text, 197f, 455f, 247f, 470f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // price number
                    char temp;
                    if (value.GstHstExtended[i] > 0 && value.PstExtended[i] > 0)
                    {
                        temp = 'B';
                    }
                    else if (value.GstHstExtended[i] > 0)
                    {
                        temp = 'T';
                    }
                    else if (value.PstExtended[i] > 0)
                    {
                        temp = 'P';
                    }
                    else
                    {
                        temp = ' ';
                    }

                    text = new Phrase(value.UnitPrice[i] + " " + temp, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 613f, 292f, 628f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    string[] tempTax = new string[2];
                    switch (temp)
                    {
                    case 'B':
                        tempTax[0] = value.GstHstExtended[i].ToString(CultureInfo.InvariantCulture);
                        tempTax[1] = value.PstExtended[i].ToString(CultureInfo.InvariantCulture);
                        break;

                    case 'T':
                        tempTax[0] = value.GstHstExtended[i].ToString(CultureInfo.InvariantCulture);
                        tempTax[1] = string.Empty;
                        break;

                    case 'P':
                        tempTax[0] = string.Empty;
                        tempTax[1] = value.PstExtended[i].ToString(CultureInfo.InvariantCulture);
                        break;

                    default:
                        tempTax[0] = string.Empty;
                        tempTax[1] = string.Empty;
                        break;
                    }
                    text = new Phrase(tempTax[0], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 589.5f, 292f, 604.5f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(tempTax[1], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 579f, 292f, 594f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase((value.UnitPrice[i] + value.GstHstExtended[i] + value.PstExtended[i]).ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 562f, 292f, 582f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    if (value.GstHstTotal[i] > 0 && value.PstTotal[i] > 0)
                    {
                        temp = 'B';
                    }
                    else if (value.GstHstTotal[i] > 0)
                    {
                        temp = 'T';
                    }
                    else if (value.PstTotal[i] > 0)
                    {
                        temp = 'P';
                    }
                    else
                    {
                        temp = ' ';
                    }

                    switch (temp)
                    {
                    case 'B':
                        tempTax[0] = value.GstHstTotal[i].ToString(CultureInfo.InvariantCulture);
                        tempTax[1] = value.PstTotal[i].ToString(CultureInfo.InvariantCulture);
                        break;

                    case 'T':
                        tempTax[0] = value.GstHstTotal[i].ToString(CultureInfo.InvariantCulture);
                        tempTax[1] = string.Empty;
                        break;

                    case 'P':
                        tempTax[0] = string.Empty;
                        tempTax[1] = value.PstTotal[i].ToString(CultureInfo.InvariantCulture);
                        break;

                    default:
                        tempTax[0] = string.Empty;
                        tempTax[1] = string.Empty;
                        break;
                    }

                    text = new Phrase(value.UnitPrice[i] + " " + temp, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 533f, 293f, 553f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.LineHandling[i].ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 513f, 293f, 528f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.LineShipping[i].ToString(CultureInfo.InstalledUICulture), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 490f, 293f, 505f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(tempTax[0], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 478f, 293f, 493f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(tempTax[1], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 466f, 293f, 481f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.LineBalanceDue[i].ToString(CultureInfo.InvariantCulture), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 252f, 455f, 292f, 470f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Left Unknown Region
                    // Other things that I don't know what is this for :(
                    text = new Phrase("SEARS CANADA / VI", new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 470f, 150f, 485f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("ORDER NO. DE COMMANDE", new Font(boldFont, 7));
                    ct.SetSimpleColumn(text, 10f, 457f, 150f, 472f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.CustOrderNumber, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 446f, 150f, 462f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("VENDOR SKU\n" + value.TrxVendorSku[i], new Font(boldFont, 13));
                    ct.SetSimpleColumn(text, 10f, 400f, 150f, 450f, 11f, Element.ALIGN_LEFT);
                    ct.Go();

                    // sku title
                    text = new Phrase("D           M              I                    Q                  C              SKU             G", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 10f, 413.5f, 250f, 428.5f, 10f, Element.ALIGN_LEFT);
                    ct.Go();

                    // sku number
                    merchantSku = value.TrxMerchantSku[i];
                    text        = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 24f, 413.5f, 39f, 428.5f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("", new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 57f, 413.5f, 72f, 428.5f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    index = 2;
                    if (merchantSku[2] == ' ')
                    {
                        index = 3;
                    }
                    text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 83f, 413.5f, 123f, 428.5f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.TrxQty[i].ToString(), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 143f, 413.5f, 158f, 428.5f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    index = index + 5;
                    if (merchantSku.Length <= index)
                    {
                        merchantSku = string.Empty;
                    }
                    else if (merchantSku[index] == ' ')
                    {
                        index++;
                        merchantSku = merchantSku.Substring(index);
                    }
                    else
                    {
                        merchantSku = merchantSku.Substring(index);
                    }
                    text = new Phrase(merchantSku, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 166f, 413.5f, 186f, 428.5f, 10f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Left Bottom Additional Info
                    // some number
                    text = new Phrase(value.PoNumber, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 357f, 150f, 367f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // sears infomation
                    text = new Phrase("CUSTOMER INQUIRY/DE CLIENT", new Font(boldFont, 7));
                    ct.SetSimpleColumn(text, 10f, 338f, 150f, 348f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("WWW.SEARS.CA", new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 10f, 328f, 150f, 338f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("1-800-267-3277", new Font(baseFont, 10));
                    ct.SetSimpleColumn(text, 10f, 318f, 150f, 328f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // note
                    text = new Phrase("THIS BILL OF SALE IS REQUIRED FOR RETURN OR ADJUSTMENT\nOF PURCHASE.\nCETTE FACTURE EST REQUISE POUR TOUT RETROU DE\nMARCHANDIS OU RECLAMATION.", new Font(boldFont, 9));
                    ct.SetSimpleColumn(text, 10f, 277f, 320f, 317f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Button Return Region
                    // draw line first
                    draw.MoveTo(10, 255);
                    draw.LineTo(doc.PageSize.Width / 2, 255);
                    draw.Stroke();

                    #region Left Box
                    // horizontal lines
                    draw.MoveTo(14, 245);
                    draw.LineTo(129, 245);
                    draw.Stroke();
                    draw.MoveTo(14, 229.5);
                    draw.LineTo(129, 229.5);
                    draw.Stroke();
                    draw.MoveTo(14, 214);
                    draw.LineTo(129, 214);
                    draw.Stroke();

                    // vertical lines
                    draw.MoveTo(14, 245);
                    draw.LineTo(14, 214);
                    draw.Stroke();
                    draw.MoveTo(129, 245);
                    draw.LineTo(129, 214);
                    draw.Stroke();

                    // text
                    text = new Phrase("REASON\n RAISON", new Font(baseFont, 11));
                    ct.SetSimpleColumn(text, 47f, 208f, 97f, 250f, 16f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Right Box
                    // horizontal lines
                    draw.MoveTo(139, 245);
                    draw.LineTo(254, 245);
                    draw.Stroke();
                    draw.MoveTo(139, 214);
                    draw.LineTo(254, 214);
                    draw.Stroke();

                    // vertical lines
                    draw.MoveTo(139, 245);
                    draw.LineTo(139, 214);
                    draw.Stroke();
                    draw.MoveTo(179, 245);
                    draw.LineTo(179, 214);
                    draw.Stroke();
                    draw.MoveTo(214, 245);
                    draw.LineTo(214, 214);
                    draw.Stroke();
                    draw.MoveTo(254, 245);
                    draw.LineTo(254, 214);
                    draw.Stroke();

                    // text
                    text = new Phrase("  D             REASON      DATE\n                  RAISON", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 148f, 214f, 254f, 259f, 21f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion
                    #endregion

                    #region Barcode Left Bottom
                    #region Barcode One
                    // barcode number
                    text = new Phrase(value.EncodedPrice[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 16f, 177f, 176f, 192f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // add barcode
                    Barcode128 barcode128 = new Barcode128
                    {
                        Code          = value.EncodedPrice[i],
                        StartStopText = false,
                        Font          = null,
                        Extended      = true
                    };

                    Image image = barcode128.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK);
                    image.ScaleAbsoluteHeight(43f);
                    image.SetAbsolutePosition(24f, 145f);
                    contentByte.AddImage(image);

                    // bar code text under
                    text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy") + "             " + value.LineBalanceDue[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 16f, 123f, 176f, 133f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Barcode Two
                    string code = value.TrxMerchantSku[i].Replace(" ", string.Empty);
                    if (code.Length % 2 != 0)
                    {
                        code += '0';
                    }

                    BarcodeInter25 barcode25 = new BarcodeInter25
                    {
                        Code          = code,
                        StartStopText = false,
                        Font          = null,
                        Extended      = true
                    };

                    image = barcode25.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK);
                    image.ScaleAbsoluteHeight(43f);
                    image.SetAbsolutePosition(24f, 70f);
                    contentByte.AddImage(image);

                    // barcode text
                    text = new Phrase(value.TrxMerchantSku[i] + '\n' + value.Description[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 16f, 48f, 156f, 68f, 9f, Element.ALIGN_LEFT);
                    ct.Go();

                    // section description
                    text = new Phrase("THIS BILL OF SALE IS\nREQUIRED FOR RETURN", new Font(boldFont, 9));
                    ct.SetSimpleColumn(text, 181f, 66f, 291f, 116f, 9f, Element.ALIGN_LEFT);
                    ct.Go();

                    // useless stuff
                    text = new Phrase("66", new Font(boldFont, 11));
                    ct.SetSimpleColumn(text, 200f, 61f, 220f, 71f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("V2C", new Font(boldFont, 13));
                    ct.SetSimpleColumn(text, 258f, 3f, 300f, 23f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion
                    #endregion

                    #region Right Ship To Address
                    // title
                    text = new Phrase("RECIPIENT/DESTINATAIRA:", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 318f, 753f, 418f, 773f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // ship to recipient and address
                    text = new Phrase(value.Recipient.Name + '\n' + value.Recipient.Address1 + '\n' + value.Recipient.Address2 + '\n' + value.Recipient.City, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 318f, 726f, 458f, 771f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.Recipient.State + '\n' + value.Recipient.PostalCode + '\n' + value.ExpectedShipDate[i].ToString("MM/dd/yy"), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 428f, 704f, 488f, 744f, 9f, Element.ALIGN_LEFT);
                    ct.Go();

                    // ship to phone and total price
                    text = new Phrase(value.Recipient.DayPhone + '\n' + value.LineBalanceDue[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 515f, 729f, 605f, 779f, 17f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Barcode Right Top
                    // barcode number
                    text = new Phrase(value.EncodedPrice[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 318f, 683f, 468f, 693f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // add barcode
                    barcode128 = new Barcode128
                    {
                        Code          = value.EncodedPrice[i],
                        StartStopText = false,
                        Font          = null,
                        Extended      = true
                    };

                    image = barcode128.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK);
                    image.ScaleAbsoluteHeight(43f);
                    image.SetAbsolutePosition(326f, 646f);
                    contentByte.AddImage(image);

                    // bar code text under
                    text = new Phrase(value.CustOrderDate.ToString("MM/dd/yy") + "             " + value.LineBalanceDue[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 318f, 625f, 488f, 635f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Top Right Box
                    // upper and lower line for sku box
                    draw.MoveTo(318, 611);
                    draw.LineTo(421, 611);
                    draw.Stroke();
                    draw.MoveTo(318, 589);
                    draw.LineTo(421, 589);
                    draw.Stroke();

                    // straight lines for sku box
                    draw.MoveTo(318, 611);
                    draw.LineTo(318, 589);
                    draw.Stroke();
                    draw.MoveTo(341, 611);
                    draw.LineTo(341, 589);
                    draw.Stroke();
                    draw.MoveTo(364, 611);
                    draw.LineTo(364, 589);
                    draw.Stroke();
                    draw.MoveTo(398, 611);
                    draw.LineTo(398, 589);
                    draw.Stroke();
                    draw.MoveTo(421, 611);
                    draw.LineTo(421, 589);
                    draw.Stroke();

                    // title in the first box
                    text = new Phrase(" D        M             I          SKU", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 326f, 594f, 476f, 604f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // data in the first box
                    merchantSku = value.TrxMerchantSku[i];
                    text        = new Phrase(merchantSku.Remove(2), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 326f, 582f, 349f, 592f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("", new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 350f, 582f, 365f, 592f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    index = 2;
                    if (merchantSku[2] == ' ')
                    {
                        index = 3;
                    }
                    text = new Phrase(merchantSku.Substring(index, 5), new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 368f, 582f, 400f, 592f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    index = index + 5;
                    if (merchantSku.Length <= index)
                    {
                        merchantSku = string.Empty;
                    }
                    else if (merchantSku[index] == ' ')
                    {
                        index++;
                        merchantSku = merchantSku.Substring(index);
                    }
                    else
                    {
                        merchantSku = merchantSku.Substring(index);
                    }
                    text = new Phrase(merchantSku, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 402f, 582f, 422f, 592f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    // sku description
                    text = new Phrase(value.Description[i] + '\n' + value.Description2[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 318f, 560f, 458f, 585f, 10f, Element.ALIGN_LEFT);
                    ct.Go();

                    #region Right Unknown Region
                    // determine if the order is direct shipment
                    string take = value.PartnerPersonPlaceId == "" ? "DIRECT" : value.PartnerPersonPlaceId;

                    text = new Phrase(take, new Font(boldFont, 16));
                    ct.SetSimpleColumn(text, 318f, 519f, 418f, 539f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase("CSU:", new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 318f, 518f, 418f, 528f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    if (take != "DIRECT")
                    {
                        // strange address
                        text = new Phrase(value.ShipTo.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City, new Font(baseFont, 9));
                        ct.SetSimpleColumn(text, 318f, 481f, 468f, 526f, 9f, Element.ALIGN_LEFT);
                        ct.Go();
                        text = new Phrase(value.ShipTo.State + '\n' + value.ShipTo.PostalCode, new Font(baseFont, 9));
                        ct.SetSimpleColumn(text, 428f, 459f, 488f, 499f, 9f, Element.ALIGN_LEFT);
                        ct.Go();

                        // strange message
                        text = new Phrase(value.PaymentMethod + "                                                " + value.LineBalanceDue[i], new Font(baseFont, 13));
                        ct.SetSimpleColumn(text, 318f, 452f, 618f, 472f, 9f, Element.ALIGN_LEFT);
                        ct.Go();
                    }

                    // strange message continue
                    text = new Phrase(value.PackSlipMessage, new Font(baseFont, 7));
                    ct.SetSimpleColumn(text, 318f, 441f, 418f, 451f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Buttom Right Ship To Address
                    //title
                    text = new Phrase("SHIP TO/EXPEDIER A:", new Font(boldFont, 10));
                    ct.SetSimpleColumn(text, 318f, 408f, 458f, 423f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // address
                    text = new Phrase(value.Recipient.Name + '\n' + value.ShipTo.Address1 + '\n' + value.ShipTo.Address2 + '\n' + value.ShipTo.City, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 318f, 375f, 468f, 420f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.ShipTo.State + '\n' + value.ShipTo.PostalCode, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 428f, 362f, 488f, 392f, 9f, Element.ALIGN_LEFT);
                    ct.Go();

                    // freight info
                    text = new Phrase("FREIGHE LANE/LIGNE DE FRET:                   SPUR/CONVOYEUR:", new Font(boldFont, 7));
                    ct.SetSimpleColumn(text, 318f, 348f, 568f, 358f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.FreightLane, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 318f, 348f, 358f, 358f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    text = new Phrase(value.Spur, new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 465f, 348f, 495f, 358f, 9f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    #region Right Buttom Barcode
                    // barcode number
                    text = new Phrase(value.ReceivingInstructions[i], new Font(baseFont, 9));
                    ct.SetSimpleColumn(text, 318f, 306f, 468f, 316f, 0f, Element.ALIGN_LEFT);
                    ct.Go();

                    // add barcode
                    code = value.ReceivingInstructions[i].Replace(" ", string.Empty);
                    if (code.Length % 2 != 0)
                    {
                        code += '0';
                    }

                    barcode25 = new BarcodeInter25
                    {
                        Code          = code,
                        StartStopText = false,
                        Font          = null,
                        Extended      = true
                    };

                    image = barcode25.CreateImageWithBarcode(contentByte, BaseColor.BLACK, BaseColor.BLACK);
                    image.ScaleAbsoluteHeight(43f);
                    image.SetAbsolutePosition(326f, 269f);
                    contentByte.AddImage(image);

                    // a minor stuff
                    text = new Phrase("V2C", new Font(boldFont, 30));
                    ct.SetSimpleColumn(text, 480f, 85f, 550f, 135f, 0f, Element.ALIGN_LEFT);
                    ct.Go();
                    #endregion

                    doc.Close();

                    if (!preview)
                    {
                        continue;
                    }

                    // start the pdf for previewing
                    if (System.Diagnostics.Process.GetProcessesByName(file).Length < 1)
                    {
                        System.Diagnostics.Process.Start(file);
                    }
                }
            }
        }
Esempio n. 28
0
        public static Document CreateReport(Box[] boxInfo, string fileName)
        {
            var pdfdoc      = new Document(PageSize.Letter);
            var pdfFilePath = fileName;
            var fileStream  = new FileStream(pdfFilePath, FileMode.Create);

            PdfWriter  writer  = PdfWriter.GetInstance(pdfdoc, fileStream);
            Barcode128 barcode = new Barcode128();

            BaseFont bf_helvBold = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, false);

            pdfdoc.Open();

            PdfContentByte under  = writer.DirectContentUnder;
            PdfContentByte canvas = writer.DirectContent;


            for (int i = 0; i < boxInfo.Length; i++)
            {
                if (boxInfo[i].IsSelected)
                {
                    under.Rectangle(boundingBoxLocations[i].BoundingLocation.X, boundingBoxLocations[i].BoundingLocation.Y, box_bounding_width, box_bounding_height);
                    under.Rectangle(boundingBoxLocations[i].BoundingLocation.X, boundingBoxLocations[i].BoundingLocation.Y - box_small_height, box_small_width, box_small_height);
                    under.SetLineWidth(1);
                    under.Stroke();

                    under.Circle(boundingBoxLocations[i].SphereColorLocation.X, boundingBoxLocations[i].SphereColorLocation.Y, circleRadius);
                    if (boxInfo[i].LensInfo.Sphere >= 0)
                    {
                        under.SetRgbColorFill(230, 50, 0);
                    }
                    else
                    {
                        under.SetRgbColorFill(138, 182, 252);
                    }
                    under.FillStroke();

                    if (boxInfo[i].LensInfo.AntiReflectiveCoating)
                    {
                        canvas.BeginText();
                        canvas.SetFontAndSize(bf_helvBold, 12);
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, "AR", boundingBoxLocations[i].AntiReflectiveLocation.X, boundingBoxLocations[i].AntiReflectiveLocation.Y, 0);
                        canvas.EndText();
                    }

                    if (boxInfo[i].LensInfo.Transitions)
                    {
                        canvas.BeginText();
                        canvas.SetFontAndSize(bf_helvBold, 16);
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, "T", boundingBoxLocations[i].TransitionsLocation.X, boundingBoxLocations[i].TransitionsLocation.Y, 0);
                        canvas.EndText();
                    }

                    //MATERIAL
                    canvas.BeginText();
                    canvas.SetFontAndSize(bf_helvBold, 12);
                    canvas.ShowTextAligned(Element.ALIGN_CENTER, boxInfo[i].LensInfo.Material.Name.ToString().ToUpper(), boundingBoxLocations[i].MaterialLocation.X, boundingBoxLocations[i].MaterialLocation.Y, 0);
                    canvas.EndText();


                    //POWER SPHERE
                    canvas.BeginText();
                    canvas.SetFontAndSize(bf_helvBold, 34);
                    if (boxInfo[i].LensInfo.Sphere > 0.00m)
                    {
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, "+" + boxInfo[i].LensInfo.Sphere.ToString().ToUpper() + " / " + boxInfo[i].LensInfo.Cylinder.ToString().ToUpper(), boundingBoxLocations[i].SphereLocation.X, boundingBoxLocations[i].SphereLocation.Y, 0);
                    }
                    else
                    {
                        canvas.ShowTextAligned(Element.ALIGN_CENTER, boxInfo[i].LensInfo.Sphere.ToString().ToUpper() + " / " + boxInfo[i].LensInfo.Cylinder.ToString().ToUpper(), boundingBoxLocations[i].SphereLocation.X, boundingBoxLocations[i].SphereLocation.Y, 0);
                    }
                    canvas.EndText();

                    //Barcode
                    barcode.Code = boxInfo[i].LensInfo.ProductLabel;
                    barcode.Size = 10;

                    Image code128Image = barcode.CreateImageWithBarcode(canvas, BaseColor.Black, BaseColor.Black);
                    code128Image.ScalePercent(110);
                    code128Image.Alignment = Element.ALIGN_CENTER;
                    code128Image.SetAbsolutePosition(((box_bounding_width - code128Image.ScaledWidth) / 2) + boundingBoxLocations[i].BoundingLocation.X, boundingBoxLocations[i].BarcodeLocation.Y);
                    pdfdoc.Add(code128Image);
                }
            }

            pdfdoc.Close();
            fileStream.Dispose();

            return(pdfdoc);
        }
Esempio n. 29
0
        private void pr_pro_Click(object sender, EventArgs e)
        {
            connection_check();
            try
            {
                Document doc = new Document(new iTextSharp.text.Rectangle(110, 80));

                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes.pdf", FileMode.Create));

                doc.Open();

                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Price");
                dt.Columns.Add("INV");
                dt.Columns.Add("Expire");
                string       so1 = "", so2 = "", so3 = "", so4 = "", so5 = "";
                MySqlCommand cmsel = new MySqlCommand("select bar_name,bar_price,invoice_no,expdate from barcod", conngsm1);
                // SqlCommand cmsel = new SqlCommand("select bar_name,bar_price,invoice_no from barcod", cnn);
                cmsel.ExecuteNonQuery();
                MySqlDataReader cmread = cmsel.ExecuteReader();
                //cmsel.ExecuteNonQuery();
                // SqlDataReader cmread = cmsel.ExecuteReader();
                while (cmread.Read())
                {
                    so1 = cmread[0].ToString();
                    so2 = cmread[1].ToString();
                    so3 = cmread[2].ToString();
                    so4 = cmread[3].ToString();
                    //DateTime dts = Convert.ToDateTime(so4);
                    so5 = so4;
                    //int conts = Convert.ToInt32(textBox3.Text);

                    // for (int i = 0; i < conts; i++)
                    {
                        DataRow row = dt.NewRow();
                        row["ID"]     = so1;
                        row["Price"]  = so2;
                        row["INV"]    = so3;
                        row["Expire"] = so5;
                        dt.Rows.Add(row);
                    }
                }
                cmread.Dispose();
                System.Drawing.Image img1 = null;


                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    {
                        if (i != 0)
                        {
                            doc.NewPage();
                        }



                        PdfContentByte cb1 = writer.DirectContent;
                        BaseFont       bf  = BaseFont.CreateFont(BaseFont.TIMES_BOLDITALIC, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                        cb1.SetFontAndSize(bf, 9.0f);
                        cb1.BeginText();
                        cb1.SetTextMatrix(10.0f, 68.5f);
                        cb1.ShowText("F r e s c o s w e e t s");

                        cb1.EndText();



                        PdfContentByte cb21  = writer.DirectContent;
                        BaseFont       bf111 = BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                        cb21.SetFontAndSize(bf111, 8.0f);
                        cb21.BeginText();
                        cb21.SetTextMatrix(5.0f, 60.0f);
                        cb21.ShowText(dt.Rows[i]["INV"].ToString());
                        cb21.EndText();



                        PdfContentByte cb21c  = writer.DirectContent;
                        BaseFont       bf111c = BaseFont.CreateFont(BaseFont.COURIER_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                        cb21c.SetFontAndSize(bf111c, 5.3f);
                        cb21c.BeginText();
                        cb21c.SetTextMatrix(5.0f, 50.0f);
                        cb21c.ShowText(dt.Rows[i]["Expire"].ToString());
                        cb21c.EndText();



                        iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
                        iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                        bc.TextAlignment = Element.ALIGN_LEFT;
                        bc.Size          = 5;

                        //BaseFont bf1m = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                        //bc.SetFontAndSize(bf1m, 24.3f);
                        bc.Code          = dt.Rows[i]["ID"].ToString();
                        bc.StartStopText = true;
                        bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                        bc.Extended      = false;


                        iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb, iTextSharp.text.Color.BLACK, iTextSharp.text.Color.BLACK);
                        BaseFont bf11             = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);


                        cb.SetTextMatrix(3.5f, 6.0f);
                        img.ScaleToFit(100, 30);
                        img.SetAbsolutePosition(5.0f, 5);
                        img.Alignment = Element.ALIGN_LEFT;
                        cb.AddImage(img);
                    }
                }

                ////////////////////***********************************//////////////////////
                doc.Open();
                doc.Close();
                System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes.pdf");

                checkBox1.CheckState = CheckState.Unchecked;
                checkBox2.CheckState = CheckState.Unchecked;
                checkBox3.CheckState = CheckState.Unchecked;
                checkBox4.CheckState = CheckState.Unchecked;
                textBox5.Text        = "";
            }
            catch (OleDbException ex)
            { }
        }
Esempio n. 30
0
        private void button1_Click(object sender, EventArgs e)
        {
            Document doc = new Document(new iTextSharp.text.Rectangle(24, 12), 5, 5, 1, 1);

            try
            {
                PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(
                                                             Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/codes5555555.pdf", FileMode.Create));
                doc.Open();

                DataTable dt = new DataTable();
                dt.Columns.Add("ID");
                dt.Columns.Add("Price");
                for (int i = 0; i < 20; i++)
                {
                    DataRow row = dt.NewRow();
                    row["ID"]    = "ZS00000000000000" + i.ToString();
                    row["Price"] = "100," + i.ToString();
                    dt.Rows.Add(row);
                }
                //       System.Drawing.Image img1 = null;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (i != 0)
                    {
                        doc.NewPage();
                    }
                    PdfContentByte cb1 = writer.DirectContent;
                    BaseFont       bf  = BaseFont.CreateFont(BaseFont.TIMES_BOLDITALIC, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

                    cb1.SetFontAndSize(bf, 2.0f);
                    cb1.BeginText();
                    cb1.SetTextMatrix(1.2f, 9.5f);
                    cb1.ShowText("Safi Garments");
                    cb1.EndText();

                    PdfContentByte cb2 = writer.DirectContent;
                    BaseFont       bf1 = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                    cb2.SetFontAndSize(bf1, 1.3f);
                    cb2.BeginText();
                    cb2.SetTextMatrix(17.5f, 1.0f);
                    cb2.ShowText(dt.Rows[i]["Price"].ToString());
                    cb2.EndText();

                    iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;
                    iTextSharp.text.pdf.Barcode128     bc = new Barcode128();
                    bc.TextAlignment = Element.ALIGN_LEFT;
                    bc.Code          = dt.Rows[i]["ID"].ToString();
                    bc.StartStopText = false;
                    bc.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
                    bc.Extended      = true;

                    //System.Drawing.Image bimg =
                    //  bc.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
                    //img1 = bimg;

                    iTextSharp.text.Image img = bc.CreateImageWithBarcode(cb,
                                                                          iTextSharp.text.BaseColor.BLACK, iTextSharp.text.BaseColor.BLACK);

                    cb.SetTextMatrix(1.5f, 3.0f);
                    img.ScaleToFit(60, 5);
                    img.SetAbsolutePosition(1.5f, 1);
                    cb.AddImage(img);
                }

                ////////////////////***********************************//////////////////////

                doc.Close();
                System.Diagnostics.Process.Start(Environment.GetFolderPath(
                                                     Environment.SpecialFolder.Desktop) + "/codes.pdf");
                //MessageBox.Show("Bar codes generated on desktop fileName=codes.pdf");
            }
            catch
            {
            }
            finally
            {
                doc.Close();
            }
        }