A Table is a Rectangle that contains Cells, ordered in some kind of matrix.
Tables that span multiple pages are cut into different parts automatically. If you want a table header to be repeated on every page, you may not forget to mark the end of the header section by using the method EndHeaders().

The matrix of a table is not necessarily an m x n-matrix. It can contain holes or cells that are bigger than the unit. Believe me or not, but it took some serious thinking to make this as userfriendly as possible. I hope you wil find the result quite simple (I love simple solutions, especially for complex problems).

Наследование: Rectangle, ILargeElement
Пример #1
0
    public static bool ExportPDF(string path)
    {
        try
        {
        //            string path = "D:\\RebateForm" + confirmDetailsRow.ConfirmationID + ".pdf"; //Server.MapPath(ConfigurationManager.AppSettings["ExportPDF"] + misc.RandomString(6, true) + ".pdf");
            Document document = new Document(PageSize.A4, 3, 3, 10, 10);
            PdfWriter.GetInstance(document, new FileStream(path, FileMode.Create));

            Phrase ph = new Phrase("All Information Deemed Accurate but not Warranted\n EQUAL HOUSING OPPERTUNITY", FontFactory.GetFont(FontFactory.HELVETICA, 10, new Color(51, 51, 51)));
            HeaderFooter footer = new HeaderFooter(ph, false);
            footer.Border = 0;
            footer.Alignment = Element.ALIGN_CENTER;
            document.Footer = footer;

            document.Open();
            iTextSharp.text.Table tblMain = new iTextSharp.text.Table(2);
            tblMain.Border = 0;
            tblMain.DefaultCellBorder = 0;
            tblMain.Cellpadding = 2;
            SetTitle(confirmDetailsRow, tblMain);
            SetContactInfo(confirmDetailsRow, tblMain);

            document.Add(tblMain);
            document.Close();
            return true;
        }
        catch (Exception)
        {
            //return false;
            throw;
        }
    }
        protected override void FillContents() {
            Table detailsTable = new Table(6, 1);

            //este offset deve passar novamente para 0 caso se volte a usar Tables em vez de PdfTables
            detailsTable.Offset = 3;
            detailsTable.Width = 100;
            detailsTable.BorderColor = iTextSharp.text.Color.LIGHT_GRAY;
            detailsTable.DefaultCellBorderColor = iTextSharp.text.Color.LIGHT_GRAY;
            detailsTable.Padding = 3;
            detailsTable.CellsFitPage = true;

            //float indentPercent = (0.0f + 5.0f) * 100f / 21.6f;
            // uma página A4 tem 21.6 cm
            //detailsTable.Widths = new float[] { 10, indentPercent, 19, 100 - 19 - 19 - 10 - indentPercent }; //, 19 };
            detailsTable.Widths = new float[] { 20, 20, 20, 20, 20, 20 };

            AddNewCell(detailsTable, "Identificador do Documento", this.BodyFont);
            AddNewCell(detailsTable, "Código Referência", this.BodyFont);
            AddNewCell(detailsTable, "Designação", this.BodyFont);
            AddNewCell(detailsTable, "Identificador do Movimento", this.BodyFont);
            AddNewCell(detailsTable, "Data de Requisição", this.BodyFont);
            AddNewCell(detailsTable, "Entidade e notas", this.BodyFont);

            foreach (MovimentoRule.DocumentoRequisicaoInfo doc in this.documentos) {
                AddDocumentoRequisitado(detailsTable, doc);
                DoRemovedEntries(1);
            }

            AddTable(base.mDoc, detailsTable);
        }
Пример #3
0
 public static void Export(DetailsView dvGetStudent)
 {
     int rows = dvGetStudent.Rows.Count;
     int columns = dvGetStudent.Rows[0].Cells.Count;
     int pdfTableRows = rows;
     iTextSharp.text.Table PdfTable = new iTextSharp.text.Table(2, pdfTableRows);
     PdfTable.BorderWidth = 1;
     PdfTable.Cellpadding = 0;
     PdfTable.Cellspacing = 0;
     for (int rowCounter = 0; rowCounter < rows; rowCounter++)
     {
         for (int columnCounter = 0; columnCounter < columns; columnCounter++)
         {
             string strValue = dvGetStudent.Rows[rowCounter].Cells[columnCounter].Text;
             PdfTable.AddCell(strValue);
         }
     }
     Document Doc = new Document();
     PdfWriter.GetInstance(Doc, HttpContext.Current.Response.OutputStream);
     Doc.Open();
     Doc.Add(PdfTable);
     Doc.Close();
     HttpContext.Current.Response.ContentType = "application/pdf";
     HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=StudentDetails.pdf");
     HttpContext.Current.Response.End();
 }
Пример #4
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();
        }
Пример #5
0
        public static void Export(DetailsView dvGetStudent, string imageFilePath, string filename)
        {
            int rows = dvGetStudent.Rows.Count;
            int columns = dvGetStudent.Rows[0].Cells.Count;
            int pdfTableRows = rows - 1;
            iTextSharp.text.Table PdfTable = new iTextSharp.text.Table(2, pdfTableRows);
            //PdfTable.BorderWidth = 1;
            PdfTable.Cellpadding = 0;
            PdfTable.Cellspacing = 0;
            iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageFilePath);
            jpg.Alignment = Element.ALIGN_CENTER;
            jpg.ScaleToFit(150f, 150f);
            string fontUrl = System.AppDomain.CurrentDomain.BaseDirectory + "Files\\arial.ttf";
            BaseFont STF_Helvetica_Russian = BaseFont.CreateFont(fontUrl, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font font = new Font(STF_Helvetica_Russian, Font.DEFAULTSIZE, Font.NORMAL);
            for (int rowCounter = 1; rowCounter < rows; rowCounter++)
            {
                for (int columnCounter = 0; columnCounter < columns; columnCounter++)
                {
                    string strValue = dvGetStudent.Rows[rowCounter].Cells[columnCounter].Text;

                    PdfTable.AddCell(new Paragraph(strValue, font));
                }
            }
            Document Doc = new Document();

            PdfWriter.GetInstance(Doc, HttpContext.Current.Response.OutputStream);
            Doc.Open();
            Doc.Add(jpg);
            Doc.Add(PdfTable);
            Doc.Close();
            HttpContext.Current.Response.ContentType = "application/pdf";
            HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + filename + ".pdf");
            HttpContext.Current.Response.End();
        }
Пример #6
0
 /**
 * Creates a Table object based on this TableAttributes object.
 * @return a com.lowagie.text.Table object
 * @throws BadElementException
 */
 public Table CreateTable() {
     if (content.Count == 0) throw new BadElementException("Trying to create a table without rows.");
     SimpleCell rowx = (SimpleCell)content[0];
     int columns = 0;
     foreach (SimpleCell cell in rowx.Content) {
         columns += cell.Colspan;
     }
     float[] widths = new float[columns];
     float[] widthpercentages = new float[columns];
     Table table = new Table(columns);
     table.Alignment = alignment;
     table.Spacing = cellspacing;
     table.Padding = cellpadding;
     table.CloneNonPositionParameters(this);
     int pos;
     foreach (SimpleCell row in content) {
         pos = 0;
         foreach (SimpleCell cell in row.Content) {
             table.AddCell(cell.CreateCell(row));
             if (cell.Colspan == 1) {
                 if (cell.Width > 0) widths[pos] = cell.Width;
                 if (cell.Widthpercentage > 0) widthpercentages[pos] = cell.Widthpercentage;
             }
             pos += cell.Colspan;
         }
     }
     float sumWidths = 0f;
     for (int i = 0; i < columns; i++) {
         if (widths[i] == 0) {
             sumWidths = 0;
             break;
         }
         sumWidths += widths[i];
     }
     if (sumWidths > 0) {
         table.Width = sumWidths;
         table.Locked = true;
         table.Widths = widths;
     }
     else {
         for (int i = 0; i < columns; i++) {
             if (widthpercentages[i] == 0) {
                 sumWidths = 0;
                 break;
             }
             sumWidths += widthpercentages[i];
         }
         if (sumWidths > 0) {
             table.Widths = widthpercentages;
         }
     }
     if (width > 0) {
         table.Width = width;
         table.Locked = true;
     }
     else if (widthpercentage > 0) {
         table.Width = widthpercentage;
     }
     return table;
 }
Пример #7
0
        protected override void FillContents()
        {
            Table detailsTable = new Table(7, 1);

            //este offset deve passar novamente para 0 caso se volte a usar Tables em vez de PdfTables
            detailsTable.Offset = 3;
            detailsTable.Width = 100;
            detailsTable.BorderColor = iTextSharp.text.Color.LIGHT_GRAY;
            detailsTable.DefaultCellBorderColor = iTextSharp.text.Color.LIGHT_GRAY;
            detailsTable.Padding = 3;
            detailsTable.CellsFitPage = true;

            //float indentPercent = (0.0f + 5.0f) * 100f / 21.6f;
            // uma página A4 tem 21.6 cm
            detailsTable.Widths = new float[] { 8, 10, 15, 15, 8, 15, 100 - 8 - 10 - 15 - 15 - 8 - 15 };

            AddNewCell(detailsTable, "Ident. mov.", this.BodyFont);
            AddNewCell(detailsTable, "Tipo mov.", this.BodyFont);
            AddNewCell(detailsTable, "Data mov.", this.BodyFont);
            AddNewCell(detailsTable, "Entidade", this.BodyFont);
            AddNewCell(detailsTable, "Ident. doc.", this.BodyFont);
            AddNewCell(detailsTable, "Código Referência", this.BodyFont);
            AddNewCell(detailsTable, "Título doc.", this.BodyFont);

            foreach (Movimento mov in movimentos)
            {
                AddMovimento(detailsTable, mov);
                DoRemovedEntries(1);
            }

            AddTable(base.mDoc, detailsTable);
        }
        //        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);
        }
 private void AddDocumentoRequisitado(Table detailsTable, MovimentoRule.DocumentoRequisicaoInfo documento) {
     AddNewCell(detailsTable, documento.idNivel.ToString(), this.ContentFont);
     AddNewCell(detailsTable, documento.Codigo_Completo, this.ContentFont);
     AddNewCell(detailsTable, documento.ND_Designacao, this.ContentFont);
     // Identificador movimento
     AddNewCell(detailsTable, documento.idMovimento.ToString(), this.ContentFont);
     // Data:
     AddNewCell(detailsTable, documento.data.ToString(), this.ContentFont);
     // Entidade + Notas
     AddNewCell(detailsTable, documento.entidade + "\n" + documento.notas, this.ContentFont);
 }
        public void AddTableInPdfDocument( string tableIdentifier, Table table )
        {
            var fieldsInTemplate = _pdfDocument.PDFFields.GetFieldPositions( tableIdentifier );
            var targetContainerDetails = new TargetContainerDetails( fieldsInTemplate[0] );

            var pdfContent = _pdfDocument.PDFStamper.GetOverContent( targetContainerDetails.Page );

            pdfContent.CreateTemplate( targetContainerDetails.Width, targetContainerDetails.Height );
            var pdfTable = GetPdfTable( targetContainerDetails.Width, table );

            pdfTable.WriteSelectedRows( 0, 50, targetContainerDetails.Left, targetContainerDetails.Top, pdfContent );
        }
Пример #11
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);
        }
Пример #12
0
        public static void write_pdf()
        {
            string sFilePDF="myFile.pdf";

            // step 1: creation of a document-object

            Document document = new Document();

            try
            {
                // step 2:

                // we create a writer that listens to the document

                // and directs a PDF-stream to a file

                PdfWriter writer = PdfWriter.GetInstance(document,
                                   new FileStream(sFilePDF, FileMode.Create));

                // step 3: we open the document

                document.Open();

                // step 4: we create a table and add it to the document

                Table aTable = new Table(2, 2);    // 2 rows, 2 columns

                aTable.AddCell("0.0");

                aTable.AddCell("0.1");
                aTable.AddCell("1.0");
                aTable.AddCell("1.1");
                document.Add(aTable);

            }
            catch (DocumentException de)
            {
                Console.WriteLine(de.ToString());
            }
            catch (IOException ioe)
            {
                Console.WriteLine(ioe.ToString());
            }

            // step 5: we close the document

            document.Close();
        }
        private void EscrevaProcessosNoDocumento()
        {
            Table tabela = new Table(9);

            tabela.Widths = new Single[] {100, 100, 100, 100, 100, 400, 400, 90, 85};

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

            var corBackgroudHeader = new Color(211, 211, 211);

            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Número do processo", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data do cadastro", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data do depósito", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data de concessão", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Data da vigência", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Marca", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Cliente", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Despacho", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Ativo?", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));

            tabela.EndHeaders();

            foreach (var processo in _processos)
            {
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Processo.ToString(), _Fonte1, Cell.ALIGN_CENTER,0, false));
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDoCadastro.ToString("dd/MM/yyyy"), _Fonte1, Cell.ALIGN_CENTER, 0, false));
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDoDeposito.HasValue ? processo.DataDoDeposito.Value.ToString("dd/MM/yyyy") : "", _Fonte1, Cell.ALIGN_CENTER, 0, false));
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDeConcessao.HasValue ? processo.DataDeConcessao.Value.ToString("dd/MM/yyyy") : "", _Fonte1, Cell.ALIGN_CENTER, 0, false));
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.DataDaVigencia.HasValue ? processo.DataDaVigencia.Value.ToString("dd/MM/yyyy") : "", _Fonte1, Cell.ALIGN_CENTER, 0, false));
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.DescricaoDaMarca, _Fonte1, Cell.ALIGN_LEFT,0 , false));
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.Cliente.Pessoa.Nome, _Fonte1, Cell.ALIGN_LEFT, 0, false));
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Despacho != null ? processo.Despacho.CodigoDespacho.ToString() : "", _Fonte1, Cell.ALIGN_CENTER, 0, false));

                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Ativo ? "SIM" : "NÃO", _Fonte1, Cell.ALIGN_CENTER, 0, false));
            }

            _documento.Add(tabela);
            //  Chunk linhaQuantidadeDeItens = new Chunk(String.Concat("Quantidade de processos de marcas : ", _processos.Count), _Fonte4);
               // _documento.Add(linhaQuantidadeDeItens);
        }
        private void EscrevaProcessosNoDocumentoAnalitico()
        {
            var tabela = new Table(1);

            tabela.Widths = new Single[] { 218 };

            tabela.Padding = 0;
            tabela.Spacing = 0;
            tabela.Width = 100;
            tabela.AutoFillEmptyCells = true;
            tabela.DefaultCell.Border = Rectangle.NO_BORDER;

            tabela.EndHeaders();

            foreach (var revistaDePatente in _revistasPatentes)
            {
                var tabela1 = new Table(1);
                tabela1.Widths = new Single[] { 100 };
                tabela1.Padding = 0;
                tabela1.Spacing = 0;
                tabela1.Width = 100;
                tabela1.AutoFillEmptyCells = true;
                tabela1.Border = 0;
                tabela1.EndHeaders();
                tabela1.DefaultCell.Border = Rectangle.NO_BORDER;

                var tabelaProcesso = new Cell(ObtenhaTabelaCelulaProcesso(revistaDePatente));
                tabela1.AddCell(tabelaProcesso);

                var tabelaRevistas = new Cell(ObtenhaTabelaInformacoesRevista(revistaDePatente));
                tabela1.AddCell(tabelaRevistas);

                tabela.AddCell(new Cell(tabela1));
                tabela.AddCell(ObtenhaCelulaVazia());
                tabela.AddCell(ObtenhaCelulaVazia());
                tabela.AddCell(ObtenhaCelulaVazia());
            }

            _documento.Add(tabela);
        }
Пример #15
0
 // Tables					// Report item table
 public bool TableStart(Table t, Row row)
 {
     return true;
 }
        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);
        }
            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);
            }
        private void EscrevaProcessosNoDocumentoSintetico()
        {
            var tabela = new Table(4);

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

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

            var corBackgroudHeader = new Color(211, 211, 211);

            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Número do processo", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Marca", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Despacho", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true));
            tabela.AddCell(iTextSharpUtilidades.CrieCelula("Cliente", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true));

            tabela.EndHeaders();

            foreach (var processo in _processos)
            {
                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Processo.ToString(), _Fonte1, Cell.ALIGN_CENTER, 0, false));

                if (processo.Marca != null && !string.IsNullOrEmpty(processo.Marca.DescricaoDaMarca))
                    tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.DescricaoDaMarca, _Fonte1, Cell.ALIGN_LEFT, 0, false));
                else
                    tabela.AddCell(iTextSharpUtilidades.CrieCelula(string.Empty, _Fonte1, Cell.ALIGN_LEFT, 0, false));

                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Despacho != null ? processo.Despacho.CodigoDespacho : "", _Fonte1, Cell.ALIGN_CENTER, 0, false));

                tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.Cliente.Pessoa.Nome, _Fonte1, Cell.ALIGN_LEFT, 0, false));
            }

            _documento.Add(tabela);
        }
Пример #19
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;
            }
        }
Пример #20
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;
            }
        }
Пример #21
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;
            }
        }
Пример #22
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);
        }
    }
Пример #23
0
        /// <summary>
        /// Create a PDF representation of the table
        /// </summary>
        /// <param name="inputTable">
        /// The <c>Table</c> to parse
        /// </param>
        /// <returns>
        /// A PDF Table
        /// </returns>
        private static PdfPTable CreatePdf(Table inputTable)
        {
            if (inputTable.Children.Count > 0 && inputTable.Children[0] != null)
            {
                TableRow firstRow = inputTable.GetRow(0);
                int cols = firstRow.CellCount;
                var table = new PdfPTable(cols);
                foreach (TableRow row in inputTable.Children)
                {
                    if (row != null)
                    {
                        foreach (TableCell tableCell in row.Children)
                        {
                            if (tableCell != null)
                            {
                                var cell = new PdfPCell(new Paragraph(tableCell.Text))
                                {
                                    Rowspan = tableCell.RowSpan,
                                    Colspan = tableCell.ColumnSpan,
                                    Padding = 3.0f,
                                    HorizontalAlignment = Element.ALIGN_CENTER,
                                    VerticalAlignment = Element.ALIGN_MIDDLE,
                                    BorderColor = _borderColor,
                                    BackgroundColor = _defaultBackgroundColor
                                };

                                cell.Phrase.Font.SetFamily("Helvetica");
                                cell.Phrase.Font.SetStyle(Font.NORMAL);

                                if (tableCell.HasClass(HtmlClasses.SliceKeyTitle))
                                {
                                    cell.Phrase.Font.SetStyle(Font.BOLD);
                                    cell.BackgroundColor = _keyValueBackgroundColor;
                                    cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                                }
                                else if (tableCell.HasClass(HtmlClasses.VerticalKeyTitle)
                                         || tableCell.HasClass(HtmlClasses.HorizontalKeyTitle))
                                {
                                    cell.Phrase.Font.SetStyle(Font.BOLD);
                                    cell.BackgroundColor = _keyValueBackgroundColor;
                                }
                                else if (tableCell.HasClass(HtmlClasses.HorizontalKeyValue)
                                         || tableCell.HasClass(HtmlClasses.VerticalKeyValue))
                                {
                                    cell.BackgroundColor = _keyValueBackgroundColor;
                                }

                                // TODO handle this some other way
                                // if (td.Attr.TryGetValue("class", out clazz) && !String.IsNullOrEmpty(clazz)) {
                                // if ("keytitle".Contains(clazz.Substring(1))) {
                                // cell.Phrase.Font.SetStyle(Font.BOLD);
                                // cell.BackgroundColor = new BaseColor(0xDF, 0xEF, 0xFC);
                                // if (clazz.Contains("skeytitle")) {
                                // cell.HorizontalAlignment = Element.ALIGN_RIGHT;
                                // }
                                // }
                                // else if (clazz.Contains("keyvalue")) {
                                // cell.BackgroundColor = new BaseColor(0xDF, 0xEF, 0xFC);
                                // }

                                // }
                                table.AddCell(cell);
                            }
                        }
                    }
                }

                return table;
            }

            return null;
        }
Пример #24
0
 private static Table MakeTable(int dataColums, int rows)
 {
     var tbl = new Table(dataColums, rows);
     tbl.WidthPercentage = 100;
     tbl.Cellpadding = 0;
     tbl.Border = Border;
     tbl.CellsFitPage = true;
     tbl.SpaceInsideCell = 0;
     tbl.Spacing = 0;
     tbl.SpaceInsideCell = 0;
     return tbl;
 }
Пример #25
0
 public void TableBodyEnd(Table t, Row row)
 {
 }
Пример #26
0
 public void TableEnd(Table t, Row row)
 {
 }
Пример #27
0
        // methods to set the membervariables

        /**
         * Adds an element to this Cell.
         * <P>
         * Remark: you can't add ListItems, Rows, Cells,
         * JPEGs, GIFs or PNGs to a Cell.
         *
         * @param element The Element to add
         * @throws BadElementException if the method was called with a ListItem, Row or Cell
         */
        /// <summary>
        /// Adds an element to this Cell.
        /// </summary>
        /// <remarks>
        /// You can't add ListItems, Rows, Cells,
        /// JPEGs, GIFs or PNGs to a Cell.
        /// </remarks>
        /// <param name="element">the Element to add</param>
        public void AddElement(IElement element)
        {
            if (IsTable())
            {
                Table table = (Table)arrayList[0];
                Cell  tmp   = new Cell(element);
                tmp.Border  = NO_BORDER;
                tmp.Colspan = table.Columns;
                table.AddCell(tmp);
                return;
            }
            switch (element.Type)
            {
            case Element.LISTITEM:
            case Element.ROW:
            case Element.CELL:
                throw new BadElementException("You can't add listitems, rows or cells to a cell.");

            case Element.JPEG:
            case Element.IMGRAW:
            case Element.IMGTEMPLATE:
                arrayList.Add(element);
                break;

            case Element.LIST:
                if (float.IsNaN(this.Leading))
                {
                    leading = ((List)element).TotalLeading;
                }
                if (((List)element).IsEmpty())
                {
                    return;
                }
                arrayList.Add(element);
                return;

            case Element.ANCHOR:
            case Element.PARAGRAPH:
            case Element.PHRASE:
                if (float.IsNaN(leading))
                {
                    leading = ((Phrase)element).Leading;
                }
                if (((Phrase)element).IsEmpty())
                {
                    return;
                }
                arrayList.Add(element);
                return;

            case Element.CHUNK:
                if (((Chunk)element).IsEmpty())
                {
                    return;
                }
                arrayList.Add(element);
                return;

            case Element.TABLE:
                Table   table  = new Table(3);
                float[] widths = new float[3];
                widths[1] = ((Table)element).Width;

                switch (((Table)element).Alignment)
                {
                case Element.ALIGN_LEFT:
                    widths[0] = 0f;
                    widths[2] = 100f - widths[1];
                    break;

                case Element.ALIGN_CENTER:
                    widths[0] = (100f - widths[1]) / 2f;
                    widths[2] = widths[0];
                    break;

                case Element.ALIGN_RIGHT:
                    widths[0] = 100f - widths[1];
                    widths[2] = 0f;
                    break;
                }
                table.Widths = widths;
                Cell tmp;
                if (arrayList.Count == 0)
                {
                    table.AddCell(Cell.DummyCell);
                }
                else
                {
                    tmp         = new Cell();
                    tmp.Border  = NO_BORDER;
                    tmp.Colspan = 3;
                    foreach (IElement ele in arrayList)
                    {
                        tmp.Add(ele);
                    }
                    table.AddCell(tmp);
                }
                tmp        = new Cell();
                tmp.Border = NO_BORDER;
                table.AddCell(tmp);
                table.InsertTable((Table)element);
                tmp        = new Cell();
                tmp.Border = NO_BORDER;
                table.AddCell(tmp);
                table.AddCell(Cell.DummyCell);
                Clear();
                arrayList.Add(table);
                return;

            default:
                arrayList.Add(element);
                break;
            }
        }
Пример #28
0
 public void TableBodyStart(Table t, Row row)
 {
 }
Пример #29
0
        private void RenderProjectsReports()
        {
            if (this.ProjectList != null && this.ProjectList.Count > 0)
            {
                //  float[] DetailsHeaderwidths = {"100"}; // percentage
                iTextSharp.text.Table JobDetailstable = new iTextSharp.text.Table(1);

                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;
                Font myDetailFont = fntDetails;

                JobDetailstable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
                JobDetailstable.AddCell(new Phrase("Projects", fntDetails));

                foreach (var x in this.ProjectList)
                {
                    JobDetailstable.DefaultCell.BackgroundColor = Color.WHITE;
                    JobDetailstable.AddCell(new Phrase(x.Project_Number + " : " + x.Project_Name, fntDetails));
                }
                JobDetailstable.DefaultCell.BorderWidth = 0;
                JobDetailstable.AddCell(new Phrase(" ", fntDetails));
                JobDetailstable.AddCell(new Phrase(" ", fntDetails));
                JobDetailstable.AddCell(new Phrase(" ", fntDetails));
                JobDetailstable.AddCell(new Phrase(" ", fntDetails));
                JobDetailstable.AddCell(new Phrase(" ", fntDetails));
                JobDetailstable.AddCell(new Phrase(" ", fntDetails));
                doc.Add(JobDetailstable);
            }
        }
Пример #30
0
        /**
        * Creates an Table object based on a list of properties.
        * @param attributes
        * @return a Table
        */
        public static Table GetTable(Properties attributes)
        {
            String value;
            Table table;

            value = attributes[ElementTags.WIDTHS];
            if (value != null) {
                StringTokenizer widthTokens = new StringTokenizer(value, ";");
                ArrayList values = new ArrayList();
                while (widthTokens.HasMoreTokens()) {
                    values.Add(widthTokens.NextToken());
                }
                table = new Table(values.Count);
                float[] widths = new float[table.Columns];
                for (int i = 0; i < values.Count; i++) {
                    value = (String)values[i];
                    widths[i] = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                }
                table.Widths = widths;
            }
            else {
                value = attributes[ElementTags.COLUMNS];
                try {
                    table = new Table(int.Parse(value));
                }
                catch {
                    table = new Table(1);
                }
            }

            table.Border = Table.BOX;
            table.BorderWidth = 1;
            table.DefaultCell.Border = Table.BOX;

            value = attributes[ElementTags.LASTHEADERROW];
            if (value != null) {
                table.LastHeaderRow = int.Parse(value);
            }
            value = attributes[ElementTags.ALIGN];
            if (value != null) {
                table.SetAlignment(value);
            }
            value = attributes[ElementTags.CELLSPACING];
            if (value != null) {
                table.Spacing = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.CELLPADDING];
            if (value != null) {
                table.Padding = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.OFFSET];
            if (value != null) {
                table.Offset = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
            }
            value = attributes[ElementTags.WIDTH];
            if (value != null) {
                if (value.EndsWith("%"))
                    table.Width = float.Parse(value.Substring(0, value.Length - 1), System.Globalization.NumberFormatInfo.InvariantInfo);
                else {
                    table.Width = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo);
                    table.Locked = true;
                }
            }
            table.TableFitsPage = Utilities.CheckTrueOrFalse(attributes, ElementTags.TABLEFITSPAGE);
            table.CellsFitPage = Utilities.CheckTrueOrFalse(attributes, ElementTags.CELLSFITPAGE);
            table.Convert2pdfptable = Utilities.CheckTrueOrFalse(attributes, ElementTags.CONVERT2PDFP);

            SetRectangleProperties(table, attributes);
            return table;
        }
Пример #31
0
        // constructors
        /**
         * Constructs a <CODE>PdfTable</CODE>-object.
         *
         * @param   table   a <CODE>Table</CODE>
         * @param   left    the left border on the page
         * @param   right   the right border on the page
         * @param   top     the start position of the top of the table
         */
        internal PdfTable(Table table, float left, float right, float top, bool supportUpdateRowAdditions)
            : base(left, top, right, top)
        {
            // constructs a Rectangle (the bottomvalue will be changed afterwards)
            this.table = table;
            table.Complete();

            // copying the attributes from class Table
            CloneNonPositionParameters(table);

            this.columns = table.Columns;
            positions = table.GetWidths(left, right - left);

            // initialisation of some parameters
            Left = positions[0];
            Right = positions[positions.Length - 1];

            headercells = new ArrayList();
            cells = new ArrayList();

            UpdateRowAdditionsInternal();
            if (supportUpdateRowAdditions) {
                table.DeleteAllRows();
            }
        }