Ejemplo n.º 1
63
// ===========================================================================
    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);        
      }
    }
Ejemplo n.º 2
2
    /// <summary>
    /// this version outputs gif to web page
    /// ProcessRequest is intrinsic function of hppthandler, do not change the name
    /// </summary>
    /// <param name="context"></param>
    public void ProcessRequest(HttpContext context)
    {
        //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" />
        //
        if(context.Request["code"] != null){

            string _code = wwi_security.DecryptString(context.Request["code"].ToString(),"publiship"); //code to use
            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

            Barcode128 _bc = new Barcode128();
            _bc.CodeType = Barcode.CODE128;
            _bc.ChecksumText = true;
            _bc.GenerateChecksum = true;
            _bc.Code = _code;

            //draws directly to web page with no code underneath bar
            //System.Drawing.Bitmap _bm = new System.Drawing.Bitmap(_bc.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
            //_bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);

            //draws with actual code underneath bar
            //create bitmap from System.Drawing library, add some height for actual code underneath
            Bitmap _bm = new Bitmap(_wd, _ht + 10);
            //provide this, else the background will be black by default
            Graphics _gr = Graphics.FromImage(_bm);
            
            _gr.PageUnit = GraphicsUnit.Pixel;
            _gr.Clear(Color.White); 
            //draw the barcode
            _gr.DrawImage(_bc.CreateDrawingImage(Color.Black, System.Drawing.Color.White), new Point(0,0));
            //place text underneath - if you want the placement to be dynamic, calculate the point based on size of the image
            System.Drawing.Font _ft = new System.Drawing.Font("Arial", 8, FontStyle.Regular);
            SizeF _sz = _gr.MeasureString(_code, _ft); 
            //position text
            _wd = (_wd - (int)_sz.Width) / 2;
            
            StringFormat _sf = new StringFormat();
            _sf.Alignment = StringAlignment.Center;
            _sf.LineAlignment = StringAlignment.Center;

            _gr.DrawString(_code, _ft, SystemBrushes.WindowText,_wd,_ht, _sf);
            //output as gif to web page,  can also save it to external file
            _bm.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        }//end if
    }
Ejemplo n.º 3
1
        public Bitmap box(string prodCode, string urun, string renk, string numara, string nakitFiyat, string krediFiyat)
        {
            System.Drawing.Bitmap bmpimg;

            Barcode128 code128 = new Barcode128();
            code128.CodeType = iTextSharp.text.pdf.Barcode.CODE128;
            code128.ChecksumText = true;
            code128.GenerateChecksum = true;
            code128.StartStopText = false;
            code128.Code = prodCode;
            code128.BarHeight = 60;

            bmpimg = new Bitmap(130, 150);

            Graphics bmpgraphics = Graphics.FromImage(bmpimg);
            Pen pen = new Pen(Color.Black, 3.0f);
            System.Drawing.Rectangle rec = new System.Drawing.Rectangle(92, 2, 32, 27);
            bmpgraphics.Clear(Color.White);

            bmpgraphics.DrawRectangle(pen, rec);
            bmpgraphics.DrawString(urun, new System.Drawing.Font("Arial", 9, FontStyle.Bold), SystemBrushes.WindowText, new Point(8, 4));
            bmpgraphics.DrawString(renk, new System.Drawing.Font("Arial", 8, FontStyle.Regular), SystemBrushes.WindowText, new Point(8, 18));
            bmpgraphics.DrawString(numara, new System.Drawing.Font("Arial", 15, FontStyle.Bold), SystemBrushes.WindowText, new Point(95, 5));
            bmpgraphics.DrawImage(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White), new Point(10, 40));

            bmpgraphics.DrawString(prodCode, new System.Drawing.Font("Arial", 7, FontStyle.Regular), SystemBrushes.WindowText, new Point(30, 102));
            bmpgraphics.DrawString("Nakit:" + nakitFiyat + " TL", new System.Drawing.Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(15, 114));
            bmpgraphics.DrawString("Kredi:" + krediFiyat + " TL", new System.Drawing.Font("Arial", 12, FontStyle.Bold), SystemBrushes.WindowText, new Point(15, 132));
            //pictureBox1.Image = bmpimg;

            return bmpimg;
        }
        // Tuotteen lisäys nappulan koodit
        private void btn_add_prod_Click(object sender, RoutedEventArgs e)
        {
            Random rnd = new Random();                                                                          // Random num generaattori
            string random_barcode = rnd.Next(10000000, 99999999).ToString(); // Tehdään barcode random numerolla

            // Luodaan barcode
               Barcode128 code128 = new Barcode128();
            code128.CodeType = Barcode.CODE128_UCC;
            code128.Code = random_barcode;

            // Generoidaan barcode png image /barcodes hakemistoon
            System.Drawing.Bitmap barcode = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));  // Mustaa valkoiselle
            barcode.Save("barcodes/"+random_barcode+".png");    // Tallennetaan /barcodes hakemistoon

            // Ihan samat SQL Connectionit kun aina.
            string dbConnectionString = @"Data Source=database.db;Version=3;";
            SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString);
            if (tb_name_update.Text != "" && tb_brand_update.Text != "" && tb_qty_update.Text != "")    // Jos nimi, brändi ja määrä kentät EIvät ole tyhjiä niin eteenpäin. (Muuten tulee vähän huono tuotemerkintä.)
            {
                try
                {
                    sqliteCon.Open();
                    string Query = "INSERT INTO products (name, brand, price, qty, desc, barcode) VALUES('" + this.tb_name_update.Text + "','" + this.tb_brand_update.Text + "','" + this.tb_price_update.Text + "','" + this.tb_qty_update.Text + "','" + this.tb_desc_update.Text + "','"+random_barcode+"') ";

                    SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon);
                    createCommand.ExecuteNonQuery();

                    sqliteCon.Close();                                                  // Sinne vaan pusketaan tiedot taas tietokantaan ja näytetään käyttäjälle ilmoitus ja suljetaan db-yhteys.
                    MessageBox.Show("Product added successfully!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                                                                                        // Kun tiedot on uploadattu niin päivitetäänpä samalla vaivalla datagrid niin ei pysyy käyttäjäkin ajan tasalla.
                updateGrid();

            }
        }
 //**********************************************************************************
 //Generar un nuevo codigo de barras
 public Bitmap GenerarCodBarras(string codParaGenerar)
 {
     Barcode128 codigo_barras = new Barcode128();
     codigo_barras.CodeType = Barcode128.CODE128;
     codigo_barras.Code = codParaGenerar;
     codigo_barras.AltText = codParaGenerar;
     codigo_barras.TextAlignment = Barcode128.SHIFT;
     Bitmap codigo_barras_completo = new Bitmap(codigo_barras.CreateDrawingImage(Color.Black, Color.White));
     return codigo_barras_completo;
 }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
 public Image GeneraBarcode128(PdfContentByte pdfContentByte, string codigo, bool extendido, int tipoCodigo)
 {
     Barcode128 code128 = new Barcode128 { Code = codigo, Extended = extendido, CodeType = tipoCodigo };
     return code128.CreateImageWithBarcode(pdfContentByte, null, null);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the barcode128.
 /// </summary>
 /// <param name="pdfContentByte">The PDF content byte.</param>
 /// <param name="code">The code.</param>
 /// <param name="extended">if set to <c>true</c> [extended].</param>
 /// <param name="codeType">Type of the code.</param>
 /// <returns>Barcode image.</returns>
 public Image GetBarcode128(PdfContentByte pdfContentByte, string code, bool extended, int codeType)
 {
     Barcode128 code128 = new Barcode128 { Code = code, Extended = extended, CodeType = codeType };
     return code128.CreateImageWithBarcode(pdfContentByte, null, null);
 }
        /// <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();
                SettingsBll BllSettings = new SettingsBll();
                Info = BllBarcodeSettings.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 CurrencyBll().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", "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("BCP5:" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            finally
            {
                try
                {
                    pdfdoc.Close();
                }
                catch
                {
                }
            }
        }
Ejemplo n.º 10
0
        //, StreamWriter strWriter)
        static void addCuponDePago(Document doc, PdfWriter writer, ExpensasEdificio expensa, TotalUnidad unidad, DateTime vto1, DateTime vto2)
        {
            PdfPTable t = new PdfPTable(4);
            t.WidthPercentage = 85;
            float[] widths = new float[] { 30f, 25f, 40f, 30f };
            t.SetWidths(widths);
            double importe1 = 0;
            double importe2 = 0;

            foreach (Totales total in unidad.TotalSector) //CatalogoExpensas.getTotales(edificio, unidad, periodo))
            {
                importe1 += total.corresponde;
            }

            importe1 += unidad.Exclusivos;
            importe1 += unidad.Varios;
            importe1 += unidad.Legales;
            importe1 += unidad.Deuda + unidad.Recargo;

            importe2 = importe1 * (1 + (Double)expensa.Tasa2Vto / 100);

            if (expensa.ImporteVto1 > 0 && expensa.ImporteVto2 > 0)
            {
                importe1 = expensa.ImporteVto1;
                importe2 = expensa.ImporteVto2;
            }

            string codigoEmpresa = "0954";
            string nroReferencia = completarCadena(Math.Abs((expensa.Edificio.direccion.ToLower() + unidad.Unidad.id_unidad.Replace("-", "")).GetHashCode()).ToString(), 12, "0");
            string nroFactura = completarCadena(unidad.NroFactura, 15, "0");
            string fechaVto = getFechaCsv(vto1).Replace("/", ""); // vto1.ToShortDateString().Replace("/", "");
            string parametroFijo = "0400";
            string fechaVtoCB = vto1.ToShortDateString().Replace("/", "");
            string codigo = codigoEmpresa + nroReferencia + nroFactura + fechaVtoCB + parametroFijo + codigoEmpresa;
            string digitoVerificador = getDigitoVerificador(codigo).ToString();
            codigo += digitoVerificador;

            Paragraph p;

            int leading = 9;
            PdfPCell totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "Cupón de pago", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "Red Banelco", calibri11B);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "www.pagomiscuentas.com", calibri11B);
            p.Alignment = Element.ALIGN_CENTER;
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, " ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

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

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, " ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "Código Electrónico : ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, nroReferencia, calibri11B);
            p.Alignment = Element.ALIGN_CENTER;
            totalesSector.HorizontalAlignment = Element.ALIGN_CENTER;
            totalesSector.AddElement(p);

            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, " ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

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

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, " ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "VTO 1 : " + vto1.ToShortDateString(), calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "$ " + importe1.ToString("n2"), calibri11B);
            p.Alignment = Element.ALIGN_CENTER;
            totalesSector.HorizontalAlignment = Element.ALIGN_CENTER;
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, " ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

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

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, " ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "VTO 2 : " + vto2.ToShortDateString(), calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, "$ " + importe2.ToString("n2"), calibri11B);
            p.Alignment = Element.ALIGN_CENTER;
            totalesSector.HorizontalAlignment = Element.ALIGN_CENTER;
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);

            totalesSector = new PdfPCell();
            totalesSector.Border = 0;
            totalesSector.PaddingTop = 6;
            p = new Paragraph(leading, " ", calibri11N);
            totalesSector.AddElement(p);
            t.AddCell(totalesSector);
            doc.Add(t);

            doc.Add(new Paragraph(10, " "));

            Barcode128 code128 = new Barcode128();
            code128.CodeSet = Barcode128.Barcode128CodeSet.C;
            code128.CodeType = Barcode128.CODE_C;
            code128.ChecksumText = true;
            code128.GenerateChecksum = true;
            code128.Code = codigo;

            PdfPCell codigoDeBarrasCell = new PdfPCell();
            codigoDeBarrasCell.AddElement(code128.CreateImageWithBarcode(writer.DirectContent, null, null));
            codigoDeBarrasCell.BorderWidth = 0;

            //StringBuilder sb = new StringBuilder("");
            //.Replace("\n\r", Environment.NewLine);
            string strAclaracion = "El pago del mes en emisión no implica libre deuda de la unidad.\r\nCarece de valor sin intervención de las entidades de cobro autorizadas.\r\nAl cierre de la presente pueden quedar operaciones sin registrar.";
            p = new Paragraph(10, strAclaracion, calibri9N);
            p.Alignment = Element.ALIGN_CENTER;
            codigoDeBarrasCell.AddElement(p);
            t = new PdfPTable(1);
            t.AddCell(codigoDeBarrasCell);
            t.WidthPercentage = 70;
            doc.Add(t);
        }
Ejemplo n.º 11
0
    /// <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;
    }
Ejemplo n.º 12
0
 public iTextSharp.text.Image GetBarcode128(PdfContentByte pdfContentByte, string code, bool extended, int codeType)
 {
     Barcode128 code128 = new Barcode128 { Code = code, Extended = extended, CodeType = codeType };
     code128.ChecksumText = true;
     return code128.CreateImageWithBarcode(pdfContentByte, null, null);
 }
Ejemplo n.º 13
0
        private void createEventSheet(int tournamentId, TournamentDivision tournamentDivision)
        {
            List<CompetitorDivision> competitorDivisions = db.CompetitorDivisions.Where(m => m.Competitor.TournamentId == tournamentId && m.DivisionId == tournamentDivision.DivisionId).ToList();

            PdfPTable headerTable = new PdfPTable(4);
            headerTable.HorizontalAlignment = Element.ALIGN_LEFT;
            headerTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
            headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
            headerTable.WidthPercentage = 100f;
            headerTable.SetWidths(new float[] { 10, 60, 15, 15 });

            headerTable.AddCell(Image.GetInstance(Server.MapPath("/Content/images/reportLogo.gif")));
            headerTable.AddCell(new Phrase(tournamentDivision.Division.DivisionName, fontH1));
            headerTable.AddCell("Ring No.:");

            PdfContentByte pdfContentByte = PDFWriter.DirectContent;
            Barcode128 code128 = new Barcode128 { Code = string.Format("*{0}*", tournamentDivision.DivisionId), Extended = false, CodeType = Barcode.CODE128/*, Font = null*/ };
            headerTable.AddCell(code128.CreateImageWithBarcode(pdfContentByte, null, null));

            document.Add(headerTable);

            if (tournamentDivision.Division.DivisionTypeId == WKSADBConstants.DivisionType_SparringId)
            {
                //document.SetMargins(27f, 27f, 27f, 27f);
                PdfPTable table = new PdfPTable(5);
                table.HorizontalAlignment = Element.ALIGN_LEFT;
                table.DefaultCell.Border = Rectangle.NO_BORDER;
                table.WidthPercentage = 100f;
                table.SpacingBefore = 5f;
                table.SpacingAfter = 5f;

                int byeCount = getByeCount(competitorDivisions.Count);

                PdfPCell cell = iTextSharpHelper.CreateCell(string.Format("Competitor List (division requires {0} bye{1})", byeCount, byeCount == 1 ? string.Empty : "s"), new Font(baseFont, 9, Font.BOLD), 0, Element.ALIGN_LEFT, null);
                cell.Colspan = 5;
                table.AddCell(cell);

                foreach (CompetitorDivision competitorDivision in competitorDivisions)
                {
                    table.AddCell(iTextSharpHelper.CreateCell(string.Format("{0} {1} ({2})", competitorDivision.Competitor.Student.FirstName, competitorDivision.Competitor.Student.LastName, competitorDivision.Competitor.Student.School.SchoolName), new Font(baseFont, 6), 0, Element.ALIGN_LEFT, null));
                }

                int remaining = competitorDivisions.Count % 5;
                for (int i = 0; i < 5 - remaining; i++)
                {
                    table.AddCell("");
                }

                document.Add(table);

                Image sparringTreeImage = Image.GetInstance(Server.MapPath("/Content/images/sparringtreev03.jpg"));
                // Have to scale as it's in 150dpi
                sparringTreeImage.ScalePercent(48f);
                document.Add(sparringTreeImage);

                //document.Add(CreateByeChartTable());
            }
            else
            {
                //document.SetMargins(36f, 36f, 36f, 36f);
                PdfPTable table = new PdfPTable(13);
                table.HorizontalAlignment = Element.ALIGN_LEFT;
                table.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
                table.DefaultCell.PaddingTop = 10f;
                table.WidthPercentage = 100f;
                table.SetWidths(new float[] { 30, 2, 8, 2, 8, 2, 8, 2, 8, 2, 8, 2, 8 });
                table.SpacingBefore = 20f;

                PdfPCell gapCell = new PdfPCell();
                gapCell.Rowspan = competitorDivisions.Count() + 1;
                gapCell.Border = 0;

                table.AddCell(iTextSharpHelper.CreateCell(string.Empty, new Font(baseFont, 9), 0, Element.ALIGN_CENTER, null));
                table.AddCell(gapCell);
                table.AddCell(iTextSharpHelper.CreateCell("Judge 1", new Font(baseFont, 9), 0, Element.ALIGN_CENTER, null));
                table.AddCell(gapCell);
                table.AddCell(iTextSharpHelper.CreateCell("Judge 2", new Font(baseFont, 9), 0, Element.ALIGN_CENTER, null));
                table.AddCell(gapCell);
                table.AddCell(iTextSharpHelper.CreateCell("Judge 3", new Font(baseFont, 9), 0, Element.ALIGN_CENTER, null));
                table.AddCell(gapCell);
                table.AddCell(iTextSharpHelper.CreateCell("Judge 4", new Font(baseFont, 9), 0, Element.ALIGN_CENTER, null));
                table.AddCell(gapCell);
                table.AddCell(iTextSharpHelper.CreateCell("Judge 5", new Font(baseFont, 9), 0, Element.ALIGN_CENTER, null));
                table.AddCell(gapCell);
                table.AddCell(iTextSharpHelper.CreateCell("Total", new Font(baseFont, 9, Font.BOLD), 0, Element.ALIGN_CENTER, null));

                // Randomise Competitors
                competitorDivisions.Shuffle();
                foreach (CompetitorDivision competitorDivision in competitorDivisions)
                {
                    table.AddCell(string.Format("{0} {1}", competitorDivision.Competitor.Student.FirstName, competitorDivision.Competitor.Student.LastName));
                    table.AddCell(string.Empty);
                    table.AddCell(string.Empty);
                    table.AddCell(string.Empty);
                    table.AddCell(string.Empty);
                    table.AddCell(string.Empty);
                    table.AddCell(string.Empty);
                }

                document.Add(table);
            }
        }