A Cell is a Rectangle containing other Elements.
A Cell is a Rectangle containing other Elements.

A Cell must be added to a Table. The Table will place the Cell in a Row.

상속: Rectangle, ITextElementArray
예제 #1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Page.Title = "Contact List";
            MemoryStream PDFData = new MemoryStream();

            // step 1: creation of a document-object
            Document document = new Document();

            // step 2:
            // we create a writer that listens to the document
            // and directs a PDF-stream to a file

            PdfWriter.GetInstance(document, PDFData);

            // step 3: we open the document
            document.Open();

            // step 4: we add a paragraph to the document
            document.Add(new Paragraph(DateTime.Now.ToString()));
            Contact oContact = new Contact();
            DataTable dtContact = oContact.LoadAll();
            int numRow = dtContact.Rows.Count;
            int numCol = 5;
            iTextSharp.text.Table aTable = new iTextSharp.text.Table(numCol, numRow);
            aTable.AutoFillEmptyCells = true;
            aTable.Padding = 1;
            aTable.Spacing = 1;

            Cell cell = new Cell(new Phrase("Contact List", FontFactory.GetFont(FontFactory.TIMES, 14, Font.BOLD)));
            cell.Header = true;
            cell.Colspan = numCol;
            cell.BackgroundColor = Color.LIGHT_GRAY;
            cell.HorizontalAlignment = Element.ALIGN_CENTER;

            aTable.AddCell(cell);

            for (int i = 0; i < dtContact.Rows.Count; i++)
            {
                for (int n = 1; n <= numCol; n++)
                    aTable.AddCell(dtContact.Rows[i][n].ToString());

            }
            document.Add(aTable);
            // step 5: we close the document
            document.Close();

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.ContentType = "application/pdf";
            Response.Charset = string.Empty;
            Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
            Response.AddHeader("Content-Disposition",
                "attachment; filename=" + Title.Replace(" ", "").Replace(":", "-") + ".pdf");

            Response.OutputStream.Write(PDFData.GetBuffer(), 0, PDFData.GetBuffer().Length);
            Response.OutputStream.Flush();
            Response.OutputStream.Close();
            Response.End();
        }
예제 #2
0
 public static Cell GetCellRight(string value)
 {
     Cell result = new Cell(new Paragraph(value, fontContent));
     result.HorizontalAlignment = Element.ALIGN_RIGHT;
     result.VerticalAlignment = Element.ALIGN_MIDDLE;
     return result;
 }
예제 #3
0
 public static Cell GetFooterCellLeft(string value)
 {
     Cell result = new Cell(new Paragraph(value, fontTableFooter));
     result.HorizontalAlignment = Element.ALIGN_LEFT;
     result.VerticalAlignment = Element.ALIGN_MIDDLE;
     result.BackgroundColor = new Color(234, 234, 234);
     return result;
 }
예제 #4
0
 public static Cell GetTitleCellRight(string value)
 {
     Cell result = new Cell(new Paragraph(value, fontTableTitle));
     result.HorizontalAlignment = Element.ALIGN_RIGHT;
     result.VerticalAlignment = Element.ALIGN_MIDDLE;
     result.BackgroundColor = new Color(127, 127, 127);
     return result;
 }
        //        public static SimpleAttendanceList GetInstance(Selection selection,
        //                                                       Rectangle pageSize,
        //                                                       string reportFile) {
        //            
        //            if (instance == null)
        //                instance = new SimpleAttendanceList(selection, pageSize, reportFile);
        //            else {
        //                instance.selection = selection;
        //                instance.reportFile = reportFile;
        //            }
        //            
        //            if (!this.doc.IsOpen())
        //                this.doc.Open();
        //            
        //            return instance;
        //        }
        public override void MakeReport()
        {
            // Subtitle = Event name
            Chunk c = new Chunk(this.selection.Events[0].Name,
                                FontFactory.GetFont(FontFactory.HELVETICA, 14, Font.BOLD));
            Paragraph par = new Paragraph(c);
            par.Alignment = Rectangle.ALIGN_CENTER;

            this.doc.Add(par);

            // List
            Table t = new Table(2);
            t.Border = 0;
            t.DefaultCellBorder = 0;

            Cell cell = new Cell();
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            t.DefaultCell = cell; // Default cell

            Font fuenteTitulo = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 14, Font.UNDERLINE);

            cell = new Cell();
            Chunk texto = new Chunk("Nombre y Apellido", fuenteTitulo);
            cell.Add(texto);
            t.AddCell(cell);

            cell = new Cell();
            texto = new Chunk("¿Asistió?", fuenteTitulo);
            cell.Add(texto);
            t.AddCell(cell);

            Font fuenteDatos = FontFactory.GetFont(FontFactory.HELVETICA, 10);

            Font fuenteSi = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10);
            fuenteSi.Color = Color.BLUE;

            Font fuenteNo = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10);
            fuenteNo.Color = Color.RED;

            foreach (Person p in this.selection.Persons) {
                cell = new Cell();
                texto = new Chunk(p.Name + " " + p.Surname, fuenteDatos);
                cell.Add(texto);
                t.AddCell(cell);

                cell = new Cell();

                if (AttendancesManager.Instance.Attended(p, this.selection.Events[0]))
                    texto = new Chunk("Si", fuenteSi);
                else
                    texto = new Chunk("No", fuenteNo);

                cell.Add(texto);
                t.AddCell(cell);
            }

            this.doc.Add(t);
        }
예제 #6
0
        //        
        //        public static SimplePersonsList GetInstance(Selection selection,
        //                                                    Rectangle pageSize,
        //                                                    string reportFile) {
        //            
        //            if (instance == null)
        //                instance = new SimplePersonsList(selection, pageSize, reportFile);
        //            else {
        //                instance.selection = selection;
        //                instance.reportFile = reportFile;
        //            }
        //            
        //            if (!this.doc.IsOpen())
        //                this.doc.Open();
        //            
        //            return instance;
        //        }
        public override void MakeReport()
        {
            Table t = new Table(3);
            t.Border = 0;
            t.DefaultCellBorder = 0;

            Cell cell = new Cell();
            cell.HorizontalAlignment = Element.ALIGN_CENTER;
            t.DefaultCell = cell; // Default cell

            Font fuenteTitulo = FontFactory.GetFont(FontFactory.HELVETICA_OBLIQUE, 14, Font.UNDERLINE);

            cell = new Cell();
            Chunk texto = new Chunk("Apellido", fuenteTitulo);
            cell.Add(texto);
            t.AddCell(cell);

            cell = new Cell();
            texto = new Chunk("Nombre", fuenteTitulo);
            cell.Add(texto);
            t.AddCell(cell);

            cell = new Cell();
            texto = new Chunk("E-Mail", fuenteTitulo);
            cell.Add(texto);
            t.AddCell(cell);

            Font fuenteDatos = FontFactory.GetFont(FontFactory.HELVETICA, 10);

            foreach (Person p in this.selection.Persons) {
                cell = new Cell();
                texto = new Chunk(p.Surname, fuenteDatos);
                cell.Add(texto);
                t.AddCell(cell);

                cell = new Cell();
                texto = new Chunk(p.Name, fuenteDatos);
                cell.Add(texto);
                t.AddCell(cell);

                cell = new Cell();
                texto = new Chunk(p.EMail, fuenteDatos);
                cell.Add(texto);
                t.AddCell(cell);
            }

            this.doc.Add(t);
        }
 public void SetCell( int col, int row, Phrase phrase, Alignment alignment )
 {
     Cells[col, row] = new Cell( phrase, alignment );
 }
예제 #8
0
파일: Row.cs 프로젝트: hjgode/iTextSharpCF
        /// <summary>
        /// Deletes a certain column has been deleted.
        /// </summary>
        /// <param name="column">the number of the column to delete</param>
        internal void DeleteColumn(int column)
        {
            if ((column >= columns) || (column < 0)) {
                throw new Exception("getCell at illegal index : " + column);
            }
            columns--;
            bool[] newReserved = new bool[columns];
                Object[] newCells = new Cell[columns];

                    for (int i = 0; i < column; i++) {
                        newReserved[i] = reserved[i];
                        newCells[i] = cells[i];
                        if (newCells[i] != null && (i + ((Cell) newCells[i]).Colspan > column)) {
                            ((Cell) newCells[i]).Colspan = ((Cell) cells[i]).Colspan - 1;
                        }
                    }
            for (int i = column; i < columns; i++) {
                newReserved[i] = reserved[i + 1];
                newCells[i] = cells[i + 1];
            }
            if (cells[column] != null && ((Cell) cells[column]).Colspan > 1) {
                newCells[column] = cells[column];
                ((Cell) newCells[column]).Colspan = ((Cell) newCells[column]).Colspan - 1;
            }
            reserved = newReserved;
            cells = newCells;
        }
        private void EscrevaProcessosNoDocumentoAnalitico()
        {
            var tabela = new Table(6);

            tabela.Widths = new Single[] { 60, 100, 50, 100, 60, 100 };

            tabela.Padding = 0;
            tabela.Spacing = 0;
            tabela.Width = 100;
            tabela.AutoFillEmptyCells = true;

            tabela.EndHeaders();

            foreach (var processo in _processos)
            {
                var labelNumeroProcesso =
                    new Cell(new Phrase("Número do processo: ", _Fonte2));

                labelNumeroProcesso.DisableBorderSide(0);

                tabela.AddCell(labelNumeroProcesso);

                var valorNumeroProcesso =
                    new Cell(new Phrase(processo.Processo.ToString(), _Fonte1));

                valorNumeroProcesso.DisableBorderSide(0);

                tabela.AddCell(valorNumeroProcesso);

                var labelDataDoCadastro = new Cell(new Phrase("Data do cadastro: ", _Fonte2));

                labelDataDoCadastro.DisableBorderSide(0);

                tabela.AddCell(labelDataDoCadastro);

                var valorDataDoCadastro = new Cell(new Phrase(processo.DataDoCadastro.ToString("dd/MM/yyyy"), _Fonte1));

                valorDataDoCadastro.DisableBorderSide(0);

                tabela.AddCell(valorDataDoCadastro);

                var labelDespacho = new Cell(new Phrase("Despacho: ", _Fonte2));

                labelDespacho.DisableBorderSide(0);

                tabela.AddCell(labelDespacho);

                var valorDespacho = processo.Despacho != null ? new Cell(new Phrase(processo.Despacho.CodigoDespacho, _Fonte1)) :
                   new Cell(new Phrase(string.Empty, _Fonte1));

                valorDespacho.DisableBorderSide(0);

                tabela.AddCell(valorDespacho);

                var labelApresentacao = new Cell(new Phrase("Apresentação: ", _Fonte2));

                labelApresentacao.DisableBorderSide(0);

                tabela.AddCell(labelApresentacao);

                Cell valorApresentacao;

                if(processo.Marca != null && processo.Marca.Apresentacao != null)
                     valorApresentacao = new Cell(new Phrase(processo.Marca.Apresentacao.Nome, _Fonte1));
                else
                     valorApresentacao = new Cell(new Phrase(string.Empty, _Fonte1));

                valorApresentacao.DisableBorderSide(0);

                tabela.AddCell(valorApresentacao);

                var labelNatureza = new Cell(new Phrase("Natureza: ", _Fonte2));

                labelNatureza.DisableBorderSide(0);

                tabela.AddCell(labelNatureza);

                Cell valorNatureza;

                if (processo.Marca != null && processo.Marca.Natureza != null)
                    valorNatureza = new Cell(new Phrase(processo.Marca.Natureza.Nome, _Fonte1));
                else
                    valorNatureza = new Cell(new Phrase(string.Empty, _Fonte1));

                valorNatureza.DisableBorderSide(0);

                tabela.AddCell(valorNatureza);

                var labelNCL = new Cell(new Phrase("NCL: ", _Fonte2));

                labelNCL.DisableBorderSide(0);

                tabela.AddCell(labelNCL);

                Cell valorNCL;

                if (processo.Marca != null && processo.Marca.NCL != null)
                    valorNCL = new Cell(new Phrase(processo.Marca.NCL.Codigo, _Fonte1));
                else
                    valorNCL = new Cell(new Phrase(string.Empty, _Fonte1));

                valorNCL.DisableBorderSide(0);

                tabela.AddCell(valorNCL);

                var labelCliente = new Cell(new Phrase("Cliente: ", _Fonte2));

                labelCliente.DisableBorderSide(0);

                tabela.AddCell(labelCliente);

                var valorCliente = new Cell(new Phrase(processo.Marca.Cliente.Pessoa.Nome, _Fonte1)) { Colspan = 5 };

                valorCliente.DisableBorderSide(0);

                tabela.AddCell(valorCliente);

                var labelMarca = new Cell(new Phrase("Marca: ", _Fonte2));

                labelMarca.DisableBorderSide(0);

                tabela.AddCell(labelMarca);

                Cell valorMarca;

                if (processo.Marca != null && !string.IsNullOrEmpty(processo.Marca.DescricaoDaMarca))
                    valorMarca = new Cell(new Phrase(processo.Marca.DescricaoDaMarca, _Fonte1));
                else
                    valorMarca = new Cell(new Phrase(string.Empty, _Fonte1));

                valorMarca.Colspan = 5;
                valorMarca.DisableBorderSide(0);

                tabela.AddCell(valorMarca);

                var labelApostila = new Cell(new Phrase("Apostila: ", _Fonte2));

                labelApostila.DisableBorderSide(0);

                tabela.AddCell(labelApostila);

                Cell valorApostila;

                if (!string.IsNullOrEmpty(processo.Apostila))
                    valorApostila = new Cell(new Phrase(processo.Apostila, _Fonte1));
                else
                    valorApostila = new Cell(new Phrase(string.Empty, _Fonte1));

                valorApostila.Colspan = 5;
                valorApostila.DisableBorderSide(0);

                tabela.AddCell(valorApostila);

                var labelTextoDespacho = new Cell(new Phrase("Texto do Despacho: ", _Fonte2));

                labelTextoDespacho.DisableBorderSide(0);

                tabela.AddCell(labelTextoDespacho);

                Cell valorTextoDespacho;

                if (!string.IsNullOrEmpty(processo.TextoComplementarDoDespacho))
                    valorTextoDespacho = new Cell(new Phrase(processo.Apostila, _Fonte1));
                else
                    valorTextoDespacho = new Cell(new Phrase(string.Empty, _Fonte1));

                valorTextoDespacho.Colspan = 5;
                valorTextoDespacho.DisableBorderSide(0);

                tabela.AddCell(valorTextoDespacho);

                var labelProcurador = new Cell(new Phrase("Procurador: ", _Fonte2));

                labelProcurador.DisableBorderSide(0);

                tabela.AddCell(labelProcurador);

                Cell valorProcurador;

                if (processo.Procurador != null && processo.Procurador.Pessoa != null &&
                    !string.IsNullOrEmpty(processo.Procurador.Pessoa.Nome))
                    valorProcurador = new Cell(new Phrase(processo.Procurador.Pessoa.Nome, _Fonte1));
                else
                    valorProcurador = new Cell(new Phrase(string.Empty, _Fonte1));

                valorProcurador.Colspan = 5;
                valorProcurador.DisableBorderSide(0);

                tabela.AddCell(valorProcurador);

                var linhaVazia = new Cell(new Phrase("\n", _Fonte1));
                linhaVazia.Colspan = 6;
                linhaVazia.DisableBorderSide(1);

                tabela.AddCell(linhaVazia);
            }

            _documento.Add(tabela);
        }
예제 #10
0
        public static void PYU960326AG7(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc)
        {
            try
            {
                //DAL dal = new DAL();

                #region "Construimos el Documento"

                #region "Construimos el Encabezado"

                Table encabezado = new Table(7);
                float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 };
                encabezado.Widths = headerwidthsEncabezado;
                encabezado.WidthPercentage = 100;
                encabezado.Padding = 1;
                encabezado.Spacing = 1;
                encabezado.BorderWidth = 0;
                encabezado.DefaultCellBorder = 0;
                encabezado.BorderColor = gris;

                Image imgLogo = Image.GetInstance(pathIMGLOGO);
                imgLogo.ScalePercent(47f);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(1f, 1f);
                par.Add(new Chunk(imgLogo, 0, 0));
                par.Add(new Chunk("", f6));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(8f, 9f);
                par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B));
                par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                StringBuilder expedido = new StringBuilder();
                expedido.
                    Append("Lugar de Expedición México DF\n").
                    Append(htCFDI["sucursal"]).Append("\n").
                    Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n").
                    Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n").
                    Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n");

                cel = new Cell(new Phrase(expedido.ToString(), f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 4;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Día", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Mes", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Año", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats();
                string HORAS = fechaCFDI[103];
                string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString();
                string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper();
                string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString();

                cel = new Cell(new Phrase(DIA, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(MES, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(ANIO, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                //cel = new Cell(new Phrase("No. y Año de Aprobación: " + dtEncabezado.Rows[0]["NoAp"].ToString() + " " + dtEncabezado.Rows[0]["AnoAp"].ToString(), f6));
                cel = new Cell(new Phrase("", f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                //cel = new Cell(new Phrase(HORAS, f6));
                cel = new Cell(new Phrase("", f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("CLIENTE", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Termino Pago: " + electronicDocument.Data.CondicionesPago.Value, f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor1"] + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor2"] + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor3"] + "\n", f5));
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                #region "Consignado a"

                string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE
                string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12
                string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13
                string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18
                string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15
                string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16
                string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE17
                string localidadEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-LOCAL"].ToString();//CE14
                string saltoEntregado = "\n";
                string separador = ", ";
                string espacio = " ";

                if (nombreEntregado.Length > 0)
                    nombreEntregado = nombreEntregado + saltoEntregado;
                else
                    nombreEntregado = "" + saltoEntregado;

                if (calleEntregado.Length > 0)
                    calleEntregado = calleEntregado + saltoEntregado;
                else
                    calleEntregado = "" + saltoEntregado;

                if (coloniaEntregado.Length > 0)
                    coloniaEntregado = coloniaEntregado + espacio;
                else
                    coloniaEntregado = "" + espacio;

                if (cpEntregado.Length > 0)
                    cpEntregado = ", CP " + cpEntregado + saltoEntregado;
                else
                    cpEntregado = "" + separador + saltoEntregado;

                if (municEntregado.Length > 0)
                    municEntregado = municEntregado + separador;
                else
                    municEntregado = "";

                if (localidadEntregado.Length > 0)
                    localidadEntregado = localidadEntregado + saltoEntregado;
                else
                    localidadEntregado = "" + saltoEntregado;

                if (estadoEntregado.Length > 0)
                    estadoEntregado = estadoEntregado + espacio;
                else
                    estadoEntregado = "" + espacio;

                if (paisEntregado.Length > 0)
                    paisEntregado = paisEntregado + "";
                else
                    paisEntregado = "";

                #endregion

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Consignado a:\n", f5B));
                par.Add(new Chunk(calleEntregado, f5));
                par.Add(new Chunk(coloniaEntregado, f5));
                par.Add(new Chunk(cpEntregado, f5));
                par.Add(new Chunk(municEntregado, f5));
                par.Add(new Chunk(localidadEntregado, f5));
                par.Add(new Chunk(estadoEntregado, f5));
                par.Add(new Chunk(paisEntregado, f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Cliente No:\n", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5));
                par.Add(new Chunk("\nContacto:\n", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5));
                par.Add(new Chunk("\nTeléfono:\n", f5B));
                par.Add(new Chunk("" + "\n", f5));

                //if (htCFDI["serie"].ToString() == "C" || htCFDI["serie"].ToString() == "D")
                //{
                //    par.Add(new Chunk("Zona:\n", f5B));
                //    par.Add(new Chunk(dtEncabezado.Rows[0]["zona"].ToString(), f5));
                //}

                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                //if (htCFDI["serie"].ToString() == "C")
                //{
                //    par = new Paragraph();
                //    par.SetLeading(7f, 1f);
                //    par.Add(new Chunk("Vencimiento: ", f5B));
                //    par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27
                //    cel = new Cell(par);
                //    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                //    cel.HorizontalAlignment = Element.ALIGN_CENTER;
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthRight = (float).5;
                //    cel.BorderWidthBottom = (float).5;
                //    cel.BorderColor = gris;
                //    cel.Colspan = 3;
                //    encabezado.AddCell(cel);
                //}

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Vencimiento: ", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Moneda: ", f5B));
                par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5));
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);

                //if (htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N")
                //    par.Add(new Chunk("Referencia: ", f5B));
                //else
                //    par.Add(new Chunk("Orden Compra: ", f5B));
                par.Add(new Chunk("Orden Compra: ", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["referencia"].ToString(), f5));//CE33
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                //if (htCFDI["serie"].ToString() == "N")
                //{
                //    par = new Paragraph();
                //    par.SetLeading(7f, 1f);
                //    par.Add(new Chunk("Fecha Referencia: ", f5B));
                //    par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34
                //    cel = new Cell(par);
                //    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                //    cel.HorizontalAlignment = Element.ALIGN_CENTER;
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthRight = (float).5;
                //    cel.BorderWidthBottom = 0;
                //    cel.BorderColor = gris;
                //    cel.Colspan = 3;
                //    encabezado.AddCell(cel);
                //}

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Pedido: ", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["pedido"].ToString(), f5));//CE19
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("División: ", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["division"].ToString(), f5));//CE20
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                #endregion

                #region "Construimos Tablas de Partidas"

                #region "Construimos Encabezados de Partidas"

                Table encabezadoPartidas = new Table(7);
                float[] headerwidthsEncabesadoPartidas = { 5, 10, 10, 40, 11, 12, 12 };
                encabezadoPartidas.Widths = headerwidthsEncabesadoPartidas;
                encabezadoPartidas.WidthPercentage = 100;
                encabezadoPartidas.Padding = 1;
                encabezadoPartidas.Spacing = 1;
                encabezadoPartidas.BorderWidth = (float).5;
                encabezadoPartidas.DefaultCellBorder = 1;
                encabezadoPartidas.BorderColor = gris;

                cel = new Cell(new Phrase("No.", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Código", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Descripción", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Colspan = 2;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Cantidad", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Precio Unitario", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Importe", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                #endregion

                #region "Construimos Contenido de las Partidas"

                Table partidas = new Table(7);
                float[] headerwidthsPartidas = { 5, 10, 10, 40, 11, 12, 12 };
                partidas.Widths = headerwidthsPartidas;
                partidas.WidthPercentage = 100;
                partidas.Padding = 1;
                partidas.Spacing = 1;
                partidas.BorderWidth = 0;
                partidas.DefaultCellBorder = 0;
                partidas.BorderColor = gris;

                if (dtEncabezado.Rows.Count > 0)
                {
                    for (int i = 0; i < electronicDocument.Data.Conceptos.Count; i++)
                    {
                        cel = new Cell(new Phrase((i + 1).ToString(), f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_CENTER;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        cel.Rowspan = 2;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(dtDetalle.Rows[i]["codeLocal"].ToString(), f5));//CD1
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_CENTER;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        cel.Rowspan = 2;
                        partidas.AddCell(cel);

                        #region "Descripción"

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = 0;
                        cel.BorderColor = gris;
                        cel.Colspan = 2;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value + " " + electronicDocument.Data.Conceptos[i].Unidad.Value, f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_CENTER;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        cel.Rowspan = 2;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        cel.Rowspan = 2;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = (float).5;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        cel.Rowspan = 2;
                        partidas.AddCell(cel);

                        par = new Paragraph();
                        par.SetLeading(7f, 1f);
                        par.Add(new Chunk("Lote\n", f5L));
                        par.Add(new Chunk(dtDetalle.Rows[i]["lote"].ToString().Replace("*", "\n"), f5));//CD3
                        cel = new Cell(par);
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        par = new Paragraph();
                        par.SetLeading(7f, 1f);
                        par.Add(new Chunk("Cantidad\n", f5L));
                        par.Add(new Chunk(dtDetalle.Rows[i]["cantidad"].ToString().Replace("*", "\n"), f5));//CD4
                        cel = new Cell(par);
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = 0;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        #endregion
                    }
                }

                #endregion

                #endregion

                #region "Construimos el Comentarios"

                Table comentarios = new Table(7);
                float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 };
                comentarios.Widths = headerwidthsComentarios;
                comentarios.WidthPercentage = 100;
                comentarios.Padding = 1;
                comentarios.Spacing = 1;
                comentarios.BorderWidth = 0;
                comentarios.DefaultCellBorder = 0;
                comentarios.BorderColor = gris;

                cel = new Cell(new Phrase("Cantidad:", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Rowspan = 3;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                cel.Rowspan = 3;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Sub Total", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                double importe = 0;
                double tasa = 0;

                for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++)
                {
                    if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA")
                    {
                        importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value;
                        tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value;
                        break;
                    }
                }

                cel = new Cell(new Phrase("IVA " + tasa + " %", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Total", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Observaciones:", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Rowspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                cel.Rowspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Descuento Pronto Pago", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _ci), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Importe Pago Neto", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Descuento.Value.ToString("C", _ci), f5));//Duda
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.FormaPago.Value.ToUpper(), f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 7;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 7;
                comentarios.AddCell(cel);

                #endregion

                #region "Construimos Tabla de Datos CFDI"

                DefaultSplitCharacter split = new DefaultSplitCharacter();
                Table adicional = new Table(3);
                float[] headerwidthsAdicional = { 20, 25, 55 };
                adicional.Widths = headerwidthsAdicional;
                adicional.WidthPercentage = 100;
                adicional.Padding = 1;
                adicional.Spacing = 1;
                adicional.BorderWidth = (float).5;
                adicional.DefaultCellBorder = 1;
                adicional.BorderColor = gris;

                if (timbrar)
                {
                    #region "Generamos Quick Response Code"

                    byte[] bytesQRCode = new byte[0];

                    if (timbrar)
                    {
                        // Generamos el Quick Response Code (QRCode)
                        string re = electronicDocument.Data.Emisor.Rfc.Value;
                        string rr = electronicDocument.Data.Receptor.Rfc.Value;
                        string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value);
                        string id = objTimbre.Uuid.Value;

                        StringBuilder sbCadenaQRCode = new StringBuilder();

                        sbCadenaQRCode.
                            Append("?").
                            Append("re=").Append(re).
                            Append("&").
                            Append("rr=").Append(rr).
                            Append("&").
                            Append("tt=").Append(tt).
                            Append("&").
                            Append("id=").Append(id);

                        BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode();

                        barcode.Data = sbCadenaQRCode.ToString();
                        barcode.ModuleSize = 3;
                        barcode.LeftMargin = 0;
                        barcode.RightMargin = 10;
                        barcode.TopMargin = 0;
                        barcode.BottomMargin = 0;
                        barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto;
                        barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto;
                        barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L;
                        bytesQRCode = barcode.drawBarcodeAsBytes();
                    }

                    #endregion

                    Image imageQRCode = Image.GetInstance(bytesQRCode);
                    imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT);
                    imageQRCode.ScaleToFit(90f, 90f);
                    imageQRCode.IndentationLeft = 9f;
                    imageQRCode.SpacingAfter = 9f;
                    imageQRCode.BorderColorTop = Color.WHITE;

                    cel = new Cell(imageQRCode);
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.HorizontalAlignment = Element.ALIGN_CENTER;
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = (float).5;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Rowspan = 6;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L));
                    par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.Colspan = 2;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("FOLIO FISCAL:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s');

                    cel = new Cell(new Phrase(fechaTimbrado[0], f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = (float).5;
                    adicional.AddCell(cel);

                    string lbRegimen = "REGIMEN FISCAL APLICABLE: ";
                    StringBuilder regimenes = new StringBuilder();
                    if (electronicDocument.Data.Emisor.Regimenes.IsAssigned)
                    {
                        for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++)
                        {
                            regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n");
                        }
                    }
                    else
                    {
                        regimenes.Append("");
                        lbRegimen = "";
                    }

                    string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned
                                    ? electronicDocument.Data.NumeroCuentaPago.Value
                                    : "";

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + "   |   ", f5));
                    par.Add(new Chunk("Moneda: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.Moneda.Value + "   |   ", f5));
                    par.Add(new Chunk("TASA DE CAMBIO: ", f5L));
                    string tasaCambio = electronicDocument.Data.TipoCambio.Value;

                    if (tasaCambio.Length > 0)
                    {
                        par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + "   |   ", f5));
                    }
                    else
                    {
                        par.Add(new Chunk("   |   ", f5));
                    }
                    par.Add(new Chunk("FORMA DE PAGO: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5));
                    par.Add(new Chunk("MÉTODO DE PAGO: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + "   |   ", f5));
                    par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L));
                    par.Add(new Chunk(cuenta + "   |   ", f5));
                    par.Add(new Chunk(lbRegimen, f5L));
                    par.Add(new Chunk(regimenes.ToString(), f5));

                    cel.BorderColor = gris;
                    cel = new Cell(par);
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Colspan = 2;
                    cel.BorderColor = gris;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L));
                    par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.Colspan = 3;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.KeepTogether = true;
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L));
                    par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Colspan = 3;
                    adicional.AddCell(cel);
                }
                #endregion

                #region "Construimos Tabla Adicional Datos de Pago"

                Table pago = new Table(5);
                float[] headerwidthsPago = { 40, 10, 20, 10, 20 };
                pago.Widths = headerwidthsPago;
                pago.WidthPercentage = 100;
                pago.Padding = 1;
                pago.Spacing = 1;
                pago.BorderWidth = (float).5;
                pago.DefaultCellBorder = 1;
                pago.BorderColor = gris;

                cel = new Cell(new Phrase("Para ejecutar su pago para consultas", f5L));
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Para efectuar su pago", f5L));
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                cel.Colspan = 2;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Información del Cliente", f5L));
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                cel.Colspan = 2;
                pago.AddCell(cel);

                string[] ejecutarPago = dtEncabezado.Rows[0]["paraConsultas"].ToString().Split(new Char[] { '*' });//CE23
                string[] pagoDatos = dtEncabezado.Rows[0]["efectuarPago"].ToString().Split(new Char[] { '*' });//CE21

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (ejecutarPago.Length > 0)
                    par.Add(new Chunk(ejecutarPago[0] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                if (ejecutarPago.Length > 1)
                    par.Add(new Chunk(ejecutarPago[1] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                if (ejecutarPago.Length > 2)
                    par.Add(new Chunk(ejecutarPago[2] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                if (ejecutarPago.Length > 3)
                    par.Add(new Chunk(ejecutarPago[3] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                cel.Rowspan = 6;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Banco:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 0)
                    par.Add(new Chunk(pagoDatos[0], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Cliente:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Cuenta:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 1)
                    par.Add(new Chunk(pagoDatos[1], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("No. Cliente:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                //if (htCFDI["serie"].ToString() == "B" || htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "J" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N")
                //{
                //    cel = new Cell(new Phrase("", f5));
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthRight = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthBottom = 0;
                //    cel.Colspan = 2;
                //    pago.AddCell(cel);
                //}

                //else
                //{
                //    cel = new Cell(new Phrase("SWIFT:", f5L));
                //    cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthRight = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthBottom = 0;
                //    pago.AddCell(cel);

                //    cel = new Cell(new Phrase(pagoDatos[3], f5));
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthRight = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthBottom = 0;
                //    pago.AddCell(cel);
                //}

                cel = new Cell(new Phrase("", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Factura No:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + "-" + electronicDocument.Data.Folio.Value.ToString(), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Moneda:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 4)
                    par.Add(new Chunk(pagoDatos[4], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Fecha Factura", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                string[] fechaFactura = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s');

                cel = new Cell(new Phrase(DIA + "/" + MES + "/" + ANIO, f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Beneficiario:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 5)
                    par.Add(new Chunk(pagoDatos[5], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Valor Total:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Dirección:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 4)
                    par.Add(new Chunk(dtEncabezado.Rows[0]["direccionPie"].ToString(), f5));//CE22
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                pago.AddCell(cel);

                //if (htCFDI["serie"].ToString() == "C")
                //{
                //    cel = new Cell(new Phrase("Fecha Vencimiento:", f5L));
                //    cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                //    cel.BorderColor = gris;
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthRight = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthBottom = (float).5;
                //    pago.AddCell(cel);

                //    cel = new Cell(new Phrase(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B));
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthRight = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthBottom = (float).5;
                //    cel.BorderColor = gris;
                //    pago.AddCell(cel);
                //}
                //else
                //{
                //    cel = new Cell(new Phrase("Moneda:", f5L));
                //    cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                //    cel.BorderColor = gris;
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthRight = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthBottom = (float).5;
                //    pago.AddCell(cel);

                //    cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5));
                //    cel.BorderWidthTop = 0;
                //    cel.BorderWidthRight = 0;
                //    cel.BorderWidthLeft = 0;
                //    cel.BorderWidthBottom = (float).5;
                //    cel.BorderColor = gris;
                //    pago.AddCell(cel);
                //}

                cel = new Cell(new Phrase("Moneda:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                pago.AddCell(cel);

                #endregion

                #region "Construimos Tabla del Footer"

                PdfPTable footer = new PdfPTable(1);
                footer.WidthPercentage = 100;
                footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;

                cell = new PdfPCell(new Phrase("", f5));
                cell.BorderWidthTop = 0;
                cell.BorderWidthLeft = 0;
                cell.BorderWidthRight = 0;
                cell.BorderWidthBottom = 0;
                footer.AddCell(cell);

                cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo));
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.BackgroundColor = azul;
                cell.BorderWidthTop = 0;
                cell.BorderWidthLeft = 0;
                cell.BorderWidthRight = 0;
                cell.BorderWidthBottom = 0;
                footer.AddCell(cell);

                #endregion

                pageEventHandler.encabezado = encabezado;
                pageEventHandler.encPartidas = encabezadoPartidas;
                pageEventHandler.footer = footer;

                document.Open();

                document.Add(partidas);
                document.Add(comentarios);
                document.Add(adicional);
                document.Add(pago);

                #endregion
            }
            catch (Exception ex)
            {
                string exe = ex.Message;
            }
        }
예제 #11
0
        public static void formatoABCDIJKLM(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, Int64 idCfdi, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc)
        {
            try
            {
                DAL dal = new DAL();
                #region "Construimos el Documento"

                #region "Construimos el Encabezado"

                Table encabezado = new Table(7);
                float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 };
                encabezado.Widths = headerwidthsEncabezado;
                encabezado.WidthPercentage = 100;
                encabezado.Padding = 1;
                encabezado.Spacing = 1;
                encabezado.BorderWidth = 0;
                encabezado.DefaultCellBorder = 0;
                encabezado.BorderColor = gris;

                //Agregando Imagen de Logotipo
                Image imgLogo = Image.GetInstance(pathIMGLOGO);
                imgLogo.ScalePercent(47f);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(1f, 1f);
                par.Add(new Chunk(imgLogo, 0, 0));
                par.Add(new Chunk("", f6));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(8f, 9f);
                par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B));
                par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                StringBuilder expedido = new StringBuilder();
                expedido.
                    Append("Lugar de Expedición México DF\n").
                    Append(htCFDI["sucursal"]).Append("\n").
                    Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n").
                    Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n").
                    Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n");

                cel = new Cell(new Phrase(expedido.ToString(), f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 4;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Día", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Mes", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Año", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats();
                string HORAS = fechaCFDI[103];
                string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString();
                string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper();
                string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString();

                cel = new Cell(new Phrase(DIA, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(MES, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(ANIO, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("No. y Año de Aprobación: " + dtEncabezado.Rows[0]["NoAp"].ToString() + " " + dtEncabezado.Rows[0]["AnoAp"].ToString(), f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(HORAS, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("CLIENTE", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Termino Pago: " + electronicDocument.Data.CondicionesPago.Value, f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor1"] + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor2"] + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor3"] + "\n", f5));
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                #region "Consignado a"

                string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE
                string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12
                string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13
                string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18
                string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15
                string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16
                string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE17
                string localidadEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-LOCAL"].ToString();//CE14
                string saltoEntregado = "\n";
                string separador = ", ";
                string espacio = " ";

                if (nombreEntregado.Length > 0)
                    nombreEntregado = nombreEntregado + saltoEntregado;
                else
                    nombreEntregado = "" + saltoEntregado;

                if (calleEntregado.Length > 0)
                    calleEntregado = calleEntregado + saltoEntregado;
                else
                    calleEntregado = "" + saltoEntregado;

                if (coloniaEntregado.Length > 0)
                    coloniaEntregado = coloniaEntregado + espacio;
                else
                    coloniaEntregado = "" + espacio;

                if (cpEntregado.Length > 0)
                    cpEntregado = ", CP " + cpEntregado + saltoEntregado;
                else
                    cpEntregado = "" + separador + saltoEntregado;

                if (municEntregado.Length > 0)
                    municEntregado = municEntregado + separador;
                else
                    municEntregado = "";

                if (localidadEntregado.Length > 0)
                    localidadEntregado = localidadEntregado + saltoEntregado;
                else
                    localidadEntregado = "" + saltoEntregado;

                if (estadoEntregado.Length > 0)
                    estadoEntregado = estadoEntregado + espacio;
                else
                    estadoEntregado = "" + espacio;

                if (paisEntregado.Length > 0)
                    paisEntregado = paisEntregado + "";
                else
                    paisEntregado = "";

                #endregion

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Consignado a:\n", f5B));
                par.Add(new Chunk(calleEntregado, f5));
                par.Add(new Chunk(coloniaEntregado, f5));
                par.Add(new Chunk(cpEntregado, f5));
                par.Add(new Chunk(municEntregado, f5));
                par.Add(new Chunk(localidadEntregado, f5));
                par.Add(new Chunk(estadoEntregado, f5));
                par.Add(new Chunk(paisEntregado, f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Cliente No:\n", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5));
                par.Add(new Chunk("\nContacto:\n", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5));
                par.Add(new Chunk("\nTeléfono:\n", f5B));
                par.Add(new Chunk("" + "\n", f5));

                if (htCFDI["serie"].ToString() == "C" || htCFDI["serie"].ToString() == "D")
                {
                    par.Add(new Chunk("Zona:\n", f5B));
                    par.Add(new Chunk(dtEncabezado.Rows[0]["zona"].ToString(), f5));
                }

                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                if (htCFDI["serie"].ToString() == "C")
                {
                    par = new Paragraph();
                    par.SetLeading(7f, 1f);
                    par.Add(new Chunk("Vencimiento: ", f5B));
                    par.Add(new Chunk(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B)); //CE27
                    cel = new Cell(par);
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.HorizontalAlignment = Element.ALIGN_CENTER;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthRight = (float).5;
                    cel.BorderWidthBottom = (float).5;
                    cel.BorderColor = gris;
                    cel.Colspan = 3;
                    encabezado.AddCell(cel);
                }

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Moneda: ", f5B));
                par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5));
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);

                if (htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N")
                    par.Add(new Chunk("Referencia: ", f5B));
                else
                    par.Add(new Chunk("Orden Compra: ", f5B));

                par.Add(new Chunk(dtEncabezado.Rows[0]["referencia"].ToString(), f5));//CE33
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                if (htCFDI["serie"].ToString() == "N")
                {
                    par = new Paragraph();
                    par.SetLeading(7f, 1f);
                    par.Add(new Chunk("Fecha Referencia: ", f5B));
                    par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34
                    cel = new Cell(par);
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.HorizontalAlignment = Element.ALIGN_CENTER;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthRight = (float).5;
                    cel.BorderWidthBottom = 0;
                    cel.BorderColor = gris;
                    cel.Colspan = 3;
                    encabezado.AddCell(cel);
                }

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Pedido: ", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["pedido"].ToString(), f5));//CE19
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("División: ", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["division"].ToString(), f5));//CE20
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                #endregion

                #region "Construimos Tablas de Partidas"

                #region "Añadimos Detalle de Conceptos"

                // Creamos la tabla para insertar los conceptos de detalle de la factura

                StringBuilder sbOpcionalDetalle = new StringBuilder();
                sbOpcionalDetalle.
                    Append("SELECT ROW_NUMBER() OVER (ORDER BY idCfdi ASC) AS numero, ").
                    Append("campo1 AS codigoProducto, campo18 AS codigoBarras, ").
                    Append("campo3 AS lote, campo5 AS fechaLote, campo4 AS cantidadLote ").
                    Append("FROM opcionalDetalle ").
                    Append("WHERE idCfdi = @0 ");

                DataTable dtOpcionalDetalle = dal.QueryDT("DS_FE", sbOpcionalDetalle.ToString(), "F:I:" + idCfdi, hc);

                // Obtenemos los conceptos guardados en el Xml
                int numConceptosXml = electronicDocument.Data.Conceptos.Count;

                // Debido a que no siempre hacen match el número de conceptos de xml con los de opcionalDetalle armamos un Hashtable
                // Armamos la tabla que contendra los conceptops finales a imprimir en el Pdf

                DataTable dtConceptosFinal = new DataTable();
                dtConceptosFinal.Columns.Add("numero", typeof(int));
                dtConceptosFinal.Columns.Add("codigoBarras", typeof(string));
                dtConceptosFinal.Columns.Add("codigoProducto", typeof(string));
                dtConceptosFinal.Columns.Add("lote", typeof(string));
                dtConceptosFinal.Columns.Add("fechaLote", typeof(string));
                dtConceptosFinal.Columns.Add("cantidadLote", typeof(string));
                dtConceptosFinal.Columns.Add("descripcion", typeof(string));
                dtConceptosFinal.Columns.Add("cantidad", typeof(double));
                dtConceptosFinal.Columns.Add("unidadMedida", typeof(string));
                dtConceptosFinal.Columns.Add("precioUnitario", typeof(double));
                dtConceptosFinal.Columns.Add("importe", typeof(double));

                int contConceptos = 1;

                foreach (DataRow rowConceptos in dtOpcionalDetalle.Rows)
                {
                    for (int i = contConceptos; i <= numConceptosXml; i++)
                    {
                        object[] arrayConceptos = new object[11];

                        if (Convert.ToInt32(rowConceptos["numero"]) == i)
                        {
                            arrayConceptos[0] = Convert.ToInt32(rowConceptos["numero"]);
                            arrayConceptos[1] = rowConceptos["codigoBarras"].ToString();
                            arrayConceptos[2] = rowConceptos["codigoProducto"].ToString();
                            arrayConceptos[3] = rowConceptos["lote"].ToString();
                            arrayConceptos[4] = rowConceptos["fechaLote"].ToString();
                            arrayConceptos[5] = rowConceptos["cantidadLote"].ToString();
                            arrayConceptos[6] = electronicDocument.Data.Conceptos[i - 1].Descripcion.Value;
                            arrayConceptos[7] = electronicDocument.Data.Conceptos[i - 1].Cantidad.Value;
                            arrayConceptos[8] = electronicDocument.Data.Conceptos[i - 1].Unidad.Value;
                            arrayConceptos[9] = electronicDocument.Data.Conceptos[i - 1].ValorUnitario.Value;
                            arrayConceptos[10] = electronicDocument.Data.Conceptos[i - 1].Importe.Value;
                        }
                        else
                        {
                            arrayConceptos[0] = 0;
                            arrayConceptos[1] = string.Empty;
                            arrayConceptos[2] = string.Empty;
                            arrayConceptos[3] = string.Empty;
                            arrayConceptos[4] = string.Empty;
                            arrayConceptos[5] = string.Empty;
                            arrayConceptos[6] = electronicDocument.Data.Conceptos[i - 1].Descripcion.Value;
                            arrayConceptos[7] = electronicDocument.Data.Conceptos[i - 1].Cantidad.Value;
                            arrayConceptos[8] = electronicDocument.Data.Conceptos[i - 1].Unidad.Value;
                            arrayConceptos[9] = electronicDocument.Data.Conceptos[i - 1].ValorUnitario.Value;
                            arrayConceptos[10] = electronicDocument.Data.Conceptos[i - 1].Importe.Value;
                        }

                        dtConceptosFinal.Rows.Add(arrayConceptos);
                        break;
                    }

                    contConceptos++;
                }

                // Una vez llena la tabla final de conceptos procedemos a generar la tabla de detalle.

                #region"Tabla Detalle"

                Table encabezadoDetalle = new Table(7);
                float[] headerEncabezadoDetalle = { 5, 12, 11, 40, 9, 10, 12 };
                encabezadoDetalle.Widths = headerEncabezadoDetalle;
                encabezadoDetalle.WidthPercentage = 100F;
                encabezadoDetalle.Padding = 1;
                encabezadoDetalle.Spacing = 1;
                encabezadoDetalle.BorderWidth = 0;
                encabezadoDetalle.DefaultCellBorder = 0;
                encabezadoDetalle.BorderColor = gris;

                // Número
                cel = new Cell(new Phrase("No", titulo));
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Còdigo de Barras
                cel = new Cell(new Phrase("Cod. Barras", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Código
                cel = new Cell(new Phrase("Código", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Descripción
                cel = new Cell(new Phrase("Descripción", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Cantidad
                cel = new Cell(new Phrase("Cantidad", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Precio Unitario
                cel = new Cell(new Phrase("Precio Unitario", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Importe
                cel = new Cell(new Phrase("Importe", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                PdfPCell cell;
                PdfPTable tableConceptos = new PdfPTable(7);
                tableConceptos.SetWidths(new int[7] { 5, 12, 11, 40, 9, 10, 12 });
                //                tableConceptos.WidthPercentage = 91.5F;
                tableConceptos.WidthPercentage = 100F;

                Font fontLbl = new Font(Font.HELVETICA, 7, Font.BOLD, new Color(43, 145, 175));
                Font fontVal = new Font(Font.HELVETICA, 7, Font.NORMAL);

                foreach (DataRow rowConceptos in dtConceptosFinal.Rows)
                {
                    // Número
                    cell = new PdfPCell(new Phrase(rowConceptos["numero"].ToString(), f5));
                    cell.BorderWidthTop = 0;
                    cell.BorderWidthLeft = (float).5;
                    cell.BorderWidthRight = 0;
                    cell.BorderWidthBottom = (float).5;
                    cell.BorderColor = gris;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    tableConceptos.AddCell(cell);

                    // Código de Barras
                    cell = new PdfPCell(new Phrase(rowConceptos["codigoBarras"].ToString(), f5));
                    cell.BorderWidthTop = 0;
                    cell.BorderWidthLeft = (float).5;
                    cell.BorderWidthRight = 0;
                    cell.BorderWidthBottom = (float).5;
                    cell.BorderColor = gris;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    tableConceptos.AddCell(cell);

                    // Código de Producto
                    cell = new PdfPCell(new Phrase(rowConceptos["codigoProducto"].ToString(), f5));
                    cell.BorderWidthTop = 0;
                    cell.BorderWidthLeft = (float).5;
                    cell.BorderWidthRight = 0;
                    cell.BorderWidthBottom = (float).5;
                    cell.BorderColor = gris;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    tableConceptos.AddCell(cell);

                    // Tabla de Descripción
                    PdfPTable tableDesc = new PdfPTable(3);
                    tableDesc.WidthPercentage = 100;

                    // Descripción
                    cell = new PdfPCell(new Phrase(rowConceptos["descripcion"].ToString(), f5));
                    cell.Border = 0;
                    cell.NoWrap = true;
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell.Colspan = 3;
                    tableDesc.AddCell(cell);

                    // Lote
                    //Phrase pLote = new Phrase();
                    //Chunk cLoteLbl = new Chunk("Lote : \n", fontLbl);
                    //Chunk cLoteVal = new Chunk(rowConceptos["lote"].ToString().Replace("*", "\n"), fontVal);

                    //pLote.Add(cLoteLbl);
                    //pLote.Add(cLoteVal);

                    //par.KeepTogether = true;
                    //par.SetLeading(7f, 1f);

                    par = new Paragraph();
                    par.Add(new Chunk("Lote\n\n", f5L));
                    par.Add(new Chunk(rowConceptos["lote"].ToString().Replace("*", "\n"), f5));
                    cell = new PdfPCell(par);
                    cell.Border = 0;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    tableDesc.AddCell(cell);

                    //// Cantidad
                    //Phrase pCantidad = new Phrase();
                    //Chunk cCantidadLbl = new Chunk("Cantidad\n", fontLbl);
                    //Chunk cCantidadVal = new Chunk(rowConceptos["cantidadLote"].ToString().Replace("*", "\n"), fontVal);

                    //pCantidad.Add(cCantidadLbl);
                    //pCantidad.Add(cCantidadVal);
                    //cell = new PdfPCell(pCantidad);
                    //cell.Border = 1;
                    //cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    //cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    //tableDesc.AddCell(cell);

                    par = new Paragraph();
                    par.Add(new Chunk("Cantidad\n\n", f5L));
                    par.Add(new Chunk(rowConceptos["cantidadLote"].ToString().Replace("*", "\n"), f5));
                    cell = new PdfPCell(par);
                    cell.Border = 0;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    tableDesc.AddCell(cell);

                    //// Fecha Lote
                    //Phrase pFecLote = new Phrase();
                    //Chunk cFecLoteLbl;
                    //Chunk cFecLoteVal;

                    par = new Paragraph();
                    //if (electronicDocument.Data.Serie.Value == "C" || electronicDocument.Data.Serie.Value == "D" || electronicDocument.Data.Serie.Value == "K" || electronicDocument.Data.Serie.Value == "L" || electronicDocument.Data.Serie.Value == "M" || electronicDocument.Data.Serie.Value == "N")
                    //{
                    //    par.Add(new Chunk("", fontLbl));
                    //    par.Add(new Chunk("", fontVal));
                    //    //cFecLoteLbl = new Chunk("11", fontLbl);
                    //    //cFecLoteVal = new Chunk("22", fontVal);
                    //}
                    //else
                    if (electronicDocument.Data.Serie.Value == "A")
                    {
                        par.Add(new Chunk("Expiración\n\n", f5L));
                        par.Add(new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), f5));
                        //cFecLoteLbl = new Chunk("Fecha Lote : ", fontLbl);
                        //cFecLoteVal = new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), fontVal);
                    }
                    else
                    {
                        par.Add(new Chunk(""));
                        par.Add(new Chunk("", f5));
                        //cFecLoteLbl = new Chunk("Fecha Lote : ", fontLbl);
                        //cFecLoteVal = new Chunk(rowConceptos["fechaLote"].ToString().Replace("*", "\n"), fontVal);
                    }
                    //pFecLote.Add(cFecLoteLbl);
                    //pFecLote.Add(cFecLoteVal);

                    cell = new PdfPCell(par);
                    cell.Border = 0;
                    cell.HorizontalAlignment = Element.ALIGN_LEFT;
                    tableDesc.AddCell(cell);

                    // Número de Cantidad
                    cell = new PdfPCell(new Phrase(""));
                    cell.Border = 0;
                    cell.Colspan = 3;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    tableDesc.AddCell(cell);

                    cell = new PdfPCell(tableDesc);
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cell.BorderWidthTop = 0;
                    cell.BorderWidthLeft = (float).5;
                    cell.BorderWidthRight = 0;
                    cell.BorderWidthBottom = (float).5;
                    cell.BorderColor = gris;
                    tableConceptos.AddCell(cell);

                    // Cantidad
                    cell = new PdfPCell(new Phrase(rowConceptos["cantidad"] + " " + rowConceptos["unidadMedida"], f5));
                    cell.BorderWidthTop = 0;
                    cell.BorderWidthLeft = (float).5;
                    cell.BorderWidthRight = 0;
                    cell.BorderWidthBottom = (float).5;
                    cell.BorderColor = gris;
                    cell.HorizontalAlignment = Element.ALIGN_CENTER;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    tableConceptos.AddCell(cell);

                    // Precio Unitario
                    cell = new PdfPCell(new Phrase(Convert.ToDouble(rowConceptos["precioUnitario"]).ToString("C", _ci), f5));
                    cell.BorderWidthTop = 0;
                    cell.BorderWidthLeft = (float).5;
                    cell.BorderWidthRight = 0;
                    cell.BorderWidthBottom = (float).5;
                    cell.BorderColor = gris;
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    tableConceptos.AddCell(cell);

                    // Importe
                    cell = new PdfPCell(new Phrase(Convert.ToDouble(rowConceptos["importe"]).ToString("C", _ci), f5));
                    cell.BorderWidthTop = 0;
                    cell.BorderWidthLeft = (float).5;
                    cell.BorderWidthRight = (float).5;
                    cell.BorderWidthBottom = (float).5;
                    cell.BorderColor = gris;
                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    tableConceptos.AddCell(cell);
                }

                #endregion

                #endregion

                #endregion

                #region "Construimos el Comentarios"

                Table comentarios = new Table(7);
                float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 };
                comentarios.Widths = headerwidthsComentarios;
                comentarios.WidthPercentage = 100;
                comentarios.Padding = 1;
                comentarios.Spacing = 1;
                comentarios.BorderWidth = 0;
                comentarios.DefaultCellBorder = 0;
                comentarios.BorderColor = gris;

                cel = new Cell(new Phrase("Cantidad:", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Rowspan = 3;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                cel.Rowspan = 3;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Sub Total", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString("C", _ci), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                double importe = 0;
                double tasa = 0;

                for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++)
                {
                    if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA")
                    {
                        importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value;
                        tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value;
                        break;
                    }
                }

                cel = new Cell(new Phrase("IVA " + tasa + " %", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Total", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Observaciones:", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 6;
                comentarios.AddCell(cel);

                #endregion

                #region "Construimos Tabla Especial"
                Table especial = new Table(5);
                float[] headerwidthsEspecial = { 20, 20, 20, 20, 20 };
                especial.Widths = headerwidthsEspecial;
                especial.WidthPercentage = 100;
                especial.Padding = 1;
                especial.Spacing = 1;
                especial.BorderWidth = 0;
                especial.DefaultCellBorder = 0;
                especial.BorderColor = blanco;

                cel = new Cell(new Phrase("", f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = blanco;
                cel.Colspan = 5;
                especial.AddCell(cel);

                #endregion

                #region "Construimos Tabla de Datos CFDI"

                DefaultSplitCharacter split = new DefaultSplitCharacter();
                Table adicional = new Table(3);
                float[] headerwidthsAdicional = { 20, 25, 55 };
                adicional.Widths = headerwidthsAdicional;
                adicional.WidthPercentage = 100;
                adicional.Padding = 1;
                adicional.Spacing = 1;
                adicional.BorderWidth = (float).5;
                adicional.DefaultCellBorder = 1;
                adicional.BorderColor = gris;

                if (timbrar)
                {
                    #region "Generamos Quick Response Code"

                    byte[] bytesQRCode = new byte[0];

                    if (timbrar)
                    {
                        // Generamos el Quick Response Code (QRCode)
                        string re = electronicDocument.Data.Emisor.Rfc.Value;
                        string rr = electronicDocument.Data.Receptor.Rfc.Value;
                        string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value);
                        string id = objTimbre.Uuid.Value;

                        StringBuilder sbCadenaQRCode = new StringBuilder();

                        sbCadenaQRCode.
                            Append("?").
                            Append("re=").Append(re).
                            Append("&").
                            Append("rr=").Append(rr).
                            Append("&").
                            Append("tt=").Append(tt).
                            Append("&").
                            Append("id=").Append(id);

                        BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode();

                        barcode.Data = sbCadenaQRCode.ToString();
                        barcode.ModuleSize = 3;
                        barcode.LeftMargin = 0;
                        barcode.RightMargin = 10;
                        barcode.TopMargin = 0;
                        barcode.BottomMargin = 0;
                        barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto;
                        barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto;
                        barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L;
                        bytesQRCode = barcode.drawBarcodeAsBytes();
                    }

                    #endregion

                    Image imageQRCode = Image.GetInstance(bytesQRCode);
                    imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT);
                    imageQRCode.ScaleToFit(90f, 90f);
                    imageQRCode.IndentationLeft = 9f;
                    imageQRCode.SpacingAfter = 9f;
                    imageQRCode.BorderColorTop = Color.WHITE;

                    cel = new Cell(imageQRCode);
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.HorizontalAlignment = Element.ALIGN_CENTER;
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = (float).5;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Rowspan = 6;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L));
                    par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.Colspan = 2;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("FOLIO FISCAL:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s');

                    cel = new Cell(new Phrase(fechaTimbrado[0], f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = (float).5;
                    adicional.AddCell(cel);

                    string lbRegimen = "REGIMEN FISCAL APLICABLE: ";
                    StringBuilder regimenes = new StringBuilder();
                    if (electronicDocument.Data.Emisor.Regimenes.IsAssigned)
                    {
                        for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++)
                        {
                            regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n");
                        }
                    }
                    else
                    {
                        regimenes.Append("");
                        lbRegimen = "";
                    }

                    string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned
                                    ? electronicDocument.Data.NumeroCuentaPago.Value
                                    : "";

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + "   |   ", f5));
                    par.Add(new Chunk("Moneda: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.Moneda.Value + "   |   ", f5));
                    par.Add(new Chunk("TASA DE CAMBIO: ", f5L));
                    string tasaCambio = electronicDocument.Data.TipoCambio.Value;
                    if (tasaCambio.Length > 0)
                    {
                        par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + "   |   ", f5));
                    }
                    else
                    {
                        par.Add(new Chunk("   |   ", f5));
                    }
                    par.Add(new Chunk("FORMA DE PAGO: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5));
                    par.Add(new Chunk("MÉTODO DE PAGO: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + "   |   ", f5));
                    par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L));
                    par.Add(new Chunk(cuenta + "   |   ", f5));
                    par.Add(new Chunk(lbRegimen, f5L));
                    par.Add(new Chunk(regimenes.ToString(), f5));
                    cel.BorderColor = gris;
                    cel = new Cell(par);
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Colspan = 2;
                    cel.BorderColor = gris;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L));
                    par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.Colspan = 3;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.KeepTogether = true;
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L));
                    par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Colspan = 3;
                    adicional.AddCell(cel);
                }
                #endregion

                #region "Construimos Tabla Adicional Datos de Pago"

                Table pago = new Table(5);
                float[] headerwidthsPago = { 40, 10, 20, 10, 20 };
                pago.Widths = headerwidthsPago;
                pago.WidthPercentage = 100;
                pago.Padding = 1;
                pago.Spacing = 1;
                pago.BorderWidth = (float).5;
                pago.DefaultCellBorder = 1;
                pago.BorderColor = gris;

                cel = new Cell(new Phrase("Para ejecutar su pago para consultas", f5L));
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Para efectuar su pago", f5L));
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                cel.Colspan = 2;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Información del Cliente", f5L));
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                cel.Colspan = 2;
                pago.AddCell(cel);

                string[] ejecutarPago = dtEncabezado.Rows[0]["paraConsultas"].ToString().Split(new Char[] { '*' });//CE23
                string[] pagoDatos = dtEncabezado.Rows[0]["efectuarPago"].ToString().Split(new Char[] { '*' });//CE21

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (ejecutarPago.Length > 0)
                    par.Add(new Chunk(ejecutarPago[0] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                if (ejecutarPago.Length > 1)
                    par.Add(new Chunk(ejecutarPago[1] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                if (ejecutarPago.Length > 2)
                    par.Add(new Chunk(ejecutarPago[2] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                if (ejecutarPago.Length > 3)
                    par.Add(new Chunk(ejecutarPago[3] + "\n", f5));
                else
                    par.Add(new Chunk("\n", f5));
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                cel.Rowspan = 6;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Banco:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 0)
                    par.Add(new Chunk(pagoDatos[0], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Cliente:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Cuenta:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 1)
                    par.Add(new Chunk(pagoDatos[1], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("No. Cliente:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["clienteNo"].ToString(), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                if (htCFDI["serie"].ToString() == "B" || htCFDI["serie"].ToString() == "D" || htCFDI["serie"].ToString() == "J" || htCFDI["serie"].ToString() == "L" || htCFDI["serie"].ToString() == "N")
                {
                    cel = new Cell(new Phrase("", f5));
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Colspan = 2;
                    pago.AddCell(cel);
                }
                else
                {
                    cel = new Cell(new Phrase("SWIFT:", f5L));
                    cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    pago.AddCell(cel);

                    if (pagoDatos.Length > 3)
                        cel = new Cell(new Phrase(pagoDatos[3], f5));
                    else
                        cel = new Cell(new Phrase("", f5));
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    pago.AddCell(cel);
                }

                cel = new Cell(new Phrase("Factura No:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + "-" + electronicDocument.Data.Folio.Value.ToString(), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Moneda:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 4)
                    par.Add(new Chunk(pagoDatos[4], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Fecha Factura", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                string[] fechaFactura = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s');

                cel = new Cell(new Phrase(DIA + "/" + MES + "/" + ANIO, f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Beneficiario:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 5)
                    par.Add(new Chunk(pagoDatos[5], f5));
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Valor Total:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                pago.AddCell(cel);

                cel = new Cell(new Phrase("Dirección:", f5L));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                pago.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 0f);
                if (pagoDatos.Length > 4)
                    par.Add(new Chunk(dtEncabezado.Rows[0]["direccionPie"].ToString(), f5));//CE22
                else
                    par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = (float).5;
                pago.AddCell(cel);

                if (htCFDI["serie"].ToString() == "C")
                {
                    cel = new Cell(new Phrase("Fecha Vencimiento:", f5L));
                    cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    pago.AddCell(cel);

                    cel = new Cell(new Phrase(dtEncabezado.Rows[0]["vencimiento"].ToString(), f5B));
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.BorderColor = gris;
                    pago.AddCell(cel);
                }
                else
                {
                    cel = new Cell(new Phrase("Moneda:", f5L));
                    cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    pago.AddCell(cel);

                    cel = new Cell(new Phrase(electronicDocument.Data.Moneda.Value, f5));
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.BorderColor = gris;
                    pago.AddCell(cel);
                }

                #endregion

                #region "Construimos Tabla del Footer"

                PdfPTable footer = new PdfPTable(1);
                footer.WidthPercentage = 100;
                footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;

                cell = new PdfPCell(new Phrase("", f5));
                cell.BorderWidthTop = 0;
                cell.BorderWidthLeft = 0;
                cell.BorderWidthRight = 0;
                cell.BorderWidthBottom = 0;
                footer.AddCell(cell);

                cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo));
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.BackgroundColor = azul;
                cell.BorderWidthTop = 0;
                cell.BorderWidthLeft = 0;
                cell.BorderWidthRight = 0;
                cell.BorderWidthBottom = 0;
                footer.AddCell(cell);

                #endregion

                pageEventHandler.encabezado = encabezado;
                pageEventHandler.encPartidas = encabezadoDetalle;
                pageEventHandler.footer = footer;

                document.Open();

                document.Add(tableConceptos);
                document.Add(comentarios);
                document.Add(especial);
                document.Add(adicional);
                document.Add(pago);

                #endregion
            }
            catch (Exception ex)
            {
                string exe = ex.Message;
            }
        }
예제 #12
0
    protected void GeneratePDF()
    {
        // Refresh the summary grid else there will be nothing to generate (no postback)
        this.PopulateGrid();

        // Create and initialize a new document object
        iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.LEGAL, 24, 24, 24, 24);
        document.PageSize.Rotate();
        System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();

        try
        {
            // Create an instance of the writer object
            iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, memoryStream);

            // Add some meta information to the document
            Label lblPageTitle = (Label)(this.Page.Master.FindControl("lblDefaultMasterPageTitle"));
            document.AddAuthor(lblPageTitle.Text);
            document.AddSubject(this.lblReportTitle.Text);

            // Open the document
            document.Open();

            // Create a table to match our current summary grid
            iTextSharp.text.Table table = null;

            if (this.DateRangeType == DateRangeTypes.UserSpecified)
                table = new iTextSharp.text.Table(6);
            else if (this.DateRangeType == DateRangeTypes.Daily)
                table = new iTextSharp.text.Table(7);
            else
                table = new iTextSharp.text.Table(8);

            table.TableFitsPage = true;

            // Apply spacing/padding/borders/column widths to the table
            table.Padding = 2;
            table.Spacing = 0;
            table.DefaultCellBorderWidth = 1;

            if (this.DateRangeType == DateRangeTypes.UserSpecified)
            {
                float[] headerwidths1 = { 30, 30, 30, 30, 30, 30 };
                table.Widths = headerwidths1;
            }
            else if (this.DateRangeType == DateRangeTypes.Daily)
            {
                float[] headerwidths2 = { 40, 30, 30, 30, 30, 30, 30 };
                table.Widths = headerwidths2;
            }
            else
            {
                float[] headerwidths3 = { 40, 30, 30, 30, 30, 30, 30, 35 };
                table.Widths = headerwidths3;
            }

            table.Width = 100;

            // Add report title spanning all columns
            iTextSharp.text.Font titleFont = new iTextSharp.text.Font(Font.GetFamilyIndex("Tahoma"), 6, Font.BOLD);
            titleFont.Color = new iTextSharp.text.Color(System.Drawing.Color.Firebrick);

            iTextSharp.text.Cell titleCell = new iTextSharp.text.Cell();
            titleCell.SetHorizontalAlignment("Left");
            titleCell.SetVerticalAlignment("Top");
            titleCell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.White);
            titleCell.BorderWidth = 0;

            if (this.DateRangeType == DateRangeTypes.UserSpecified)
                titleCell.Colspan = 6;
            else if (this.DateRangeType == DateRangeTypes.Daily)
                titleCell.Colspan = 7;
            else
                titleCell.Colspan = 8;

            titleCell.AddElement(new iTextSharp.text.Phrase(this.lblReportTitle.Text, titleFont));
            table.AddCell(titleCell);

            // Add table headers
            for (int i = 0; i < this.grdRaveForm.Columns.Count; i++)
            {
                iTextSharp.text.Font headerCellFont = new iTextSharp.text.Font(Font.GetFamilyIndex("Tahoma"), 8, Font.NORMAL + Font.UNDERLINE);
                headerCellFont.Color = new iTextSharp.text.Color(System.Drawing.Color.White);

                iTextSharp.text.Cell headerCell = new iTextSharp.text.Cell();
                headerCell.SetHorizontalAlignment("Left");
                headerCell.SetVerticalAlignment("Top");
                headerCell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.SteelBlue);
                headerCell.BorderColor = new iTextSharp.text.Color(System.Drawing.Color.White);

                headerCell.AddElement(new iTextSharp.text.Phrase(this.grdRaveForm.Columns[i].HeaderText, headerCellFont));
                table.AddCell(headerCell);
            }

            table.EndHeaders();

            // Add data to the table
            int j = 0;
            int k = 0;
            string phrase = "";

            foreach (System.Data.DataRow row in this._pdfDataTable.Rows)
            {
                j++; // Increment the row counter
                k = 0; // Reset the column counter for the new row

                foreach (System.Data.DataColumn col in this._pdfDataTable.Columns)
                {
                    k++; // Increment the column counter

                    iTextSharp.text.Font cellFont = new iTextSharp.text.Font(Font.GetFamilyIndex("Tahoma"), 6, Font.NORMAL);

                    if (j % 2 == 0)
                    {
                        cellFont.Color = new iTextSharp.text.Color(System.Drawing.Color.DarkRed);
                    }
                    else
                    {
                        cellFont.Color = new iTextSharp.text.Color(System.Drawing.Color.Black);
                    }

                    iTextSharp.text.Cell cell = new iTextSharp.text.Cell();
                    cell.SetHorizontalAlignment("Left");
                    cell.SetVerticalAlignment("Top");
                    cell.BorderColor = new iTextSharp.text.Color(System.Drawing.Color.White);

                    if (j % 2 == 0)
                    {
                        cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.LightGray);
                    }
                    else
                    {
                        cell.BackgroundColor = new iTextSharp.text.Color(System.Drawing.Color.White);
                    }

                    // Generate formatted phrase for cell.
                    switch (col.ColumnName)
                    {
                        case "SummaryDate":
                        case "MaxDate":
                            phrase = String.Format("{0,10:MM/dd/yyyy}", row[col]);
                            break;
                        case "AvgSecs":
                        case "StdDevSecs":
                            phrase = String.Format("{0:F2}", row[col]);
                            break;
                        case "FormIDCount":
                            phrase = String.Format("{0:G}", row[col]);
                            break;
                        default:
                            phrase = row[col].ToString();
                            break;
                    }

                    cell.AddElement(new iTextSharp.text.Phrase(phrase, cellFont));
                    table.AddCell(cell);
                }
            }

            // Add the table to the document
            document.Add(table);

            // Close the document
            document.Close();

            // Show the document
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=" + Enum.GetName(typeof(DateRangeTypes), this.DateRangeType) + "Performance" + ((DropDownList)this.Page.Master.FindControl("ddlReport")).SelectedItem.Text.Replace(" ", String.Empty) + ".pdf");
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(memoryStream.ToArray());
            Response.End();
        }
        catch (Exception xcptn)
        {
            Response.Write(xcptn.Message);
        }
    }
예제 #13
0
        /**
        * Imports the Cell properties into the RtfCell
        *
        * @param cell The Cell to import
        */
        private void ImportCell(Cell cell)
        {
            this.content = new ArrayList();

            if (cell == null) {
                this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, this.parentRow.GetParentTable().GetBorders());
                return;
            }

            this.colspan = cell.Colspan;
            this.rowspan = cell.Rowspan;
            if (cell.Rowspan > 1) {
                this.mergeType = MERGE_VERT_PARENT;
            }
            if (cell is RtfCell) {
                this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, ((RtfCell) cell).GetBorders());
            } else {
                this.borders = new RtfBorderGroup(this.document, RtfBorder.CELL_BORDER, cell.Border, cell.BorderWidth, cell.BorderColor);
            }
            this.verticalAlignment = cell.VerticalAlignment;
            if (cell.BackgroundColor == null) {
                this.backgroundColor = new RtfColor(this.document, 255, 255, 255);
            } else {
                this.backgroundColor = new RtfColor(this.document, cell.BackgroundColor);
            }

            this.cellPadding = (int) this.parentRow.GetParentTable().GetCellPadding();

            Paragraph container = null;
            foreach (IElement element in cell.Elements) {
                try {
                    // should we wrap it in a paragraph
                    if (!(element is Paragraph) && !(element is List)) {
                        if (container != null) {
                            container.Add(element);
                        } else {
                            container = new Paragraph();
                            container.Alignment = cell.HorizontalAlignment;
                            container.Add(element);
                        }
                    } else {
                        if (container != null) {
                            IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container);
                            for (int i = 0; i < rtfElements.Length; i++) {
                                rtfElements[i].SetInTable(true);
                                this.content.Add(rtfElements[i]);
                            }
                            container = null;
                        }
                        // if horizontal alignment is undefined overwrite
                        // with that of enclosing cell
                        if (element is Paragraph && ((Paragraph) element).Alignment == Element.ALIGN_UNDEFINED) {
                            ((Paragraph) element).Alignment = cell.HorizontalAlignment;
                        }

                        IRtfBasicElement[] rtfElements2 = this.document.GetMapper().MapElement(element);
                        for (int i = 0; i < rtfElements2.Length; i++) {
                            rtfElements2[i].SetInTable(true);
                            this.content.Add(rtfElements2[i]);
                        }
                    }
                } catch (DocumentException) {
                }
            }
            if (container != null) {
                try {
                    IRtfBasicElement[] rtfElements = this.document.GetMapper().MapElement(container);
                    for (int i = 0; i < rtfElements.Length; i++) {
                        rtfElements[i].SetInTable(true);
                        this.content.Add(rtfElements[i]);
                    }
                } catch (DocumentException) {
                }
            }
        }
예제 #14
0
파일: Report.cs 프로젝트: paulallies/tsdt
        public void GenerateXMLReport()
        {
            try
            {
                this.doc.Open();
                RenderLogo();
                //RenderHeaderAddress();
                RenderReportJobInfo();
                RenderProjectsReports();

                #region Add Details Table
                float[] DetailsHeaderwidths = this.Headerwidths; // percentage
                iTextSharp.text.Table JobDetailstable = new iTextSharp.text.Table(DetailsHeaderwidths.Length);

                JobDetailstable.Padding = 1;
                JobDetailstable.DefaultCell.BorderWidth = 1;
                JobDetailstable.Widths = DetailsHeaderwidths;
                JobDetailstable.WidthPercentage = 100;
                JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
                JobDetailstable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY;

                foreach (var x in this.ColList)
                {
                    JobDetailstable.AddCell(new Phrase(x, fntHeading));
                }
                JobDetailstable.EndHeaders();
                Font myDetailFont = fntDetails;
                foreach (var x in this.ReportRows)
                {
                    for (int i = 0; i < ColList.Count; i++)
                    {
                        JobDetailstable.DefaultCell.BackgroundColor = Color.WHITE;
                        if(x.row[i].type == CellType.Number)
                        JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                        else
                        JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                        JobDetailstable.AddCell(new Phrase(x.row[i].value, myDetailFont));
                    }
                }
                JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                Cell cell = new Cell(new Paragraph("Total", myDetailFont));
                cell.BackgroundColor = Color.LIGHT_GRAY;
                cell.BorderWidth = 1;
                cell.Colspan = 3;
                JobDetailstable.AddCell(cell);
                JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
                JobDetailstable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY;
                JobDetailstable.AddCell(new Phrase(this.total, myDetailFont));
                doc.Add(JobDetailstable);

                #endregion

            }
            catch (Exception ex)
            {
                //MessageBox.Show("Error: " + ex.Message);
            }
            doc.Close();

            writer.Close();
        }
 public Table( int cols, int rows, Alignment align )
 {
     Cells = new Cell[cols, rows];
     ColsCount = cols;
     RowsCount = rows;
     Align = align;
     InitRelativeColumnWidths( cols );
 }
예제 #16
0
 /**
 * Sets the merge type and the <code>RtfCell</code> with which this
 * <code>RtfCell</code> is to be merged.
 *
 * @param mergeType The merge type specifies the kind of merge to be applied
 * (MERGE_HORIZ_PREV, MERGE_VERT_PREV, MERGE_BOTH_PREV)
 * @param mergeCell The <code>RtfCell</code> that the cell at x and y is to
 * be merged with
 */
 public void SetMerge(int mergeType, RtfCell mergeCell)
 {
     this.mergeType = mergeType;
     store = mergeCell.GetStore();
 }
예제 #17
0
        /**
        * Import a <code>Cell</code>.
        * <P>
        * @param cell The <code>Cell</code> containing the data for this
        * <code>RtfCell</code>
        * @param cellLeft The position of the left border
        * @param cellWidth The default width of a cell
        * @param x The column index of this <code>RtfCell</code>
        * @param y The row index of this <code>RtfCell</code>
        * @param cellpadding the cellpadding
        * @return the position of the right side of the cell
        */
        public int ImportCell(Cell cell, int cellLeft, int cellWidth, int x, int y, int cellpadding)
        {
            this.cellpadding = cellpadding;

            // set this value in any case
            this.cellWidth = cellWidth;
            if (cell == null) {
                cellRight = cellLeft + cellWidth;
                return cellRight;
            }
            if (cell.CellWidth != null && !cell.CellWidth.Equals("")) {

                this.cellWidth = (int)(int.Parse(cell.CellWidth) * RtfWriter.TWIPSFACTOR);
            }
            cellRight = cellLeft + this.cellWidth;
            store = cell;
            emptyCell = false;
            if (cell.Colspan > 1) {
                if (cell.Rowspan > 1) {
                    mergeType = MERGE_BOTH_FIRST;
                    for (int i = y; i < y + cell.Rowspan; i++) {
                        if (i > y) mainTable.SetMerge(x, i, MERGE_VERT_PREV, this);
                        for (int j = x + 1; j < x + cell.Colspan; j++) {
                            mainTable.SetMerge(j, i, MERGE_BOTH_PREV, this);
                        }
                    }
                } else {
                    mergeType = MERGE_HORIZ_FIRST;
                    for (int i = x + 1; i < x + cell.Colspan; i++) {
                        mainTable.SetMerge(i, y, MERGE_HORIZ_PREV, this);
                    }
                }
            } else if (cell.Rowspan > 1) {
                mergeType = MERGE_VERT_FIRST;
                for (int i = y + 1; i < y + cell.Rowspan; i++) {
                    mainTable.SetMerge(x, i, MERGE_VERT_PREV, this);
                }
            }
            return cellRight;
        }
예제 #18
0
        // methods

        /// <summary>
        /// Sets the unset cell properties to be the table defaults.
        /// </summary>
        /// <param name="aCell">The cell to set to table defaults as necessary.</param>
        private void AssumeTableDefaults(Cell aCell) {

            if (aCell.Border == Rectangle.UNDEFINED) {
                aCell.Border = defaultCell.Border;
            }
            if (aCell.BorderWidth == Rectangle.UNDEFINED) {
                aCell.BorderWidth = defaultCell.BorderWidth;
            }
            if (aCell.BorderColor == null) {
                aCell.BorderColor = defaultCell.BorderColor;
            }
            if (aCell.BackgroundColor == null) {
                aCell.BackgroundColor = defaultCell.BackgroundColor;
            }
            if (aCell.HorizontalAlignment == Element.ALIGN_UNDEFINED) {
                aCell.HorizontalAlignment = defaultCell.HorizontalAlignment;
            }
            if (aCell.VerticalAlignment == Element.ALIGN_UNDEFINED) {
                aCell.VerticalAlignment = defaultCell.VerticalAlignment;
            }
        }
예제 #19
0
 /**
 * Constructs a RtfCell based on a Cell.
 *
 * @param doc The RtfDocument this RtfCell belongs to
 * @param row The RtfRow this RtfCell lies in
 * @param cell The Cell to base this RtfCell on
 */
 protected internal RtfCell(RtfDocument doc, RtfRow row, Cell cell)
 {
     this.document = doc;
     this.parentRow = row;
     ImportCell(cell);
 }
 public void SetCell( int col, int row, Phrase phrase )
 {
     Cells[col, row] = new Cell( phrase );
 }
예제 #21
0
 public PrinterJob Build(ReportType reportType, int copies)
 {
     var reportConfig = Managers.PrintingManager.ReportConfig;
     var logger = Managers.PrintingManager.Logger;
     logger.LogVerbose(Message.Common_DebugCall);
     _totalPagesCount = 0;
     _currentPageNumber = 0;
     var fileName = FileUtils.GetUniqueName(
         Managers.FileSystemManager.GetDataDirectoryPath(FileType.Report),
         String.Format("{0}.{1:yyyyMMdd}.", "PrintJob", DateTime.Now),
         "pdf",
         6);
     var filePath = Path.Combine(Managers.FileSystemManager.GetDataDirectoryPath(FileType.Report), fileName);
     using (var stream = new MemoryStream())
     {
         try
         {
             _pdfDocument = new Document(PageSize.A4);
             _pdfDocument.ClaspFooter = ClaspFooter;
             PdfWriter writer = PdfWriter.GetInstance(_pdfDocument, stream);
             writer.PageEvent = new PdfEventHelper(this);
             _pdfDocument.SetMargins(Margins[0], Margins[1], Margins[2], Margins[3]);
             var fontFileName = Path.Combine(reportConfig.Font.Path,
                                             TemplateFont.ToString().ToLower() + FONT_FILE_EXTENSION);
             BaseFont baseFont = BaseFont.CreateFont(fontFileName, FONT_CODEPAGE, true);
             _font = new Font(baseFont, _defaultFontSize, Font.NORMAL);
             if (Headers.ContainsKey(PageSection.PageHeader) && Headers[PageSection.PageHeader].Count > 0)
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание PageHeader");
                 var head = new HeaderFooter(MakeParagraph(Headers[PageSection.PageHeader]), false);
                 head.Border = Border;
                 _pdfDocument.Header = head;
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание PageHeader");
             }
             if (Headers.ContainsKey(PageSection.PageFooter) && Headers[PageSection.PageFooter].Count > 0)
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание PageFooter");
                 Paragraph footParagraph = MakeParagraph(Headers[PageSection.PageFooter]);
                 if (PageNumbered)
                 {
                     footParagraph.Add(new Phrase(Chunk.NEWLINE));
                     footParagraph.Add(new Phrase(Chunk.NEWLINE));
                 }
                 var foot = new HeaderFooter(footParagraph, false);
                 foot.Border = Border;
                 _pdfDocument.Footer = foot;
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание PageFooter");
             }
             try
             {
                 _pdfDocument.Open();
             }
             catch (Exception ex)
             {
                 throw new Exception("Ошибка формирования PDF", ex);
             }
             if (Headers.ContainsKey(PageSection.Header))
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Header");
                 _pdfDocument.Add(MakeParagraph(Headers[PageSection.Header]));
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Header");
             }
             if (Data != null)
             {
                 int dataTablesCount = Data.Tables.Cast<DataTable>().Count(table => !table.TableName.StartsWith("C"));
                 for (int tableIndex = 0; tableIndex < dataTablesCount; tableIndex++)
                 {
                     float tableFactor = (_pdfDocument.Right - _pdfDocument.Left) / 100;
                     string tableName = tableIndex.ToString();
                     logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Таблицы " + tableName);
                     if (Data.Tables.Contains(tableName) && Data.Tables[tableName] != null)
                     {
                         var currentTable = Data.Tables[tableName];
                         int serviceColumnCount =
                             currentTable.Columns.Cast<DataColumn>().Count(
                                 c => c.ColumnName.StartsWith(ServiceTableColumns.SERVICE_COLUMN_PREFIX));
                         int dataColumns = currentTable.Columns.Count - serviceColumnCount;
                         if (currentTable.Rows.Count > 0)
                         {
                             Table tbl = MakeTable(dataColumns, currentTable.Rows.Count);
                             foreach (DataRow row in currentTable.Rows)
                             {
                                 if (((ServiceMode)row[ServiceTableColumns.ServiceMode] &
                                      ServiceMode.ResetPageCounter) > 0)
                                 {
                                     _currentPageNumber = 0;
                                 }
                                 TableDotted = (bool)row[ServiceTableColumns.IsTableDotted];
                                 if (((ServiceMode)row[ServiceTableColumns.ServiceMode] &
                                      ServiceMode.PageBreak) > 0)
                                 {
                                     if (row == currentTable.Rows.Cast<DataRow>().Last() &&
                                         !Data.Tables.Contains((tableIndex + 1).ToString()))
                                         continue;
                                     _pdfDocument.Add(tbl);
                                     _pdfDocument.NewPage();
                                     tbl = MakeTable(dataColumns, currentTable.Rows.Count);
                                 }
                                 var colLines = new string[dataColumns];
                                 var colWidths = new float[dataColumns];
                                 var colAligns = new LineAlign?[dataColumns];
                                 int fontSize = _defaultFontSize;
                                 bool bold = false;
                                 bool italic = false;
                                 LineAlign lineAlign = LineAlign.Left;
                                 for (int columnIndex = 0; columnIndex < currentTable.Columns.Count; columnIndex++)
                                 {
                                     switch (currentTable.Columns[columnIndex].ColumnName)
                                     {
                                         case ServiceTableColumns.FontSize:
                                             fontSize = (int)(row.ItemArray[columnIndex]);
                                             break;
                                         case ServiceTableColumns.IsBold:
                                             bold = (bool)(row.ItemArray[columnIndex]);
                                             break;
                                         case ServiceTableColumns.IsItalic:
                                             italic = (bool)(row.ItemArray[columnIndex]);
                                             break;
                                         case ServiceTableColumns.Align:
                                             lineAlign = (LineAlign)(row.ItemArray[columnIndex]);
                                             break;
                                         default:
                                             if (!currentTable.Columns[columnIndex]
                                                     .ColumnName.StartsWith(ServiceTableColumns.SERVICE_COLUMN_PREFIX))
                                             {
                                                 colLines[columnIndex] = row.ItemArray[columnIndex].ToString();
                                                 if (Data.Tables["C" + tableIndex] != null)
                                                 {
                                                     DataRow[] columnProps = Data.Tables["C" + tableIndex]
                                                         .Select(ServiceTableColumns.Name + " = '"
                                                                 + currentTable.Columns[columnIndex].ColumnName + "'");
                                                     if (columnProps.Length > 0)
                                                     {
                                                         colWidths[columnIndex] = (int)columnProps[0][ServiceTableColumns.Width];
                                                         if (columnProps[0][ServiceTableColumns.Align] != DBNull.Value)
                                                         {
                                                             colAligns[columnIndex] = (LineAlign)columnProps[0][ServiceTableColumns.Align];
                                                         }
                                                     }
                                                 }
                                             }
                                             break;
                                     }
                                 }
                                 Font tempFont = GetFont(fontSize, bold, italic, baseFont);
                                 var cellLeading = (float)Math.Round(tempFont.Size * DBL_LEADING_FONT);
                                 tbl.Widths = colWidths;
                                 for (int columnIndex = 0; columnIndex < dataColumns; columnIndex++)
                                 {
                                     float cellWidth = tableFactor * colWidths[columnIndex];
                                     colLines[columnIndex] = TextAlign(
                                         colLines[columnIndex], tempFont, colAligns[columnIndex] ?? lineAlign,
                                         cellWidth, (row != currentTable.Rows.Cast<DataRow>().First()
                                                     && TableDotted)
                                                     ? '.'
                                                     : ' ');
                                     var cell =
                                         new Cell(new Phrase(cellLeading, colLines[columnIndex], tempFont))
                                             {
                                                 Border = Border,
                                                 Leading = cellLeading,
                                             };
                                     tbl.AddCell(cell);
                                 }
                             }
                             logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Таблицы " + tableName);
                             logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Добавление Таблицы " + tableName);
                             _pdfDocument.Add(tbl);
                             logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Добавление Таблицы " + tableName);
                         }
                     }
                 }
             }
             if (Headers.ContainsKey(PageSection.Footer) && Headers[PageSection.Footer].Count > 0)
             {
                 logger.LogVerbose(Message.PrintingPdfBuilderStartEvent, "Создание Footer");
                 _pdfDocument.Add(new Phrase(Chunk.NEWLINE));
                 _pdfDocument.Add(MakeParagraph(Headers[PageSection.Footer]));
                 logger.LogVerbose(Message.PrintingPdfBuilderEndEvent, "Создание Footer");
             }
             _pdfDocument.Close();
             var size = (stream.ToArray().Length / FileUtils.BYTES_IN_KB) + 1;
             if (!Managers.FileSystemManager.ReserveDiskSpace(filePath, size))
             {
                 throw new ApplicationException("Недостаточно места на диске для сохранения отчета");
             }
             File.WriteAllBytes(filePath, stream.ToArray());
             SystemHelper.SyncFileSystem();
             logger.LogVerbose(Message.Common_DebugReturn);
             return new PrinterJob(reportType, filePath, _totalPagesCount, copies);
         }
         catch (Exception ex)
         {
             Managers.PrintingManager.Logger.LogError(Message.PrintingPdfBuildFailed, ex);
         }
     }
     return null;
 }
 public void SetCell( int col, int row, Cell cell )
 {
     Cells[col, row] = cell;
 }
예제 #23
0
 /**
 * Creates a Cell with these attributes.
 * @param rowAttributes
 * @return a cell based on these attributes.
 * @throws BadElementException
 */
 public Cell CreateCell(SimpleCell rowAttributes) {
     Cell cell = new Cell();
     cell.CloneNonPositionParameters(rowAttributes);
     cell.SoftCloneNonPositionParameters(this);
     cell.Colspan = colspan;
     cell.HorizontalAlignment = horizontalAlignment;
     cell.VerticalAlignment = verticalAlignment;
     cell.UseAscender = useAscender;
     cell.UseBorderPadding = useBorderPadding;
     cell.UseDescender = useDescender;
     foreach (IElement element in content) {
         cell.AddElement(element);
     }
     return cell;
 }
 public void SetCell( int col, int row, string text )
 {
     Cells[col, row] = new Cell( new Phrase( text ) );
 }
예제 #25
0
        public static void formatoN(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerPfizer pageEventHandler, DataTable dtEncabezado, DataTable dtDetalle, Hashtable htCFDI, HttpContext hc)
        {
            try
            {
                DAL dal = new DAL();

                #region "Construimos el Documento"

                #region "Construimos el Encabezado"

                Table encabezado = new Table(7);
                float[] headerwidthsEncabezado = { 9, 18, 28, 28, 5, 7, 5 };
                encabezado.Widths = headerwidthsEncabezado;
                encabezado.WidthPercentage = 100;
                encabezado.Padding = 1;
                encabezado.Spacing = 1;
                encabezado.BorderWidth = 0;
                encabezado.DefaultCellBorder = 0;
                encabezado.BorderColor = gris;

                //Agregando Imagen de Logotipo
                Image imgLogo = Image.GetInstance(pathIMGLOGO);
                imgLogo.ScalePercent(47f);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(1f, 1f);
                par.Add(new Chunk(imgLogo, 0, 0));
                par.Add(new Chunk("", f6));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(8f, 9f);
                par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f6B));
                par.Add(new Chunk("\nRFC " + htCFDI["rfcEmisor"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor1"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor2"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\n" + htCFDI["direccionEmisor3"].ToString().ToUpper(), f6));
                par.Add(new Chunk("\nTel. (52) 55 5081-8500", f6));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                StringBuilder expedido = new StringBuilder();
                expedido.
                    Append("Lugar de Expedición México DF\n").
                    Append(htCFDI["sucursal"]).Append("\n").
                    Append(htCFDI["direccionExpedido1"].ToString().ToUpper()).Append("\n").
                    Append(htCFDI["direccionExpedido2"].ToString().ToUpper()).Append("\n").
                    Append(htCFDI["direccionExpedido3"].ToString().ToUpper()).Append("\n").
                    Append(dtEncabezado.Rows[0]["corporateCode"]).Append("\n").//CE29
                    Append(dtEncabezado.Rows[0]["oldCorporateCode"].ToString()).Append("\n");//CE30;

                cel = new Cell(new Phrase(expedido.ToString(), f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["tipoDoc"].ToString(), titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + electronicDocument.Data.Folio.Value, f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Día", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Mes", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Año", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                string[] fechaCFDI = Convert.ToDateTime(htCFDI["fechaCfdi"].ToString()).GetDateTimeFormats();
                string HORAS = fechaCFDI[103];
                string DIA = Convert.ToDateTime(htCFDI["fechaCfdi"]).Day.ToString();
                string MES = Convert.ToDateTime(htCFDI["fechaCfdi"]).ToString("MMMM").ToUpper();
                string ANIO = Convert.ToDateTime(htCFDI["fechaCfdi"]).Year.ToString();

                cel = new Cell(new Phrase(DIA, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(MES, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(ANIO, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(HORAS, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("CLIENTE", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Receptor.Nombre.Value, f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Referencia Documento: " + dtEncabezado.Rows[0]["referencia"].ToString(), f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("R.F.C. " + electronicDocument.Data.Receptor.Rfc.Value + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor1"].ToString() + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor2"].ToString() + "\n", f5));
                par.Add(new Chunk(htCFDI["direccionReceptor3"].ToString() + "\n", f5));
                par.Add(new Chunk(dtEncabezado.Rows[0]["codigoCorporativo"] + "\n" + "\n", f5));//36
                par.Add(new Chunk(dtEncabezado.Rows[0]["codigoCorporativoAnt"].ToString(), f5));//37
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 5;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                #region "Consignado a"

                string nombreEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-NOMBRE"].ToString();//CE
                string calleEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CALLE"].ToString();//CE 10, 11, 12
                string coloniaEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-COLONIA"].ToString();//CE13
                string cpEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-CP"].ToString();//CE18
                string municEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-MUNIC"].ToString();//CE15
                string estadoEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-ESTADO"].ToString();//CE16
                string paisEntregado = dtEncabezado.Rows[0]["ENTREGADO-A-PAIS"].ToString();//CE14
                string intericom = dtEncabezado.Rows[0]["INTERICOM"].ToString().ToUpper();//CE32
                string saltoEntregado = "\n";
                string separador = ", ";
                string espacio = " ";

                if (nombreEntregado.Length > 0)
                    nombreEntregado = nombreEntregado + saltoEntregado;
                else
                    nombreEntregado = "" + saltoEntregado;

                if (calleEntregado.Length > 0)
                    calleEntregado = calleEntregado + saltoEntregado;
                else
                    calleEntregado = "" + saltoEntregado;

                if (coloniaEntregado.Length > 0)
                    coloniaEntregado = coloniaEntregado + espacio;
                else
                    coloniaEntregado = "" + espacio;

                if (cpEntregado.Length > 0)
                    cpEntregado = cpEntregado + ", CP " + saltoEntregado;
                else
                    cpEntregado = "" + separador + saltoEntregado;

                if (municEntregado.Length > 0)
                    municEntregado = municEntregado + saltoEntregado;
                else
                    municEntregado = "";

                if (estadoEntregado.Length > 0)
                    estadoEntregado = estadoEntregado + espacio;
                else
                    estadoEntregado = "" + espacio;

                if (paisEntregado.Length > 0)
                    paisEntregado = paisEntregado + "";
                else
                    paisEntregado = "";

                if (intericom.Length > 0)
                    intericom = intericom + espacio;
                else
                    intericom = "";

                #endregion

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Consignado a:\n", f5B));
                par.Add(new Chunk(calleEntregado, f5));
                par.Add(new Chunk(coloniaEntregado, f5));
                par.Add(new Chunk(cpEntregado, f5));
                par.Add(new Chunk(municEntregado, f5));
                par.Add(new Chunk(estadoEntregado, f5));
                par.Add(new Chunk(paisEntregado, f5));
                par.Add(new Chunk("INTERICOM:\n", f5));
                par.Add(new Chunk(intericom, f5));//CE32
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Contacto:\n", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["contacto"].ToString(), f5));
                par.Add(new Chunk("\nTeléfono:\n", f5B));
                par.Add(new Chunk("" + "\n", f5));
                par.Add(new Chunk("Método de Pago:\n", f5B));
                par.Add(new Chunk(electronicDocument.Data.FormaPago.Value, f5));
                cel = new Cell(par);
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Rowspan = 5;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Fecha de Ref. Doc:  ", f5B));
                par.Add(new Chunk(dtEncabezado.Rows[0]["fechaRefDoc"].ToString(), f5));//CE34
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Moneda: ", f5B));
                par.Add(new Chunk(electronicDocument.Data.Moneda.Value, f5));
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Forma de Pago: ", f5B));
                par.Add(new Chunk(electronicDocument.Data.FormaPago.Value.ToString(), f5));
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Condiciones de Pago: ", f5B));
                par.Add(new Chunk(electronicDocument.Data.CondicionesPago.Value.ToString(), f5));//CE19
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.SetLeading(7f, 1f);
                par.Add(new Chunk("Proveedor: ", f5B));
                par.Add(new Chunk("", f5));
                cel = new Cell(par);
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                #endregion

                #region "Construimos Tablas de Partidas"

                #region "Construimos Encabezados de Partidas"

                Table encabezadoPartidas = new Table(9);
                float[] headerwidthsEncabesadoPartidas = { 10, 34, 7, 7, 7, 9, 8, 9, 9 };
                encabezadoPartidas.Widths = headerwidthsEncabesadoPartidas;
                encabezadoPartidas.WidthPercentage = 100;
                encabezadoPartidas.Padding = 1;
                encabezadoPartidas.Spacing = 1;
                encabezadoPartidas.BorderWidth = (float).5;
                encabezadoPartidas.DefaultCellBorder = 1;
                encabezadoPartidas.BorderColor = gris;

                cel = new Cell(new Phrase("Codigo Producto.", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Descripción", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Cantidad", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Cantidad Real (Kg,Lt,Mt)", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Unidad Medida", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Precio Unitario", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Descuento", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Importe", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                cel = new Cell(new Phrase("Importe Neto", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderColor = gris;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthBottom = 0;
                encabezadoPartidas.AddCell(cel);

                #endregion

                #region "Construimos Contenido de las Partidas"

                Table partidas = new Table(9);
                float[] headerwidthsPartidas = { 10, 34, 7, 7, 7, 9, 8, 9, 9 };
                partidas.Widths = headerwidthsPartidas;
                partidas.WidthPercentage = 100;
                partidas.Padding = 1;
                partidas.Spacing = 1;
                partidas.BorderWidth = (float).5;
                partidas.DefaultCellBorder = 1;
                partidas.BorderColor = gris;

                double sumDescuento = 0;

                if (dtEncabezado.Rows.Count > 0)
                {
                    for (int i = 0; i < electronicDocument.Data.Conceptos.Count; i++)
                    {
                        cel = new Cell(new Phrase(dtDetalle.Rows[i]["codeLocal"].ToString(), f5));//CD1
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_CENTER;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = 0;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString("N", _ci), f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(dtDetalle.Rows[i]["cantidadReal"].ToString(), f5));//CD16
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_CENTER;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, f5));//CD10
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_CENTER;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("N", _ci), f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(dtDetalle.Rows[i]["descuento"].ToString(), f5));//CD12
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_CENTER;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        if (double.TryParse(dtDetalle.Rows[i]["descuento"].ToString(), out sumDescuento))
                            sumDescuento += double.Parse(dtDetalle.Rows[i]["descuento"].ToString());
                        else
                            sumDescuento += 0;

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("N", _ci), f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                        cel = new Cell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("N", _ci), f5));
                        cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                        cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                        cel.BorderWidthTop = 0;
                        cel.BorderWidthLeft = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthBottom = (float).5;
                        cel.BorderColor = gris;
                        partidas.AddCell(cel);

                    }
                }

                #endregion

                #endregion

                #region "Construimos el Comentarios"

                Table comentarios = new Table(7);
                float[] headerwidthsComentarios = { 9, 18, 28, 28, 7, 5, 5 };
                comentarios.Widths = headerwidthsComentarios;
                comentarios.WidthPercentage = 100;
                comentarios.Padding = 1;
                comentarios.Spacing = 1;
                comentarios.BorderWidth = 0;
                comentarios.DefaultCellBorder = 0;
                comentarios.BorderColor = gris;

                cel = new Cell(new Phrase("Observaciones:", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Cantidad:", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Sub Total", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.SubTotal.Value.ToString(), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 4;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Descuento", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(sumDescuento.ToString(), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 4;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("I.E.P.S.", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("0", f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["observaciones"].ToString(), f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                cel.Rowspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(dtEncabezado.Rows[0]["cantidadLetra"].ToString(), f5));//CE26
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                cel.Rowspan = 2;
                comentarios.AddCell(cel);

                double importe = 0;
                double tasa = 0;

                for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++)
                {
                    if (electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value == "IVA")
                    {
                        importe = electronicDocument.Data.Impuestos.Traslados[i].Importe.Value;
                        tasa = electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value;
                        break;
                    }
                }

                cel = new Cell(new Phrase("IVA " + tasa.ToString() + " %", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString(), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Total", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString(), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 4;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Total de Articulos", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.Conceptos.Count.ToString(), f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                comentarios.AddCell(cel);

                #endregion

                #region "Construimos Tabla Especial"
                Table especial = new Table(5);
                float[] headerwidthsEspecial = { 20, 20, 20, 20, 20 };
                especial.Widths = headerwidthsEspecial;
                especial.WidthPercentage = 100;
                especial.Padding = 1;
                especial.Spacing = 1;
                especial.BorderWidth = 0;
                especial.DefaultCellBorder = 0;
                especial.BorderColor = gris;

                cel = new Cell(new Phrase("", titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Rowspan = 2;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", f5));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = (float).5;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                cel = new Cell(new Phrase("", titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = (float).5;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                especial.AddCell(cel);

                #endregion

                #region "Construimos Tabla de Datos CFDI"

                DefaultSplitCharacter split = new DefaultSplitCharacter();
                Table adicional = new Table(3);
                float[] headerwidthsAdicional = { 20, 25, 55 };
                adicional.Widths = headerwidthsAdicional;
                adicional.WidthPercentage = 100;
                adicional.Padding = 1;
                adicional.Spacing = 1;
                adicional.BorderWidth = (float).5;
                adicional.DefaultCellBorder = 1;
                adicional.BorderColor = gris;

                if (timbrar)
                {
                    #region "Generamos Quick Response Code"

                    byte[] bytesQRCode = new byte[0];

                    if (timbrar)
                    {
                        // Generamos el Quick Response Code (QRCode)
                        string re = electronicDocument.Data.Emisor.Rfc.Value;
                        string rr = electronicDocument.Data.Receptor.Rfc.Value;
                        string tt = String.Format("{0:F6}", electronicDocument.Data.Total.Value);
                        string id = objTimbre.Uuid.Value;

                        StringBuilder sbCadenaQRCode = new StringBuilder();

                        sbCadenaQRCode.
                            Append("?").
                            Append("re=").Append(re).
                            Append("&").
                            Append("rr=").Append(rr).
                            Append("&").
                            Append("tt=").Append(tt).
                            Append("&").
                            Append("id=").Append(id);

                        BarcodeLib.Barcode.QRCode.QRCode barcode = new BarcodeLib.Barcode.QRCode.QRCode();

                        barcode.Data = sbCadenaQRCode.ToString();
                        barcode.ModuleSize = 3;
                        barcode.LeftMargin = 0;
                        barcode.RightMargin = 10;
                        barcode.TopMargin = 0;
                        barcode.BottomMargin = 0;
                        barcode.Encoding = BarcodeLib.Barcode.QRCode.QRCodeEncoding.Auto;
                        barcode.Version = BarcodeLib.Barcode.QRCode.QRCodeVersion.Auto;
                        barcode.ECL = BarcodeLib.Barcode.QRCode.ErrorCorrectionLevel.L;
                        bytesQRCode = barcode.drawBarcodeAsBytes();
                    }

                    #endregion

                    Image imageQRCode = Image.GetInstance(bytesQRCode);
                    imageQRCode.Alignment = (Image.TEXTWRAP | Image.ALIGN_LEFT);
                    imageQRCode.ScaleToFit(90f, 90f);
                    imageQRCode.IndentationLeft = 9f;
                    imageQRCode.SpacingAfter = 9f;
                    imageQRCode.BorderColorTop = Color.WHITE;

                    cel = new Cell(imageQRCode);
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.HorizontalAlignment = Element.ALIGN_CENTER;
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = (float).5;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Rowspan = 6;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("SELLO DIGITAL DEL EMISOR\n", f5L));
                    par.Add(new Chunk(electronicDocument.Data.Sello.Value, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.Colspan = 2;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("FOLIO FISCAL:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(objTimbre.Uuid.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("FECHA Y HORA DE CERTIFICACION:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    string[] fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value).GetDateTimeFormats('s');

                    cel = new Cell(new Phrase(fechaTimbrado[0], f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL SAT:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(objTimbre.NumeroCertificadoSat.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = 0;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase("No. DE SERIE DEL CERTIFICADO DEL EMISOR:", f5L));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    adicional.AddCell(cel);

                    cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value, f5));
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = (float).5;
                    cel.BorderWidthBottom = (float).5;
                    adicional.AddCell(cel);

                    string lbRegimen = "REGIMEN FISCAL APLICABLE: ";
                    StringBuilder regimenes = new StringBuilder();
                    if (electronicDocument.Data.Emisor.Regimenes.IsAssigned)
                    {
                        for (int i = 0; i < electronicDocument.Data.Emisor.Regimenes.Count; i++)
                        {
                            regimenes.Append(electronicDocument.Data.Emisor.Regimenes[i].Regimen.Value).Append("\n");
                        }
                    }
                    else
                    {
                        regimenes.Append("");
                        lbRegimen = "";
                    }

                    string cuenta = electronicDocument.Data.NumeroCuentaPago.IsAssigned
                                    ? electronicDocument.Data.NumeroCuentaPago.Value
                                    : "";
                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("TIPO DE COMPROBANTE: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.TipoComprobante.Value + "   |   ", f5));
                    par.Add(new Chunk("Moneda: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.Moneda.Value + "   |   ", f5));
                    par.Add(new Chunk("TASA DE CAMBIO: ", f5L));
                    string tasaCambio = electronicDocument.Data.TipoCambio.Value;
                    if (tasaCambio.Length > 0)
                    {
                        par.Add(new Chunk(Convert.ToDouble(tasaCambio).ToString("C", _ci) + "   |   ", f5));
                    }
                    else
                    {
                        par.Add(new Chunk("   |   ", f5));
                    }
                    par.Add(new Chunk("FORMA DE PAGO: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "\n", f5));
                    par.Add(new Chunk("MÉTODO DE PAGO: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value + "   |   ", f5));
                    par.Add(new Chunk("NÚMERO DE CUENTA: ", f5L));
                    par.Add(new Chunk(cuenta + "   |   ", f5));
                    par.Add(new Chunk(lbRegimen, f5L));
                    par.Add(new Chunk(regimenes.ToString(), f5));
                    cel.BorderColor = gris;
                    cel = new Cell(par);
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Colspan = 2;
                    cel.BorderColor = gris;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("CADENA ORIGINAL DEL COMPLEMENTO DE CERTIFICACIÓN DIGITAL DEL SAT\n", f5L));
                    par.Add(new Chunk(electronicDocument.FingerPrintPac, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = (float).5;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = (float).5;
                    cel.Colspan = 3;
                    adicional.AddCell(cel);

                    par = new Paragraph();
                    par.KeepTogether = true;
                    par.SetLeading(7f, 0f);
                    par.Add(new Chunk("SELLO DIGITAL DEL SAT\n", f5L));
                    par.Add(new Chunk(objTimbre.SelloSat.Value, f5).SetSplitCharacter(split));
                    cel = new Cell(par);
                    cel.BorderColor = gris;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthBottom = 0;
                    cel.Colspan = 3;
                    adicional.AddCell(cel);
                }
                #endregion

                #region "Construimos Tabla del Footer"

                PdfPTable footer = new PdfPTable(1);
                footer.WidthPercentage = 100;
                footer.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;

                cell = new PdfPCell(new Phrase("", f5));
                cell.BorderWidthTop = 0;
                cell.BorderWidthLeft = 0;
                cell.BorderWidthRight = 0;
                cell.BorderWidthBottom = 0;
                footer.AddCell(cell);

                cell = new PdfPCell(new Phrase("ESTE DOCUMENTO ES UNA REPRESENTACIÓN IMPRESA DE UN CFDI", titulo));
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.BackgroundColor = azul;
                cell.BorderWidthTop = 0;
                cell.BorderWidthLeft = 0;
                cell.BorderWidthRight = 0;
                cell.BorderWidthBottom = 0;
                footer.AddCell(cell);

                #endregion

                pageEventHandler.encabezado = encabezado;
                pageEventHandler.encPartidas = encabezadoPartidas;
                pageEventHandler.footer = footer;

                document.Open();

                document.Add(partidas);
                document.Add(comentarios);
                document.Add(especial);
                document.Add(adicional);

                document.Close();

                #endregion
            }
            catch (Exception ex)
            {
                string exe = ex.Message;
            }
        }
예제 #26
0
 protected void AddNewCell(iTextSharp.text.Table table, string text, iTextSharp.text.Font font, int hAlignment)
 {
     Cell cell;
     if (font == null)
         cell = new Cell(new Phrase(ConvertNewLines(text)));
     else
         cell = new Cell(new Phrase(ConvertNewLines(text), font));
     
     cell.VerticalAlignment = Element.ALIGN_MIDDLE;
     cell.HorizontalAlignment = hAlignment;
     table.AddCell(cell);
 }
            public void OnStartPage(PdfWriter writer, Document document)
            {
                var pessoaJuridica = empresa.Pessoa as IPessoaJuridica;

                Chunk imagem;

                if (!string.IsNullOrEmpty(pessoaJuridica.Logomarca))
                {
                    var imghead = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath(pessoaJuridica.Logomarca));
                    imagem = new Chunk(imghead, 0, 0);
                }
                else
                    imagem = new Chunk("");

                var dadosEmpresa = new Phrase();

                dadosEmpresa.Add(pessoaJuridica.NomeFantasia + Environment.NewLine);

                if (pessoaJuridica.Enderecos.Count > 0)
                {
                    var endereco = pessoaJuridica.Enderecos[0];
                    dadosEmpresa.Add(endereco.ToString());
                }

                if (pessoaJuridica.Telefones.Count > 0)
                {
                    var telefone = pessoaJuridica.Telefones[0];
                    dadosEmpresa.Add("Telefone " + telefone);
                }

                var tabelaHeader = new Table(2);
                tabelaHeader.Border = 0;
                tabelaHeader.Width = 100;

                var cell = new Cell(new Phrase(imagem));
                cell.Border = 0;
                cell.Width = 30;

                tabelaHeader.AddCell(cell);

                var cell1 = new Cell(dadosEmpresa);
                cell1.Border = 0;
                cell1.Width = 70;
                tabelaHeader.AddCell(cell1);

                var linhaVazia = new Cell(new Phrase("\n", font2));
                linhaVazia.Colspan = 2;
                linhaVazia.DisableBorderSide(1);

                tabelaHeader.AddCell(linhaVazia);

                document.Add(tabelaHeader);

                // Adicionando linha que informa o número da revista

                var tabelaNumeroDaRevista = new Table(1);
                tabelaNumeroDaRevista.Border = 0;
                tabelaNumeroDaRevista.Width = 100;

                var celulaNumeroDaRevista = new Cell(new Phrase("Processos de clientes publicados na revista de marcas: " + _numeroDaRevistaSelecionada, font3));
                celulaNumeroDaRevista.Border = 0;
                celulaNumeroDaRevista.Width = 70;
                celulaNumeroDaRevista.Colspan = 1;

                tabelaNumeroDaRevista.AddCell(celulaNumeroDaRevista);

                var linhaVaziaNumeroRevista = new Cell(new Phrase("\n", font2));
                linhaVaziaNumeroRevista.Border = 0;
                linhaVaziaNumeroRevista.Width = 70;
                linhaVaziaNumeroRevista.Colspan = 1;
                linhaVaziaNumeroRevista.DisableBorderSide(1);

                tabelaNumeroDaRevista.AddCell(linhaVaziaNumeroRevista);

                document.Add(tabelaNumeroDaRevista);
            }
예제 #28
0
        // adiciona uma célula à tabela onde cada porção de texto tem uma formatação própria
        protected void AddNewCell(iTextSharp.text.Table table, List<Chunk> chunks)
        {
            Phrase f = new Phrase();
            f.Leading = 10;
            foreach (Chunk c in chunks)
                f.Add(new iTextSharp.text.Chunk(ConvertNewLines(c.Text), c.Font));

            Cell cell = new Cell(f);
            cell.VerticalAlignment = Element.ALIGN_TOP;
            cell.HorizontalAlignment = Element.ALIGN_LEFT;
            table.AddCell(cell);
        }
예제 #29
0
        public static Cell GetCell(Properties attributes)
        {
            Cell cell = new Cell();
            String value;

            cell.SetHorizontalAlignment(attributes[ElementTags.HORIZONTALALIGN]);
            cell.SetVerticalAlignment(attributes[ElementTags.VERTICALALIGN]);
            value = attributes[ElementTags.WIDTH];
            if (value != null) {
                cell.SetWidth(value);
            }
            value = attributes[ElementTags.COLSPAN];
            if (value != null) {
                cell.Colspan = int.Parse(value);
            }
            value = attributes[ElementTags.ROWSPAN];
            if (value != null) {
                cell.Rowspan = int.Parse(value);
            }
            value = attributes[ElementTags.LEADING];
            if (value != null) {
                cell.Leading = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            cell.Header = Utilities.CheckTrueOrFalse(attributes, ElementTags.HEADER);
            if (Utilities.CheckTrueOrFalse(attributes, ElementTags.NOWRAP)) {
                cell.MaxLines = 1;
            }
            SetRectangleProperties(cell, attributes);
            return cell;
        }
예제 #30
0
 // adiciona uma célula com o texto organizado em várias linhas diferentes
 protected void AddNewCell(iTextSharp.text.Table table, List<string> paragraphs, iTextSharp.text.Font font)
 {
     Cell cell = new Cell();
     foreach (string paragraph in paragraphs)
     {
         iTextSharp.text.Chunk chunk = new iTextSharp.text.Chunk(ConvertNewLines(paragraph), font);
         Paragraph p = new Paragraph(10, chunk);
         cell.Add(p);
     }
     cell.VerticalAlignment = Element.ALIGN_TOP;
     cell.HorizontalAlignment = Element.ALIGN_LEFT;
     table.AddCell(cell);
 }