示例#1
0
        string CodigoBarra2(string c_Dato)
        {
            string c_nomarchivo = "";

            string texto = c_Dato;

            c_nomarchivo = DateTime.Now.ToString("hhmmss") + "_" + c_Dato + ".bmp";
            //BarcodePDF417 codigobarras = new BarcodePDF417();
            Barcode128 codigobarras = new Barcode128();

            //codigobarras.Options = BarcodePDF417.PDF417_USE_ASPECT_RATIO;
            //codigobarras.ErrorLevel = 8;
            //codigobarras.SetText(texto);

            //codigobarras.TextAlignment = Element.ALIGN_CENTER;
            codigobarras.Code          = c_Dato;
            codigobarras.StartStopText = false;
            codigobarras.CodeType      = iTextSharp.text.pdf.Barcode128.EAN13;
            codigobarras.Extended      = true;

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

            c_nomarchivo = @"c:\ssf-net\tmp\ticket\" + c_nomarchivo;
            Cls_IO o_io = new Cls_IO();

            o_io.Fil_EliminarArchivo(c_nomarchivo);
            bm.Save(c_nomarchivo);
            return(c_nomarchivo);
        }
示例#2
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);
        }
示例#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);
        }
示例#4
0
        public void CreatePdf(PdfDocument pdfDocument, Document document, bool isLast)
        {
            document.SetLeftMargin(100);
            Barcode128 b = new Barcode128(pdfDocument);

            b.SetCodeType(Barcode128.CODE128);
            b.SetCode(ID);

            PdfFormXObject bobject = b.CreateFormXObject(pdfDocument);
            BarcodeQRCode  qr      = new BarcodeQRCode(ID);

            document.Add(new Paragraph(String.Format("{0} {1} {2}", Testee.Surname, Testee.Forename, Testee.Birthday.ToString("yyyy-MM-dd"))).SetFontSize(25).SetPaddingBottom(10));
            document.Add(new Paragraph("ID:"));
            document.Add(new Paragraph(ID).SetFontSize(40));
            document.Add(new Paragraph("ID NICHT DOPPELT SCANNEN").SetFontColor(ColorConstants.RED).SetBold().SetPaddingBottom(20));
            //document.Add(new Image(bobject).SetAutoScale(true));
            Div d = new Div();

            d.SetWidth(UnitValue.CreatePercentValue(33));
            d.Add(new Image(bobject).SetAutoScale(true));
            d.SetMarginBottom(20);
            document.Add(d);
            Div q = new Div();

            q.SetWidth(UnitValue.CreatePercentValue(50));
            q.Add(new Image(qr.CreateFormXObject(pdfDocument)).SetAutoScale(true));
            document.Add(q);
            if (!isLast)
            {
                document.Add(new AreaBreak());
            }
            //document.Close();
        }
示例#5
0
 private void btn_generar_Click(object sender, EventArgs e)
 {
     if (veri)
     {
         Barcode128 codigoB = new Barcode128();
         codigoB.BarHeight = 50;
         codigoB.Code      = lb_referencia.Text;
         codigoB.CodeType  = Barcode.CODE128;
         try
         {
             Bitmap bm = new Bitmap(codigoB.CreateDrawingImage(Color.Black, Color.White));
             Image  ima;
             ima = new Bitmap(bm.Width, bm.Height);
             Graphics gra = Graphics.FromImage(ima);
             gra.FillRectangle(new SolidBrush(Color.White), 0, 0, bm.Width, bm.Height);
             gra.DrawImage(bm, 0, 0);
             barra.Image = ima;
             ok          = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show("No se puede  generar " + ex.Message);
         }
     }
     else
     {
         MessageBox.Show("Por favor seleccione un elemeto de la tabla para generar codigo de barras");
     }
 }
 private byte[] RetornarArrayBytesTemplate(List <DadosImagem> imagens)
 {
     using (MemoryStream memoryStream = new MemoryStream())
     {
         PdfStamper pdfStamper = new PdfStamper(new PdfReader(this.Template.Caminho), (Stream)memoryStream);
         AcroFields acroFields = pdfStamper.AcroFields;
         foreach (KeyValuePair <string, string> parametro in this.Template.Parametros)
         {
             acroFields.SetField(parametro.Key, parametro.Value);
         }
         foreach (DadosImagem imagen in imagens)
         {
             if (imagen.Barcode)
             {
                 Barcode128 barcode128 = new Barcode128();
                 barcode128.Code = imagen.AtributosImagem;
                 iTextSharp.text.Image instance = iTextSharp.text.Image.GetInstance(barcode128.CreateDrawingImage(Color.Black, Color.White), BaseColor.White);
                 pdfStamper.GetOverContent(1).AddImage(instance, (float)Convert.ToInt32((double)instance.Width * 0.98), 0.0f, 0.0f, instance.Height, 25f, 445f);
             }
             else
             {
                 iTextSharp.text.Image instance = iTextSharp.text.Image.GetInstance(imagen.Imagem, BaseColor.White);
                 pdfStamper.GetOverContent(1).AddImage(instance, instance.Width, 0.0f, 0.0f, instance.Height, (float)imagen.PosicaoVertical, (float)imagen.PosicaoHorizontal);
             }
         }
         pdfStamper.FormFlattening = true;
         pdfStamper.Close();
         return(memoryStream.ToArray());
     }
 }
示例#7
0
        private void txtCodigo_Prod_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((int)e.KeyChar == (int)Keys.Enter)

            {
                Barcode128 bcode = new Barcode128();
                bcode.BarHeight        = 50;
                bcode.Code             = txtCodigo_Prod.Text;
                bcode.GenerateChecksum = true;
                bcode.CodeType         = Barcode.CODE128;
                //   PCTCodigoBarra.BackgroundImage = bcode.Encode(BarcodeLib.TYPE.CODE128, txtCodigo_Prod.Text, Color.Black, Color.White, 400, 100);

                try
                {
                    Bitmap bm = new Bitmap(bcode.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
                    Image  img;
                    img = new Bitmap(bm.Width, bm.Height);
                    Graphics G = Graphics.FromImage(img);
                    G.FillRectangle(new SolidBrush(System.Drawing.Color.White), 0, 0, bm.Width, bm.Height);
                    G.DrawImage(bm, 0, 0);
                    PCTCodigoBarra.Image = img;
                }
                catch (Exception)
                {
                    MessageBox.Show("No se pudop genrar el codigo de barra", "Proceso", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#8
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));

            Barcode128 code128 = new Barcode128(pdfDoc);

            code128.SetCode("12345XX789XXX");
            code128.SetCodeType(Barcode128.CODE128);
            PdfFormXObject xObject = code128.CreateFormXObject(ColorConstants.BLACK,
                                                               ColorConstants.BLACK, pdfDoc);

            float x      = 36;
            float y      = 750;
            float width  = xObject.GetWidth();
            float height = xObject.GetHeight();

            // Draw the rectangle with set background color and add the created barcode object.
            PdfCanvas canvas = new PdfCanvas(pdfDoc.AddNewPage());

            canvas.SaveState();
            canvas.SetFillColor(ColorConstants.LIGHT_GRAY);
            canvas.Rectangle(x, y, width, height);
            canvas.Fill();
            canvas.RestoreState();
            canvas.AddXObjectAt(xObject, 36, 750);

            pdfDoc.Close();
        }
    protected void btnPreview_Click(object sender, EventArgs e)
    {
        if (itemsGrid.SelectedIndexes.Count == 0)
        {
            Master.ShowError("Select IRN to continue");
            return;
        }
        //////////////////////////////
        string irn = WebTools.GetExpr("IRN_NO", "PIP_PO_IRN", " WHERE IRN_ID='" + itemsGrid.SelectedValue + "'");

        irn = irn.Replace("/", "-");
        bool file_exist = System.IO.File.Exists(System.Web.Hosting.HostingEnvironment.MapPath("~/ImgFolder/"
                                                                                              + irn + ".gif"));

        Context.Response.ContentType = "image/gif";
        if (irn.Length > 0 && !file_exist)
        {
            Barcode128 code128 = new Barcode128();
            code128.CodeType         = Barcode.CODE128;
            code128.ChecksumText     = true;
            code128.GenerateChecksum = true;
            code128.Code             = irn;
            System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
            bm.Save(Context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
            bm.Save(System.Web.Hosting.HostingEnvironment.MapPath("~/ImgFolder/"
                                                                  + irn + ".gif"));
        }

        //////////////////////////////////

        Response.Redirect("ReportViewer.aspx?Arg1=" + itemsGrid.SelectedValue + "&ReportID=1");
    }
示例#10
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);
        }
示例#11
0
        public Image GetCode128Img(string source, int?height)
        {
            //Code128Helper cHelper = new Code128Helper();
            //if (height != null)
            //    cHelper.Height = (uint)height.Value;
            //cHelper.ValueFont = new System.Drawing.Font("宋体", 10);

            //System.Drawing.Bitmap img = cHelper.GetCodeImage(source, Code128Helper.Encode.Code128B);

            ////img = new System.Drawing.Bitmap(img, new System.Drawing.Size(100,9));

            Barcode128 code128 = new Barcode128();

            code128.CodeType         = Barcode.CODE128;
            code128.ChecksumText     = true;
            code128.GenerateChecksum = true;
            code128.Code             = source;
            if (height != null)
            {
                code128.BarHeight = height.Value;
            }


            System.Drawing.Bitmap img = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
            //bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);


            return(Image.GetInstance(img, System.Drawing.Imaging.ImageFormat.Gif));
        }
示例#12
0
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        Image img = new Image();                                                 // instantiating the control

        img.Attributes["src"] = Barcode128.generateBarcode(txtCode.Text, false); // setting the path to the image
        plBarCode.Controls.Add(img);
    }
示例#13
0
        public static string Encode128AB(string BarCodeData, string BarCodeName, Barcode128 Subset)
        {
            //Encode BarCodeData for 128 barcode printing
            string sBarCode = "", sBarCodeEncoded = "";

            BarCodeData = BarCodeData.Trim();
            Debug.Write("BarCodeData=" + BarCodeData);
            sBarCodeEncoded = Encode(BarCodeData, BarCodeName, Subset);
            Debug.Write("\t" + sBarCodeEncoded);
            //Build ouput string; trailing space is for Windows rasterization bug
            switch (BarCodeName)
            {
            case "Code128A":
                switch (Subset)
                {
                case Barcode128.A: sBarCode = Char.ToString(RE_START128_A) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 103) + Char.ToString(RE_STOP128); break;

                case Barcode128.B: sBarCode = Char.ToString(RE_START128_B) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 104) + Char.ToString(RE_STOP128); break;

                case Barcode128.C: sBarCode = Char.ToString(RE_START128_C) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 105) + Char.ToString(RE_STOP128); break;
                }
                break;

            case "Bar Sample 128AB":
                switch (Subset)
                {
                case Barcode128.A: sBarCode = Char.ToString(ELF_START128_A) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 103) + Char.ToString(ELF_STOP128); break;

                case Barcode128.B: sBarCode = Char.ToString(ELF_START128_B) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 104) + Char.ToString(ELF_STOP128); break;

                case Barcode128.C: sBarCode = Char.ToString(ELF_START128_C) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 105) + Char.ToString(ELF_STOP128); break;
                }
                break;

            case "Bar Sample 128AB HR":
                switch (Subset)
                {
                case Barcode128.A: sBarCode = Char.ToString(ELF_START128_A) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 103) + Char.ToString(ELF_STOP128); break;

                case Barcode128.B: sBarCode = Char.ToString(ELF_START128_B) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 104) + Char.ToString(ELF_STOP128); break;

                case Barcode128.C: sBarCode = Char.ToString(ELF_START128_C) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 105) + Char.ToString(ELF_STOP128); break;
                }
                break;

            case "IDAutomationSC128S":
                switch (Subset)
                {
                case Barcode128.A: sBarCode = Char.ToString(IDA_START128_A) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 103) + Char.ToString(IDA_STOP128); break;

                case Barcode128.B: sBarCode = Char.ToString(IDA_START128_B) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 104) + Char.ToString(IDA_STOP128); break;

                case Barcode128.C: sBarCode = Char.ToString(IDA_START128_C) + sBarCodeEncoded + CalcChecksum(BarCodeData, Subset, 105) + Char.ToString(IDA_STOP128); break;
                }
                break;
            }
            Debug.Write("\t" + sBarCode + "\n");
            return(sBarCode);
        }
示例#14
0
        private void frmToaThuocDV_Load(object sender, EventArgs e)
        {
            string idkhambenh = GetIdkhambenh();
            string MaBN       = "";

            try
            {
                KhamBenhPro.rptToaThuocDV crystalReport3 = new KhamBenhPro.rptToaThuocDV();
                DataTable dtsrc     = dtSource(idkhambenh);
                DateTime  Ngayratoa = DateTime.Parse(dtsrc.Rows[0]["ngayratoa"].ToString());
                if (dtsrc == null)
                {
                    MessageBox.Show("Không có toa thuốc bảo hiểm");
                }
                else
                {
                    dtsrc.TableName = "dtThuoc";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dtsrc);
                    MaBN = dtsrc.Rows[0]["mabenhnhan"].ToString();
                    #region ma vach
                    Barcode128 barcode = new Barcode128();
                    barcode.ChecksumText = false;
                    barcode.Code         = MaBN;
                    //barcode.Code = MaPhieuCLS.Replace("PT", "").Replace("-", "").Replace("CT", "") + "";
                    System.Drawing.Image bmp = barcode.CreateDrawingImage(Color.Black, Color.White);
                    Byte[] arrByte           = (Byte[])TypeDescriptor.GetConverter(bmp).ConvertTo(bmp, typeof(Byte[]));
                    for (int k = 0; k < dtsrc.Rows.Count; k++)
                    {
                        dtsrc.Rows[k]["MaVach"] = arrByte;
                    }
                    #endregion
                    crystalReport3.SetDataSource(ds);
                    crystalReport3.SetParameterValue("TenBacsi", dtsrc.Rows[0]["tenbacsi"].ToString());
                    crystalReport3.SetParameterValue("MaBN", dtsrc.Rows[0]["mabenhnhan"].ToString());
                    crystalReport3.SetParameterValue("TuoiBN", dtsrc.Rows[0]["TuoiBN"].ToString());
                    crystalReport3.SetParameterValue("CanNang", dtsrc.Rows[0]["cannang"].ToString());
                    crystalReport3.SetParameterValue("HuyetAp1", dtsrc.Rows[0]["huyetap1"].ToString());
                    crystalReport3.SetParameterValue("HuyetAp2", dtsrc.Rows[0]["huyetap2"].ToString());
                    if (dtsrc.Rows[0]["NguoiGiamHo"].ToString() == "")
                    {
                        crystalReport3.SetParameterValue("TenNguoiGiamHo", "");
                    }
                    else
                    {
                        crystalReport3.SetParameterValue("TenNguoiGiamHo", "- Tên bố hoặc mẹ của trẻ hoặc người đưa trẻ đến khám bệnh, chữa bệnh :" + dtsrc.Rows[0]["NguoiGiamHo"].ToString());
                    }
                    crystalReport3.SetParameterValue("Mach", dtsrc.Rows[0]["mach"].ToString());
                    crystalReport3.SetParameterValue("GhiChu", dtsrc.Rows[0]["GhiChu"].ToString());
                    crystalReport3.SetParameterValue("LoiDan", dtsrc.Rows[0]["loidan"].ToString());
                    crystalReport3.SetParameterValue("NgayKham", "Ngày " + Ngayratoa.ToString("dd") + " tháng " + Ngayratoa.ToString("MM") + " năm " + Ngayratoa.ToString("yyyy") + "");
                    nvk_SetPara_HanhChinh(dtsrc.Rows[0]["idbenhnhan"].ToString(), dtsrc.Rows[0]["idchitietdangkykham"].ToString(), idkhambenh, crystalReport3);
                    crystalReportViewer1.ReportSource = crystalReport3;
                }
            }
            catch {
                MessageBox.Show("Không có toa DV");
            }
        }
        /// <summary>
        /// Generate a barcode based on the string passed to the method
        /// </summary>
        /// <param name="barcodeSource">string to convert to barcode</param>
        /// <returns>return a barcode image based in the parameter.</returns>
        public Image GenerateBarcode(string barcodeSource)
        {
            Barcode128 barcode128 = new Barcode128 {
                Code = barcodeSource
            };

            return(barcode128.CreateDrawingImage(Color.Black, Color.White));
        }
示例#16
0
        public System.Drawing.Image GerarBarcode(string code)
        {
            Barcode128 bc = new Barcode128();

            bc.Code = code;
            //bc.Font = null;

            return(bc.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
        }
示例#17
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();
        }
示例#18
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);
        }
示例#19
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);
        }
示例#20
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();
        }
示例#21
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);
        }
示例#22
0
        /// <summary>
        /// Создать объект штрих кода по типу и самому коду.
        /// </summary>
        /// <param name="type">Тип кода, поддерживаются Barcode.EAN8, Barcode.EAN13, Barcode.CODE128</param>
        /// <param name="code">Содержание кода</param>
        /// <returns></returns>
        private static Barcode CreateBarcode(string type, string code, bool displayText = true, float barHeight = 0)
        {
            Barcode barcode = null;

            switch (type)
            {
            case BarcodeType.Ean8:
            {
                barcode          = new BarcodeEAN();
                barcode.CodeType = Barcode.EAN8;
                barcode.Code     = AddEANCheckSum(code, 8);
                break;
            }

            case BarcodeType.Ean13:
            {
                barcode          = new BarcodeEAN();
                barcode.CodeType = Barcode.EAN13;
                barcode.Code     = AddEANCheckSum(code, 13);
                break;
            }

            case BarcodeType.Code128:
            case BarcodeType.Ean128:
            {
                barcode                  = new Barcode128();
                barcode.Code             = code;
                barcode.ChecksumText     = true;
                barcode.GenerateChecksum = true;
                barcode.StartStopText    = true;
                break;
            }

            default:
                throw new System.Exception("Not supported barcode type");
            }

            // Установим дополнительные параметры
            if (barHeight > 0)
            {
                barcode.BarHeight = barHeight; // Высота одной полоски
            }
            if (displayText == false)
            {
                barcode.Font = null; // no text
            }
            // barcode.X = 5; // длина 1-й полоски
            // barcode.Size = 8; // размер шрифта

            return(barcode);
        }
        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);
        }
        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);
        }
示例#25
0
        public System.Drawing.Image codigob(string codigo, Boolean Contexto = false, Single alto = 0, String texto = "")
        {
            Barcode128 barcode = new Barcode128();

            barcode.StartStopText = true;
            if (alto != 0)
            {
                barcode.BarHeight = alto;
            }


            barcode.Code         = codigo;
            barcode.ChecksumText = true;
            barcode.CodeType     = BarcodeEANSUPP.UPCA;

            try
            {
                String letras;
                letras = codigo + "\n" + texto;
                Size talla = new Size();
                talla.Width  = 200;
                talla.Height = 75;
                Bitmap bm = new Bitmap(barcode.CreateDrawingImage(Color.Black, Color.White), talla);
                System.Drawing.Image bmt = new Bitmap(bm.Width, bm.Height + 14);
                Graphics             g   = Graphics.FromImage(bmt);
                SolidBrush           bru = new SolidBrush(Color.White);
                g.FillRectangle(bru, 0, 0, bm.Width, bm.Height + 14);
                System.Drawing.Font PintarTexto = new System.Drawing.Font("arial", 10);
                SolidBrush          brocha      = new SolidBrush(Color.Black);
                SizeF stringsize;
                stringsize = g.MeasureString(codigo, PintarTexto);
                float centrox;
                centrox = (bm.Width - stringsize.Width) / 2;
                float x;
                float y;
                x = centrox;
                y = bm.Height;
                StringFormat drawformat = new StringFormat();
                drawformat.FormatFlags = StringFormatFlags.NoWrap;
                g.DrawImage(bm, 0, 0);
                string ncode = codigo.Substring(1, codigo.Length - 2);
                g.DrawString(codigo, PintarTexto, brocha, x, y, drawformat);
                return(bmt);
            }
            catch (Exception ex)
            {
                throw new Exception("Error al genera el codigo:" + ex.ToString());
            }
        }
示例#26
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);
                }
            }
        }
示例#27
0
 public System.Drawing.Bitmap GenerarBarcode(string prodCode)
 {
     if (prodCode.Length > 0)
     {
         Barcode128 code128 = new Barcode128();
         code128.CodeType         = Barcode.CODE128;
         code128.ChecksumText     = true;
         code128.GenerateChecksum = true;
         code128.StartStopText    = true;
         code128.Code             = prodCode;
         System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
         return(bm);
     }
     return(null);
 }
示例#28
0
        private void BarcodeGenerator(string id)
        {
            string prodCode = id;

            //context.Response.ContentType = "image/gif";
            if (prodCode.Length > 0)
            {
                Barcode128 code128 = new Barcode128();
                code128.CodeType         = Barcode.CODE128;
                code128.ChecksumText     = true;
                code128.GenerateChecksum = true;
                code128.Code             = prodCode;
                System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
                bm.Save(HttpContext.Current.Server.MapPath("~/PDF/" + id + ".gif"), System.Drawing.Imaging.ImageFormat.Gif);
            }
        }
示例#29
0
        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document    doc    = new Document(pdfDoc);
            String      code   = "675-FH-A12";

            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth();

            table.AddCell("Change baseline:");

            Barcode128 code128 = new Barcode128(pdfDoc);

            // If value is positive, the text distance under the bars. If zero or negative,
            // the text distance above the bars.
            code128.SetBaseline(-1);
            code128.SetSize(12);
            code128.SetCode(code);
            code128.SetCodeType(Barcode128.CODE128);
            Image code128Image = new Image(code128.CreateFormXObject(pdfDoc));

            // Notice that in iText5 in default PdfPCell constructor (new PdfPCell(Image img))
            // this image does not fit the cell, but it does in addCell().
            // In iText7 there is no constructor (new Cell(Image img)),
            // so the image adding to the cell can be done only using method add().
            Cell cell = new Cell().Add(code128Image);

            table.AddCell(cell);
            table.AddCell("Add text and bar code separately:");

            code128 = new Barcode128(pdfDoc);

            // Suppress the barcode text
            code128.SetFont(null);
            code128.SetCode(code);
            code128.SetCodeType(Barcode128.CODE128);

            // Let the image resize automatically by setting it to be autoscalable.
            code128Image = new Image(code128.CreateFormXObject(pdfDoc)).SetAutoScale(true);
            cell         = new Cell();
            cell.Add(new Paragraph("PO #: " + code));
            cell.Add(code128Image);
            table.AddCell(cell);

            doc.Add(table);

            doc.Close();
        }
示例#30
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));
        }