SetLeading() публичный Метод

public SetLeading ( float fixedLeading, float multipliedLeading ) : void
fixedLeading float
multipliedLeading float
Результат void
Пример #1
0
    public PdfPCell GetRichCell(string html, int colSpan = 1)
    {
        html = this.HtmlDecodeRichText(html);
        var cell = new PdfPCell {
            // Border = 1,
            HorizontalAlignment = Element.ALIGN_LEFT
        };

        iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph();
        p.SetLeading(0.1f, 0f);

        //   try {
        List <IElement> htmlArrayList = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(html), this.GetStyleSheet(true));

        p.InsertRange(0, htmlArrayList);
        //} catch (Exception ex) {
        //    var mh = new MySampleHandler();
        //    using (TextReader sr = new StringReader(html)) {
        //        XMLWorkerHelper.GetInstance().ParseXHtml(mh, sr);
        //    }
        //    p.InsertRange(0, mh.elements);
        //}
        cell.AddElement(p);
        cell.PaddingLeft = 4;
        cell.Colspan     = colSpan;
        return(cell);
    }
        /**
         * Creates a shallow clone of the Paragraph.
         * @return
         */
        public virtual Paragraph CloneShallow(bool spacingBefore)
        {
            Paragraph copy = new Paragraph();

            copy.Font      = Font;
            copy.Alignment = Alignment;
            copy.SetLeading(Leading, multipliedLeading);
            copy.IndentationLeft  = IndentationLeft;
            copy.IndentationRight = IndentationRight;
            copy.FirstLineIndent  = FirstLineIndent;
            copy.SpacingAfter     = SpacingAfter;
            if (spacingBefore)
            {
                copy.SpacingBefore = SpacingBefore;
            }
            copy.ExtraParagraphSpace = ExtraParagraphSpace;
            copy.Role = Role;
            copy.id   = ID;
            if (accessibleAttributes != null)
            {
                copy.accessibleAttributes = new Dictionary <PdfName, PdfObject>(accessibleAttributes);
            }
            copy.TabSettings  = this.TabSettings;
            copy.KeepTogether = this.KeepTogether;
            return(copy);
        }
Пример #3
0
        //说明:一个段落有一个且仅有一个间距,如果你添加了一个不同字体的短句或块,
        //原来的间距仍然有效,你可以通过SetLeading来改变间距,
        //但是段落中所有内容将使用新的中的间距
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            Document  document  = new Document();
            PdfWriter pdfWriter = PdfWriter.GetInstance(document, new FileStream("段落.pdf", FileMode.Create));

            document.Open();
            Paragraph p1 = new Paragraph(new Chunk("This is the fist paragraph",
                                                   FontFactory.GetFont(FontFactory.HELVETICA, 12)));

            //段落中插入chunk
            Chunk ck1 = new Chunk("Test chunk eea fafafe fafeefaeefefeafaefafafaeeea fafafe fafeefaeefefeafae", FontFactory.GetFont(FontFactory.COURIER,
                                                                                                                                    20, BaseColor.BLUE));

            p1.Add(ck1);
            p1.SetLeading(10, 1);

            Paragraph p2 = new Paragraph(new Phrase("This is the second paragraph",
                                                    FontFactory.GetFont(FontFactory.HELVETICA, 12)));

            Paragraph p3 = new Paragraph("This is the third paragraph",
                                         FontFactory.GetFont(FontFactory.HELVETICA, 12));

            document.Add(p1);
            document.Add(p2);
            document.Add(p3);

            document.Close();
            this.Title = "段落";
        }
Пример #4
0
        public static Paragraph GetParagraph(string text, Fonts type, int align = Element.ALIGN_LEFT)
        {
            Paragraph p;
            switch (type)
            {
                case Fonts.Footer:
                    p = new Paragraph(text, FooterFont);
                    break;

                case Fonts.ExtraLarge:
                    p = new Paragraph(text, ExtraLargeFont);
                    break;

                case Fonts.Large:
                    p = new Paragraph(text);
                    break;

                case Fonts.Compact:
                    p = new Paragraph(text, StandardFont);
                    p.SetLeading(0, 0.8f);
                    break;

                case Fonts.Standard:
                    p = new Paragraph(text, StandardFont);
                    break;

                default: throw new ArgumentOutOfRangeException("type");
            }

            p.Alignment = align;

            return p;
        }
Пример #5
0
        public ResultResponse GenerateWorkerBarcode(List <UserInformation> users)
        {
            ResultResponse resultResponse = new ResultResponse();

            var pgSize = new iTextSharp.text.Rectangle(100, 65);

            iTextSharp.text.Document doc = new iTextSharp.text.Document(pgSize, 0, 0, 0, 0);
            string   path     = HttpContext.Current.Server.MapPath("~/GenaratePDF/");
            DateTime dt       = DateTime.Now;
            string   fileName = dt.Minute.ToString() + dt.Second.ToString() + dt.Millisecond.ToString();

            PdfWriter.GetInstance(doc, new FileStream(path + fileName + ".pdf", FileMode.Create));
            //open the document for writing
            doc.Open();
            // doc.SetPageSize(new iTextSharp.text.Rectangle(100,65));
            PdfPTable pdftable = new PdfPTable(1);

            for (int i = 0; i < users.Count; i++)
            {
                int count = 0;
                iTextSharp.text.Font font = FontFactory.GetFont("Calibri", 6.0f, BaseColor.BLACK); // from 5.0f
                count++;
                var bw         = new ZXing.BarcodeWriter();
                var encOptions = new ZXing.Common.EncodingOptions()
                {
                    Margin = 0
                };                                                                      // margin 0 to 1
                bw.Options = encOptions;
                bw.Format  = ZXing.BarcodeFormat.PDF_417;
                var result = new Bitmap(bw.Write(users[i].UserSQNumber));
                result.Save(path + users[i].UserSQNumber, System.Drawing.Imaging.ImageFormat.Png);
                string first = "Employee Code : " + users[i].UserSQNumber;
                string last  = users[i].UserInformationName.ToString() + "\n" + users[i].DesignationName.ToString();
                iTextSharp.text.Paragraph paragraph     = new iTextSharp.text.Paragraph(first, font);
                iTextSharp.text.Paragraph lastparagraph = new iTextSharp.text.Paragraph(last, font);
                paragraph.SetLeading(1.0f, 1.0f);
                lastparagraph.SetLeading(1.0f, 1.0f);
                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(path + users[i].UserSQNumber);
                image.ScaleToFit(new iTextSharp.text.Rectangle(85, 100));
                image.SetAbsolutePosition(0.0f, 0.0f);
                image.PaddingTop = 2;
                PdfPCell cell = new PdfPCell {
                    PaddingLeft = 0, PaddingTop = 2, PaddingBottom = 0, PaddingRight = 0
                };
                // cell.FixedHeight = 60;
                cell.AddElement(paragraph);
                cell.AddElement(image);
                cell.AddElement(lastparagraph);
                cell.Border = 0;
                pdftable.AddCell(cell);
                File.Delete(path + users[i].UserSQNumber);
            }
            doc.Add(pdftable);
            doc.Close();
            resultResponse.isSuccess = true;
            resultResponse.data      = path + fileName + ".pdf";
            return(resultResponse);
        }
Пример #6
0
 /// <summary>
 /// Add a paragraph object containing the specified element to the PDF document.
 /// </summary>
 /// <param name="doc">Document to which to add the paragraph.</param>
 /// <param name="alignment">Alignment of the paragraph.</param>
 /// <param name="font">Font to assign to the paragraph.</param>
 /// <param name="content">Object that is the content of the paragraph.</param>
 private void AddParagraph(Document doc, int alignment, iTextSharp.text.Font font, iTextSharp.text.IElement content)
 {
     iTextSharp.text.Paragraph paragraph = new iTextSharp.text.Paragraph();
     paragraph.SetLeading(0f, 1.2f);
     paragraph.Alignment = alignment;
     paragraph.Font      = font;
     paragraph.Add(content);
     doc.Add(paragraph);
 }
 public static void AddParagraph(Document doc, int alignment, iTextSharp.text.Font font, iTextSharp.text.IElement content)
 {
     Paragraph paragraph = new Paragraph();
     paragraph.SetLeading(0f, 1.2f);
     paragraph.Alignment = alignment;
     paragraph.Font = font;
     paragraph.Add(content);
     doc.Add(paragraph);
 }
Пример #8
0
        public void ApplyNewLine()
        {
            if (this.CurrentLine.IsEmpty() == false)
            {
                var font = FontFactory.GetFont("courier", 8.2f, BaseColor.BLACK);
                var line = this.CurrentLine.ToString().TrimEndWhitespace();
                var para = new iTextSharp.text.Paragraph(line, font);
                para.SetLeading(0, 1.15f);
                this.Document.Add(para);
            }

            ClearCurrentLine();
        }
Пример #9
0
        /**
         * Creates a shallow clone of the Paragraph.
         * @return
         */
        public Paragraph cloneShallow(bool spacingBefore)
        {
            Paragraph copy = new Paragraph();

            copy.Font      = Font;
            copy.Alignment = Alignment;
            copy.SetLeading(Leading, multipliedLeading);
            copy.IndentationLeft  = IndentationLeft;
            copy.IndentationRight = IndentationRight;
            copy.FirstLineIndent  = FirstLineIndent;
            copy.SpacingAfter     = SpacingAfter;
            if (spacingBefore)
            {
                copy.SpacingBefore = SpacingBefore;
            }
            copy.ExtraParagraphSpace = ExtraParagraphSpace;
            return(copy);
        }
Пример #10
0
        /// <summary>
        ///  XMLWorker RTL sample.
        /// </summary>
        /// <param name="args"></param>
        ///
        public static PdfPCell GetRichCell(string html)
        {
            var cell = new PdfPCell {
                Border = 0,
                HorizontalAlignment = Element.ALIGN_LEFT
            };

            iTextSharp.text.Paragraph p = new iTextSharp.text.Paragraph();
            TextReader sr = new StringReader(html);

            // XMLWorkerHelper.GetInstance().ParseXHtml(elementsHandler, sr);
            System.Collections.Generic.List <IElement> htmlArrayList = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(html), null);
            p.SetLeading(0.1f, 0f);
            p.InsertRange(0, htmlArrayList);
            cell.AddElement(p);
            cell.PaddingLeft = 4;
            return(cell);
        }
Пример #11
0
        private static void SetParagraphLeading(Paragraph p, String leading) {
            if (leading == null) {
                p.SetLeading(0, 1.5f);
                return;
            }
            try {
                StringTokenizer tk = new StringTokenizer(leading, " ,");
                String v = tk.NextToken();
                float v1 = float.Parse(v, System.Globalization.NumberFormatInfo.InvariantInfo);
                if (!tk.HasMoreTokens()) {
                    p.SetLeading(v1, 0);
                    return;
                }
                v = tk.NextToken();
                float v2 = float.Parse(v, System.Globalization.NumberFormatInfo.InvariantInfo);
                p.SetLeading(v1, v2);
            }
            catch {
                p.SetLeading(0, 1.5f);
            }

        }
Пример #12
0
 protected void PopulateProperties(Paragraph copy, bool spacingBefore)
 {
     copy.Font      = Font;
     copy.Alignment = Alignment;
     copy.SetLeading(Leading, multipliedLeading);
     copy.IndentationLeft  = IndentationLeft;
     copy.IndentationRight = IndentationRight;
     copy.FirstLineIndent  = FirstLineIndent;
     copy.SpacingAfter     = SpacingAfter;
     if (spacingBefore)
     {
         copy.SpacingBefore = SpacingBefore;
     }
     copy.ExtraParagraphSpace = ExtraParagraphSpace;
     copy.Role = Role;
     copy.id   = ID;
     if (accessibleAttributes != null)
     {
         copy.accessibleAttributes = new Dictionary <PdfName, PdfObject>(accessibleAttributes);
     }
     copy.TabSettings  = this.TabSettings;
     copy.KeepTogether = this.KeepTogether;
 }
        public static Paragraph InsertSectionContent(string text, int fontSize, bool isHasColor = false, int type = 0)
        {
            var font = BaseFontAndSize("宋体", fontSize, Font.NORMAL);
            var font1 = BaseFontAndSize("宋体", fontSize, Font.BOLD,BaseColor.RED);
            var font2 = BaseFontAndSize("宋体", fontSize, Font.BOLD, new BaseColor(0, 162, 234));

            var font3 = BaseFontAndSize("宋体", fontSize, Font.NORMAL, BaseColor.RED);

            //正行字都变色
            if (type == 3)
            {
                font = font3;
            }

            var paragraph = new Paragraph
                {
                    FirstLineIndent = 24,
                    IndentationLeft = 20,//距左边差距
                    IndentationRight = 20,//距右边差距
                    SpacingBefore = 1,
                    SpacingAfter = 1
                };
            //行高间距
            paragraph.SetLeading(1, fontSize == 8 ? 1 : 2);
            //左对齐
            paragraph.Alignment = Element.ALIGN_LEFT;
            if (isHasColor)//是否要变色
            {
                var strList = text.Split('@');
                for (var i = 0; i < strList.Length;i++ )
                {
                    var val = strList[i];
                    var fo = font;
                    if (i%2 != 0) //“@@”里面的文字变色
                    {
                        var co = val.Split('#');
                        if (co.Length >= 2)
                        {
                            val = co[1];
                            fo = font2;
                        }
                        else
                        {
                            fo = font1;
                        }
                    }
                    //加入块
                    var ch = new Chunk(val, fo);
                    paragraph.Add(ch);
                }
            }
            else
            {
                var ch = new Chunk(text, font);
                paragraph.Add(ch);
            }
            return paragraph;
        }
 // 函数描述:插入底部信息
 public static Paragraph InsertTopFootParagraph(string text)
 {
     var font = BaseFontAndSize("华文中宋", 18, Font.BOLD);
     var paragraph = new Paragraph(text, font)
         {
             FirstLineIndent = 16,
             IndentationLeft = 0,
             IndentationRight = 20,
             SpacingBefore = 1,
             SpacingAfter = 1
         };
     paragraph.SetLeading(1, 2);
     //paragraph.IndentationLeft = 24;
     paragraph.Alignment = Element.ALIGN_CENTER;
     return paragraph;
 }
 // 函数描述: 格式化报告的标题----
 public static Paragraph InsertPictureTitle(string text)
 {
     var font = BaseFontAndSize("华文中宋", 12, Font.NORMAL);
     var paragraph = new Paragraph(text, font)
         {
             Alignment = Element.ALIGN_CENTER,
             SpacingBefore = 5,
             SpacingAfter = 5
         };
     paragraph.SetLeading(1, 2);
     return paragraph;
 }
Пример #16
0
 /// <summary>
 /// Add a paragraph object containing the specified element to the PDF document.
 /// </summary>
 /// <param name="doc">Document to which to add the paragraph.</param>
 /// <param name="alignment">Alignment of the paragraph.</param>
 /// <param name="font">Font to assign to the paragraph.</param>
 /// <param name="content">Object that is the content of the paragraph.</param>
 void AddParagraph(Document doc, int alignment, Font font, IElement content)
 {
     Paragraph paragraph = new Paragraph();
     paragraph.SetLeading(0f, 1.2f);
     paragraph.Alignment = alignment;
     paragraph.Font = font;
     paragraph.Add(content);
     doc.Add(paragraph);
 }
        public static Paragraph InsertSectionContent(string text, BaseColor color)
        {
            var font = BaseFontAndSize("宋体", 12, Font.NORMAL,color);
            var paragraph = new Paragraph(text, font)
            {
                FirstLineIndent = 24,
                IndentationLeft = 20,
                IndentationRight = 20,
                SpacingBefore = 1,
                SpacingAfter = 1
            };
            paragraph.SetLeading(1, 2);
            paragraph.Alignment = Element.ALIGN_LEFT;

            return paragraph;
        }
 // 函数描述:格式化“摘要”二字----
 public static Paragraph InsertSummaryParagraph(string text, int spaceNum)
 {
     var font = BaseFontAndSize("黑体", 12, Font.BOLD);
     var paragraph = new Paragraph(text, font)
         {
             Alignment = Element.ALIGN_JUSTIFIED,
             SpacingBefore = 1,
             IndentationLeft = 0,
             Font = {Size = 12},
             FirstLineIndent = 20,
             SpacingAfter = spaceNum
         };
     paragraph.SpacingBefore = spaceNum;
     paragraph.SetLeading(1, 2);  //设置行间距
     paragraph.Alignment = Element.ALIGN_LEFT;
     return paragraph;
 }
Пример #19
0
        public static Paragraph InsertTitleContent(string text)
        {
            try
            {
                Font fontTitle = new Font(basefont, 20, Font.BOLD);
                text = System.Web.HttpUtility.HtmlDecode(text);
                Paragraph paragraph = new Paragraph(text, fontTitle);//新建一行
                paragraph.Alignment = Element.ALIGN_CENTER;//居中
                paragraph.SpacingBefore = 10;
                paragraph.SpacingAfter = 10;
                paragraph.SetLeading(1, 2);//每行间的间隔

                return paragraph;
            }
            catch (Exception ex)
            {
                throw new Exception("HeaderAndFooterEvent-->InsertTitleContent-->" + ex.Message);
            }
        }
Пример #20
0
        public static void formatoCED110324NN4(Document document, ElectronicDocument electronicDocument, Data objTimbre, pdfPageEventHandlerCED110324NN4 pageEventHandler, Int64 idCfdi, DataTable dtOpcDet, Hashtable htCFDI, HttpContext hc)
        {
            try
            {
                DAL dal = new DAL();
                #region "Construimos el Documento"

                #region "Construimos el Encabezado"

                Table encabezado = new Table(3);
                float[] headerwidthsEncabezado = { 60, 20, 20 };
                encabezado.Widths = headerwidthsEncabezado;
                encabezado.WidthPercentage = 100;
                encabezado.Padding = 1;
                encabezado.Spacing = 1;
                encabezado.BorderWidth = 0;
                encabezado.DefaultCellBorder = 0;
                encabezado.BorderColor = gris;

                cel = new Cell(new Phrase("COMPROBANTE FISCAL DIGITAL POR INTERNET", f8LA));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Colspan = 3;
                encabezado.AddCell(cel);

                par = new Paragraph();
                par.KeepTogether = true;
                par.SetLeading(8f, 9f);
                par.Add(new Chunk(htCFDI["nombreEmisor"].ToString().ToUpper(), f8B));
                par.Add(new Chunk("\n\nRFC: " + htCFDI["rfcEmisor"].ToString().ToUpper(), f8L));
                par.Add(new Chunk("\n\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));
                cel = new Cell(par);
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                cel.Rowspan = 4;
                encabezado.AddCell(cel);

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

                cel = new Cell(new Phrase("Número de Certificado", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["serie"].ToString().ToUpper() + " " + htCFDI["folio"].ToString(), folio));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(electronicDocument.Data.NumeroCertificado.Value.ToString(), f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Fecha/Hora: ", f6B));
                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;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["fechaCfdi"].ToString(), f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

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

                cel = new Cell(new Phrase(electronicDocument.Data.TipoComprobante.Value.ToString(), f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("Expedido en: \n", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase("FOLIO FISCAL", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = grisOX;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                StringBuilder expedido = new StringBuilder();
                expedido.
                    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 = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                encabezado.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["UUID"].ToString(), f7B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                encabezado.AddCell(cel);

                //Tabla Receptor y Encabezados Detalle

                Table tReceptor = new Table(5);
                float[] headerwidthsReceptor = { 15, 15, 40, 15, 15 };
                tReceptor.Widths = headerwidthsReceptor;
                tReceptor.WidthPercentage = 100;
                tReceptor.Padding = 1;
                tReceptor.Spacing = 1;
                tReceptor.BorderWidth = 0;
                tReceptor.DefaultCellBorder = 0;
                tReceptor.BorderColor = gris;

                cel = new Cell(new Phrase("Receptor:\n", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 5;
                tReceptor.AddCell(cel);

                cel = new Cell(new Phrase(htCFDI["nombreReceptor"].ToString(), f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                cel.Colspan = 5;
                tReceptor.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\n", f6));
                par.Add(new Chunk(htCFDI["direccionReceptor1"].ToString() + "\n", f6));
                par.Add(new Chunk(htCFDI["direccionReceptor2"].ToString() + "\n", f6));
                par.Add(new Chunk(htCFDI["direccionReceptor3"].ToString() + "\n", f6));
                cel = new Cell(par);
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthBottom = 1;
                cel.Colspan = 5;
                tReceptor.AddCell(cel);

                cel = new Cell(new Phrase("Cantidad\n", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BackgroundColor = grisOX;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = grisOX;
                tReceptor.AddCell(cel);

                cel = new Cell(new Phrase("Unidad", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BackgroundColor = grisOX;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = grisOX;
                tReceptor.AddCell(cel);

                cel = new Cell(new Phrase("Descripción", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BackgroundColor = grisOX;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = grisOX;
                tReceptor.AddCell(cel);

                cel = new Cell(new Phrase("Precio Unitario", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BackgroundColor = grisOX;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = grisOX;
                tReceptor.AddCell(cel);

                cel = new Cell(new Phrase("Total", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BackgroundColor = grisOX;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = grisOX;
                tReceptor.AddCell(cel);

                #endregion

                #region "Construimos Tablas de Partidas"

                // Creamos la tabla para insertar los conceptos de detalle de la factura
                PdfPTable tableConceptos = new PdfPTable(5);

                int[] colWithsConceptos = new int[5];
                //String[] arrColWidthConceptos = dtConfigFact.Rows[0]["conceptosColWidth"].ToString().Split(new Char[] { ',' });
                String[] arrColWidthConceptos = { "15", "15", "40", "15", "15" };

                for (int i = 0; i < arrColWidthConceptos.Length; i++)
                {
                    colWithsConceptos.SetValue(Convert.ToInt32(arrColWidthConceptos[i]), i);
                }

                tableConceptos.SetWidths(colWithsConceptos);
                tableConceptos.WidthPercentage = 100F;

                int numConceptos = electronicDocument.Data.Conceptos.Count;
                PdfPCell cellConceptos = new PdfPCell();
                PdfPCell cellMontos = new PdfPCell();

                for (int i = 0; i < numConceptos; i++)
                {
                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT;
                    tableConceptos.AddCell(cellConceptos);

                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT;
                    tableConceptos.AddCell(cellConceptos);

                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value + "\nNo Identificación: " + dtOpcDet.Rows[i]["noIdent"].ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    tableConceptos.AddCell(cellConceptos);

                    cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellMontos.Border = 0;
                    cellMontos.HorizontalAlignment = PdfCell.ALIGN_JUSTIFIED;
                    tableConceptos.AddCell(cellMontos);

                    cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), new Font(Font.HELVETICA, 8, Font.NORMAL)));
                    cellMontos.Border = 0;
                    cellMontos.HorizontalAlignment = PdfCell.ALIGN_JUSTIFIED;
                    tableConceptos.AddCell(cellMontos);
                }

                #endregion

                #region "Construimos el Comentarios"

                Table comentarios = new Table(4);
                float[] headerwidthsComentarios = { 25, 25, 35, 15 };
                comentarios.Widths = headerwidthsComentarios;
                comentarios.WidthPercentage = 100;
                comentarios.Padding = 1;
                comentarios.Spacing = 1;
                comentarios.BorderWidth = 0;
                comentarios.DefaultCellBorder = 0;
                comentarios.BorderColor = gris;

                int idMoneda = 1;
                DataTable dtImporteLetra = dal.QueryDT("DS_FE", "SELECT dbo.convertNumToTextFunction(@0, @1) AS cantidadLetra", "F:S:" + electronicDocument.Data.Total.Value.ToString() + ";F:I:" + idMoneda, hc);

                cel = new Cell(new Phrase("Importe con Letra:\n" + dtImporteLetra.Rows[0]["cantidadLetra"].ToString(), f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                cel.Rowspan = 3;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Sub Total:", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 1;
                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), f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase("Total Trasladados:", f6B));
                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), f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 0;
                cel.BorderColor = gris;
                comentarios.AddCell(cel);

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

                cel = new Cell(new Phrase(electronicDocument.Data.Total.Value.ToString("C", _ci), f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BackgroundColor = grisOX;
                cel.BorderColor = grisOX;
                comentarios.AddCell(cel);

                #endregion

                #region "Construimos el Desglose de Impuestos"

                Table desgloseImpuestos = new Table(3);
                float[] headerwidthsDesgloce = { 15, 15, 70 };
                desgloseImpuestos.Widths = headerwidthsDesgloce;
                desgloseImpuestos.WidthPercentage = 100;
                desgloseImpuestos.Padding = 1;
                desgloseImpuestos.Spacing = 1;
                desgloseImpuestos.BorderWidth = 0;
                desgloseImpuestos.DefaultCellBorder = 0;
                desgloseImpuestos.BorderColor = gris;

                cel = new Cell(new Phrase("Desgloce de Impuestos", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                desgloseImpuestos.AddCell(cel);

                cel = new Cell(new Phrase("", f6B));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                desgloseImpuestos.AddCell(cel);

                for (int i = 0; i < electronicDocument.Data.Impuestos.Traslados.Count; i++)
                {
                    cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Traslados[i].Tipo.Value.ToString() + " " + electronicDocument.Data.Impuestos.Traslados[i].Tasa.Value.ToString() + "%", f6B));
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthLeft = 1;
                    cel.BorderWidthRight = 1;
                    cel.BorderWidthBottom = 0;
                    cel.BorderColor = gris;
                    desgloseImpuestos.AddCell(cel);

                    cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Traslados[i].Importe.Value.ToString("C", _ci), f6B));
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthRight = 1;
                    cel.BorderWidthBottom = 0;
                    cel.BorderColor = gris;
                    desgloseImpuestos.AddCell(cel);

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

                for (int i = 0; i < electronicDocument.Data.Impuestos.Retenciones.Count; i++)
                {
                    cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Retenciones[i].Tipo.Value.ToString(), f6B));
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthLeft = 1;
                    cel.BorderWidthRight = 1;
                    cel.BorderWidthBottom = 0;
                    cel.BorderColor = gris;
                    desgloseImpuestos.AddCell(cel);

                    cel = new Cell(new Phrase(electronicDocument.Data.Impuestos.Retenciones[i].Importe.Value.ToString("C", _ci), f6B));
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthRight = 1;
                    cel.BorderWidthBottom = 0;
                    cel.BorderColor = gris;
                    desgloseImpuestos.AddCell(cel);

                    cel = new Cell(new Phrase("", f6B));
                    cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                    cel.BorderWidthTop = 0;
                    cel.BorderWidthLeft = 0;
                    cel.BorderWidthRight = 0;
                    cel.BorderWidthBottom = 0;
                    cel.BorderColor = gris;
                    desgloseImpuestos.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", f5B));
                    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:", f5B));
                    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:", f5B));
                    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:", f5B));
                    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:", f5B));
                    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);

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

                    string tasaCambio = electronicDocument.Data.TipoCambio.Value;
                    string regimenes = string.Empty;

                    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: ", f5B));
                    par.Add(new Chunk(electronicDocument.Data.FormaPago.Value + "   |   ", f5));

                    par.Add(new Chunk("MÉTODO DE PAGO: ", f5B));
                    par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value, f5));

                    if (electronicDocument.Data.NumeroCuentaPago.Value.ToString().Length > 0)
                    {
                        par.Add(new Chunk("   |   " + "No. CUENTA: ", f5B));
                        par.Add(new Chunk(electronicDocument.Data.NumeroCuentaPago.Value, f5));
                    }

                    if (electronicDocument.Data.Emisor.Regimenes.Count > 0)
                    {
                        for (int u = 0; u < electronicDocument.Data.Emisor.Regimenes.Count; u++)
                            regimenes += electronicDocument.Data.Emisor.Regimenes[u].Regimen.Value.ToString() + ",";

                        par.Add(new Chunk("   |   " + "RÉGIMEN FISCAL: ", f5B));
                        par.Add(new Chunk(regimenes.Substring(0, regimenes.Length - 1).ToString() + "   |   ", f5));
                    }

                    if (electronicDocument.Data.FolioFiscalOriginal.Value.ToString().Length > 0)
                    {
                        par.Add(new Chunk("\nDATOS CFDI ORIGINAL - SERIE: ", f5B));
                        par.Add(new Chunk(electronicDocument.Data.SerieFolioFiscalOriginal.Value, f5));
                        par.Add(new Chunk("   FOLIO: ", f5B));
                        par.Add(new Chunk(electronicDocument.Data.FolioFiscalOriginal.Value, f5));
                        par.Add(new Chunk("   FECHA: ", f5B));
                        par.Add(new Chunk(electronicDocument.Data.FechaFolioFiscalOriginal.Value.ToString(), f5));
                        par.Add(new Chunk("   MONTO: ", f5B));
                        par.Add(new Chunk(electronicDocument.Data.MontoFolioFiscalOriginal.Value.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);

                    if (electronicDocument.Data.LugarExpedicion.Value.Length > 0)
                    {
                        par = new Paragraph();
                        par.SetLeading(7f, 0f);
                        par.Add(new Chunk("LUGAR EXPEDICIÓN: ", f5B));
                        par.Add(new Chunk(electronicDocument.Data.LugarExpedicion.Value, f5));
                        cel = new Cell(par);
                        cel.BorderColor = gris;
                        cel.BorderWidthTop = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthLeft = 0;
                        cel.BorderWidthBottom = 0;
                        cel.Colspan = 3;
                        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", f5B));
                    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", f5B));
                    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", f6B));
                cell.VerticalAlignment = Element.ALIGN_MIDDLE;
                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.BackgroundColor = grisOX;
                cell.BorderWidthTop = 0;
                cell.BorderWidthLeft = 0;
                cell.BorderWidthRight = 0;
                cell.BorderWidthBottom = 0;
                footer.AddCell(cell);

                #endregion

                pageEventHandler.encabezado = encabezado;
                pageEventHandler.encReceptor = tReceptor;
                pageEventHandler.footer = footer;

                document.Open();

                //document.Add(tReceptor);
                document.Add(tableConceptos);
                document.Add(comentarios);
                document.Add(desgloseImpuestos);
                document.Add(adicional);

                #endregion
            }
            catch (Exception ex)
            {
                string exe = ex.Message;
            }
        }
        // 函数描述: 格式化报告的标题
        public static Paragraph InsertTitleContent(string text, bool isHasColor = true)
        {
            var font = BaseFontAndSize("华文中宋", 16, Font.BOLD);
            var font1 = BaseFontAndSize("华文中宋", 16, Font.BOLD,new BaseColor(0,162,234));
            var paragraph = new Paragraph
                {
                FirstLineIndent = 24,
                IndentationLeft = 20,
                IndentationRight = 20,
                SpacingBefore = 1,
                SpacingAfter = 1
            };
            paragraph.SetLeading(1, 2);
            paragraph.Alignment = Element.ALIGN_CENTER;

            if (isHasColor)
            {
                var strList = text.Split('@');
                for (var i = 0; i < strList.Length; i++)
                {
                    var fo = i % 2 == 0 ? font : font1;
                    var ch = new Chunk(strList[i], fo);
                    paragraph.Add(ch);
                }
            }
            else
            {
                var ch = new Chunk(text, font);
                paragraph.Add(ch);
            }

            return paragraph;
        }
 // 函数描述: 格式化报告的标题
 public static Paragraph InsertTopTitleContent(string text)
 {
     var font = BaseFontAndSize("华文中宋", 26, Font.BOLD);
     var paragraph = new Paragraph(text, font)
         {
             Alignment = Element.ALIGN_CENTER,
             SpacingBefore = 5,
             SpacingAfter = 5
         };
     paragraph.SetLeading(1, 1.3f);
     return paragraph;
 }
Пример #23
0
        public static string generarPdf(Hashtable htFacturaxion, HttpContext hc)
        {
            string pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString();
            FileStream fs = new FileStream(pathPdf, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            try
            {
                StringBuilder sbConfigFact = new StringBuilder();
                StringBuilder sbConfigFactParms = new StringBuilder();
                _ci.NumberFormat.CurrencyDecimalDigits = 2;

                DAL dal = new DAL();
                ElectronicDocument electronicDocument = (ElectronicDocument)htFacturaxion["electronicDocument"];
                Data objTimbre = (Data)htFacturaxion["objTimbre"];
                bool timbrar = Convert.ToBoolean(htFacturaxion["timbrar"]);
                //string pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString();

                // Obtenemos el logo y plantilla

                StringBuilder sbLogo = new StringBuilder();

                sbLogo.
                    Append("SELECT S.rutaLogo, P.rutaEncabezado, P.rutaFooter ").
                    Append("FROM sucursales S ").
                    Append("LEFT OUTER JOIN tipoPlantillas P ON S.idTipoPlantilla = P.idTipoPlantilla AND P.ST = 1 ").
                    Append("WHERE idSucursal = @0 AND S.ST = 1");

                DataTable dtLogo = dal.QueryDT("DS_FE", sbLogo.ToString(), "F:I:" + htFacturaxion["idSucursalEmisor"], hc);

                string rutaLogo = dtLogo.Rows[0]["rutaLogo"].ToString();
                string rutaHeader = dtLogo.Rows[0]["rutaEncabezado"].ToString();
                string rutaFooter = dtLogo.Rows[0]["rutaFooter"].ToString();

                //Obtenemos Rol de la empresa
                StringBuilder sbRol = new StringBuilder();

                sbRol.
                    Append("DECLARE @iduser INT; ").
                    Append("SELECT DISTINCT @iduser = UxR.idUser FROM sucursales S ").
                    Append("LEFT OUTER JOIN sucursalesXUsuario SxU ON S.idSucursal = SxU.idSucursal LEFT OUTER JOIN r3TakeCore.dbo.SYS_UserXRol UxR ON UxR.idUser = SxU.idUser ").
                    Append("WHERE idEmpresa = @0 AND UxR.idRol IN(22,15) AND S.ST = 1 AND SxU.ST = 1; ").
                    Append("SELECT UxR.idRol FROM r3TakeCore.dbo.SYS_UserXRol UxR WHERE idUser = @idUser");  //Rol 15 > MIT ; 22 > Facturizate

                int idRol = dal.ExecuteScalar("DS_FE", sbRol.ToString(), "F:S:" + htFacturaxion["idEmisor"], hc);

                sbConfigFactParms.
                    Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idSucursalEmisor"])).
                    Append(";").
                    Append("F:I:").Append(Convert.ToInt32(htFacturaxion["tipoComprobante"])).
                    Append(";").
                    Append("F:S:").Append(electronicDocument.Data.Total.Value).
                    Append(";").
                    Append("F:I:").Append(Convert.ToInt32(htFacturaxion["idMoneda"])).
                    Append(";").
                    Append("F:S:").Append(rutaLogo).
                    Append(";").
                    Append("F:S:").Append(rutaHeader).
                    Append(";").
                    Append("F:S:").Append(rutaFooter).
                    Append(";").
                    Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idEmisor"]));

                if (idRol == 15)
                {
                    if (rutaHeader.Length > 0)
                    {
                        sbConfigFact.
                            Append("SELECT @5 AS rutaTemplateHeader, @6 AS rutaTemplateFooter, @4 AS rutaLogo, objDesc, posX, posY, fontSize, dbo.convertNumToTextFunction( @2, @3) AS cantidadLetra, ").
                            Append("logoPosX, logoPosY, headerPosX, headerPosY, footerPosX, footerPosY, conceptosColWidth, desgloseColWidth ").
                            Append("FROM configuracionFacturas CF ").
                            Append("LEFT OUTER JOIN sucursales S ON S.idSucursal = @0 ").
                            Append("LEFT OUTER JOIN configuracionFactDet CFD ON CF.idConFact = CFD.idConFact ").
                            Append("WHERE CF.ST = 1 AND CF.idEmpresa = -1 AND CF.idTipoComp = @1 AND idCFDProcedencia = 1 AND objDesc NOT LIKE 'nuevoLbl%' ");
                    }
                    else
                    {
                        sbConfigFact.
                            Append("SELECT rutaTemplateHeader, rutaTemplateFooter, @4 AS rutaLogo, objDesc, posX, posY, fontSize, dbo.convertNumToTextFunction( @2, @3) AS cantidadLetra, ").
                            Append("logoPosX, logoPosY, headerPosX, headerPosY, footerPosX, footerPosY, conceptosColWidth, desgloseColWidth ").
                            Append("FROM configuracionFacturas CF ").
                            Append("LEFT OUTER JOIN sucursales S ON S.idSucursal = @0 ").
                            Append("LEFT OUTER JOIN configuracionFactDet CFD ON CF.idConFact = CFD.idConFact ").
                            Append("WHERE CF.ST = 1 AND CF.idEmpresa = -1 AND CF.idTipoComp = @1 AND idCFDProcedencia = 1 AND objDesc NOT LIKE 'nuevoLbl%' ");
                    }
                }
                else
                {
                    sbConfigFact.
                        Append("DECLARE @idEmpresa AS INT;").
                        Append("IF EXISTS (SELECT * FROM configuracionFacturas WHERE idEmpresa = @7) ").
                        Append("SET @idEmpresa = @7; ").
                        Append("ELSE ").
                        Append("SET @idEmpresa = 0; ").
                        Append("SELECT rutaTemplateHeader, rutaTemplateFooter, S.rutaLogo, objDesc, posX, posY, fontSize, dbo.convertNumToTextFunction( @2, @3) AS cantidadLetra, ").
                        Append("logoPosX, logoPosY, headerPosX, headerPosY, footerPosX, footerPosY, conceptosColWidth, desgloseColWidth, S.nombreSucursal ").
                        Append("FROM configuracionFacturas CF ").
                        Append("LEFT OUTER JOIN sucursales S ON S.idSucursal = @0 ").
                        Append("LEFT OUTER JOIN configuracionFactDet CFD ON CF.idConFact = CFD.idConFact ").
                        Append("WHERE CF.ST = 1 AND CF.idEmpresa = @idEmpresa AND CF.idTipoComp = @1 AND idCFDProcedencia = 1 AND objDesc NOT LIKE 'nuevoLbl%' ");
                }

                DataTable dtConfigFact = dal.QueryDT("DS_FE", sbConfigFact.ToString(), sbConfigFactParms.ToString(), hc);

                // Creamos el Objeto Documento
                Document document = new Document(PageSize.LETTER, 25, 25, 25, 25);
                document.AddAuthor("Facturaxion");
                document.AddCreator("r3Take");
                document.AddCreationDate();
                //FileStream fs = new FileStream(pathPdf, FileMode.Create);
                //FileStream fs = new FileStream(pathPdf, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                PdfWriter writer = PdfWriter.GetInstance(document, fs);
                writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);

                Chunk cSaltoLinea = new Chunk("\n");
                Chunk cLineaSpace = new Chunk(cSaltoLinea + "________________________________________________________________________________________________________________________________________________________________________", new Font(Font.HELVETICA, 6, Font.BOLD));
                Chunk cLineaDiv = new Chunk(cSaltoLinea + "________________________________________________________________________________________________________________________________________________________________________" + cSaltoLinea, new Font(Font.HELVETICA, 6, Font.BOLD));
                Chunk cDataSpacer = new Chunk("      |      ", new Font(Font.HELVETICA, 6, Font.BOLD));

                BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
                document.Open();
                PdfContentByte cb = writer.DirectContent;
                cb.BeginText();

                // Almacenamos en orden los objetos del Electronic Document para posteriormente añadidos al documento

                #region "Armamos las etiquetas que tienen posiciones absolutas para ser insertadas en el documento"

                Hashtable htDatosCfdi = new Hashtable();

                // Armamos las direcciones

                #region "Dirección Emisor"

                StringBuilder sbDirEmisor1 = new StringBuilder();
                StringBuilder sbDirEmisor2 = new StringBuilder();
                StringBuilder sbDirEmisor3 = new StringBuilder();

                if (electronicDocument.Data.Emisor.Domicilio.Calle.Value.Length > 0)
                {
                    sbDirEmisor1.Append("Calle ").Append(electronicDocument.Data.Emisor.Domicilio.Calle.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value.Length > 0)
                {
                    sbDirEmisor1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value.Length > 0)
                {
                    sbDirEmisor1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value);
                }

                if (electronicDocument.Data.Emisor.Domicilio.Colonia.Value.Length > 0)
                {
                    sbDirEmisor2.Append("Col. ").Append(electronicDocument.Data.Emisor.Domicilio.Colonia.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value.Length > 0)
                {
                    sbDirEmisor2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.Localidad.Value.Length > 0)
                {
                    sbDirEmisor2.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Localidad.Value);
                }

                if (electronicDocument.Data.Emisor.Domicilio.Municipio.Value.Length > 0)
                {
                    sbDirEmisor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.Domicilio.Municipio.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.Estado.Value.Length > 0)
                {
                    sbDirEmisor3.Append(", Estado ").Append(electronicDocument.Data.Emisor.Domicilio.Estado.Value).Append(" ");
                }

                sbDirEmisor3.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Pais.Value);

                #endregion

                #region "Dirección Sucursal Expedido En"

                StringBuilder sbDirExpedido1 = new StringBuilder();
                StringBuilder sbDirExpedido2 = new StringBuilder();
                StringBuilder sbDirExpedido3 = new StringBuilder();

                if (electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value.Length > 0)
                {
                    sbDirExpedido1.Append("Calle ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value.Length > 0)
                {
                    sbDirExpedido1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value.Length > 0)
                {
                    sbDirExpedido1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value);
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value.Length > 0)
                {
                    sbDirExpedido2.Append("Col. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value.Length > 0)
                {
                    sbDirExpedido2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value.Length > 0)
                {
                    sbDirExpedido2.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value);
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value.Length > 0)
                {
                    sbDirExpedido3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value.Length > 0)
                {
                    sbDirExpedido3.Append(", Estado ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value).Append(" ");
                }

                sbDirExpedido3.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Pais.Value);

                #endregion

                #region "Dirección Receptor"

                StringBuilder sbDirReceptor1 = new StringBuilder();
                StringBuilder sbDirReceptor2 = new StringBuilder();
                StringBuilder sbDirReceptor3 = new StringBuilder();

                if (electronicDocument.Data.Receptor.Domicilio.Calle.Value.Length > 0)
                {
                    sbDirReceptor1.Append("Calle ").Append(electronicDocument.Data.Receptor.Domicilio.Calle.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value.Length > 0)
                {
                    sbDirReceptor1.Append(", No. Ext ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value.Length > 0)
                {
                    sbDirReceptor1.Append(", No. Int ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value);
                }

                if (electronicDocument.Data.Receptor.Domicilio.Colonia.Value.Length > 0)
                {
                    sbDirReceptor2.Append("Col. ").Append(electronicDocument.Data.Receptor.Domicilio.Colonia.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value.Length > 0)
                {
                    sbDirReceptor2.Append(", C.P. ").Append(electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.Localidad.Value.Length > 0)
                {
                    sbDirReceptor2.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Localidad.Value);
                }

                if (electronicDocument.Data.Receptor.Domicilio.Municipio.Value.Length > 0)
                {
                    sbDirReceptor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Receptor.Domicilio.Municipio.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.Estado.Value.Length > 0)
                {
                    sbDirReceptor3.Append(", Estado ").Append(electronicDocument.Data.Receptor.Domicilio.Estado.Value).Append(" ");
                }

                sbDirReceptor3.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Pais.Value);

                #endregion

                htDatosCfdi.Add("rfcEmisor", electronicDocument.Data.Emisor.Rfc.Value);
                htDatosCfdi.Add("rfcEmpresa", electronicDocument.Data.Emisor.Rfc.Value);

                htDatosCfdi.Add("nombreEmisor", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value);
                htDatosCfdi.Add("empresa", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value);

                htDatosCfdi.Add("rfcReceptor", electronicDocument.Data.Receptor.Rfc.Value);
                htDatosCfdi.Add("rfcCliente", electronicDocument.Data.Receptor.Rfc.Value);

                htDatosCfdi.Add("nombreReceptor", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value);
                htDatosCfdi.Add("cliente", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value);

                htDatosCfdi.Add("sucursal", "Sucursal " + dtConfigFact.Rows[0]["nombreSucursal"]);

                htDatosCfdi.Add("serie", electronicDocument.Data.Serie.Value);
                htDatosCfdi.Add("folio", electronicDocument.Data.Folio.Value);

                htDatosCfdi.Add("fechaCfdi", electronicDocument.Data.Fecha.Value);
                htDatosCfdi.Add("fechaFactura", electronicDocument.Data.Fecha.Value);

                htDatosCfdi.Add("UUID", objTimbre.Uuid.Value);
                htDatosCfdi.Add("folioFiscal", objTimbre.Uuid.Value);

                htDatosCfdi.Add("direccionEmisor1", sbDirEmisor1.ToString());
                htDatosCfdi.Add("direccionEmpresa1", sbDirEmisor1.ToString());

                htDatosCfdi.Add("direccionEmisor2", sbDirEmisor2.ToString());
                htDatosCfdi.Add("direccionEmpresa2", sbDirEmisor2.ToString());

                htDatosCfdi.Add("direccionEmisor3", sbDirEmisor3.ToString());
                htDatosCfdi.Add("direccionEmpresa3", sbDirEmisor3.ToString());

                htDatosCfdi.Add("direccionExpedido1", sbDirExpedido1.ToString());
                htDatosCfdi.Add("direccionSucursal1", sbDirExpedido1.ToString());

                htDatosCfdi.Add("direccionExpedido2", sbDirExpedido2.ToString());
                htDatosCfdi.Add("direccionSucursal2", sbDirExpedido2.ToString());

                htDatosCfdi.Add("direccionExpedido3", sbDirExpedido3.ToString());
                htDatosCfdi.Add("direccionSucursal3", sbDirExpedido3.ToString());

                htDatosCfdi.Add("direccionReceptor1", sbDirReceptor1.ToString());
                htDatosCfdi.Add("direccionCliente1", sbDirReceptor1.ToString());

                htDatosCfdi.Add("direccionReceptor2", sbDirReceptor2.ToString());
                htDatosCfdi.Add("direccionCliente2", sbDirReceptor2.ToString());

                htDatosCfdi.Add("direccionReceptor3", sbDirReceptor3.ToString());
                htDatosCfdi.Add("direccionCliente3", sbDirReceptor3.ToString());

                // Leemos los objetos que se situaran en posiciones absolutas en el documento
                foreach (DataRow row in dtConfigFact.Rows)
                {
                    cb.SetFontAndSize(bf, Convert.ToInt32(row["fontSize"]));
                    cb.SetTextMatrix(Convert.ToSingle(row["posX"]), Convert.ToSingle(row["posY"]));
                    cb.ShowText(htDatosCfdi[row["objDesc"].ToString()].ToString());
                }
                /////////////////////////////////////////////////////////////
                DataTable dtGetOptional = new DataTable();

                dtGetOptional = dal.QueryDT("DS_FE", "SELECT idCFDI,campo1,campo2,campo3,campo4,campo5 FROM dbo.opcionalEncabezado WHERE idCFDI = @0", "F:I:" + htFacturaxion["idCfdi"], hc);

                if (dtGetOptional.Rows.Count > 0)
                {
                    cb.SetFontAndSize(bf, 7);
                    cb.SetTextMatrix(40, 606);
                    cb.ShowText(dtGetOptional.Rows[0]["campo1"].ToString());

                    cb.SetFontAndSize(bf, 7);
                    cb.SetTextMatrix(40, 597);
                    cb.ShowText(dtGetOptional.Rows[0]["campo2"].ToString());

                    cb.SetFontAndSize(bf, 7);
                    cb.SetTextMatrix(345, 615);
                    cb.ShowText(dtGetOptional.Rows[0]["campo3"].ToString());

                    cb.SetFontAndSize(bf, 7);
                    cb.SetTextMatrix(345, 606);
                    cb.ShowText(dtGetOptional.Rows[0]["campo4"].ToString());

                    cb.SetFontAndSize(bf, 7);
                    cb.SetTextMatrix(40, 597);
                    cb.ShowText(dtGetOptional.Rows[0]["campo5"].ToString());
                }
                ////////////////////////////////////////////////////////////////////

                #endregion

                cb.EndText();

                #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

                #region "Header"

                //Agregando Imagen de Encabezado de Página
                Image imgHeader = Image.GetInstance(dtConfigFact.Rows[0]["rutaTemplateHeader"].ToString());
                imgHeader.ScalePercent(47f);

                double posXH = Convert.ToDouble(dtConfigFact.Rows[0]["headerPosX"].ToString());
                double posYH = Convert.ToDouble(dtConfigFact.Rows[0]["headerPosY"].ToString());

                double PXH = posXH;
                double PYH = posYH;
                imgHeader.SetAbsolutePosition(Convert.ToSingle(PXH), Convert.ToSingle(PYH));
                document.Add(imgHeader);

                #endregion

                #region "Logotipo"

                //Agregando Imagen de Logotipo
                Image imgLogo = Image.GetInstance(dtConfigFact.Rows[0]["rutaLogo"].ToString());
                float imgLogoWidth = 100;
                float imgLogoHeight = 50;

                imgLogo.ScaleAbsolute(imgLogoWidth, imgLogoHeight);
                imgLogo.SetAbsolutePosition(Convert.ToSingle(dtConfigFact.Rows[0]["logoPosX"]), Convert.ToSingle(dtConfigFact.Rows[0]["logoPosY"]));
                document.Add(imgLogo);

                #endregion

                #region "Espaciador entre Header y Conceptos"

                Paragraph pRelleno = new Paragraph();
                Chunk cRelleno = new Chunk();

                for (int lineas = 0; lineas < 12; lineas++)
                {
                    cRelleno.Append("\n");
                }

                pRelleno.Add(cRelleno);
                document.Add(pRelleno);

                #endregion

                #region "Añadimos Detalle de Conceptos"

                // Creamos la tabla para insertar los conceptos de detalle de la factura
                PdfPTable tableConceptos = new PdfPTable(5);

                int[] colWithsConceptos = new int[5];
                String[] arrColWidthConceptos = dtConfigFact.Rows[0]["conceptosColWidth"].ToString().Split(new Char[] { ',' });

                for (int i = 0; i < arrColWidthConceptos.Length; i++)
                {
                    colWithsConceptos.SetValue(Convert.ToInt32(arrColWidthConceptos[i]), i);
                }

                tableConceptos.SetWidths(colWithsConceptos);
                tableConceptos.WidthPercentage = 93F;

                int numConceptos = electronicDocument.Data.Conceptos.Count;
                PdfPCell cellConceptos = new PdfPCell();
                PdfPCell cellMontos = new PdfPCell();

                for (int i = 0; i < numConceptos; i++)
                {
                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT;
                    tableConceptos.AddCell(cellConceptos);

                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT;
                    tableConceptos.AddCell(cellConceptos);

                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    tableConceptos.AddCell(cellConceptos);

                    cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellMontos.Border = 0;
                    cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT;
                    tableConceptos.AddCell(cellMontos);

                    cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), new Font(Font.HELVETICA, 8, Font.NORMAL)));
                    cellMontos.Border = 0;
                    cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT;
                    tableConceptos.AddCell(cellMontos);
                }

                document.Add(tableConceptos);

                #endregion

                #region "Espaciador entre Conceptos y Desglose"

                Paragraph pRelleno2 = new Paragraph();
                Chunk cRelleno2 = new Chunk("\n");
                pRelleno2.Add(cRelleno2);
                document.Add(pRelleno2);

                #endregion

                #region "Desglose"

                PdfPTable tableDesglose = new PdfPTable(3);
                int[] colWithsDesglose = new int[3];
                String[] arrColWidthDesglose = dtConfigFact.Rows[0]["desgloseColWidth"].ToString().Split(new Char[] { ',' });

                for (int i = 0; i < arrColWidthDesglose.Length; i++)
                {
                    colWithsDesglose.SetValue(Convert.ToInt32(arrColWidthDesglose[i]), i);
                }

                tableDesglose.SetWidths(colWithsDesglose);
                tableDesglose.WidthPercentage = 93F;

                PdfPCell cellDesgloseRelleno = new PdfPCell();
                PdfPCell cellDesgloseDescripcion = new PdfPCell();
                PdfPCell cellDesgloseMonto = new PdfPCell();

                //Armamnos el Hashtable que conntiene el desglose del Cfdi

                Hashtable htDesglose = new Hashtable();
                ArrayList alDesgloseOrden = new ArrayList();

                alDesgloseOrden.Add("Subtotal");

                if (electronicDocument.Data.Descuento.Value != 0)
                {
                    alDesgloseOrden.Add("Descuento");
                }

                if (electronicDocument.Data.Impuestos.TotalTraslados.Value != 0)
                {
                    alDesgloseOrden.Add("Impuestos Trasladados");
                }

                if (electronicDocument.Data.Impuestos.TotalRetenciones.Value != 0)
                {
                    alDesgloseOrden.Add("Impuestos Retenidos");
                }

                alDesgloseOrden.Add("Total");

                htDesglose.Add("Subtotal", electronicDocument.Data.SubTotal.Value.ToString("C", _ci));
                htDesglose.Add("Descuento", electronicDocument.Data.Descuento.Value.ToString("C", _ci));
                htDesglose.Add("Impuestos Trasladados", electronicDocument.Data.Impuestos.TotalTraslados.Value.ToString("C", _ci));
                htDesglose.Add("Impuestos Retenidos", electronicDocument.Data.Impuestos.TotalRetenciones.Value.ToString("C", _ci));
                htDesglose.Add("Total", electronicDocument.Data.Total.Value.ToString("C", _ci));

                foreach (string desglose in alDesgloseOrden)
                {
                    cellDesgloseRelleno = new PdfPCell(new Phrase(string.Empty, new Font(Font.HELVETICA, 7, Font.BOLD)));
                    cellDesgloseRelleno.Border = 0;

                    cellDesgloseDescripcion = new PdfPCell(new Phrase(desglose, new Font(Font.HELVETICA, 7, Font.BOLD)));
                    cellDesgloseDescripcion.Border = 0;

                    cellDesgloseMonto = new PdfPCell(new Phrase(htDesglose[desglose].ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellDesgloseMonto.Border = 0;
                    cellDesgloseMonto.HorizontalAlignment = PdfCell.ALIGN_RIGHT;

                    tableDesglose.AddCell(cellDesgloseRelleno);
                    tableDesglose.AddCell(cellDesgloseDescripcion);
                    tableDesglose.AddCell(cellDesgloseMonto);
                }

                document.Add(tableDesglose);

                #endregion

                #region "Desglose Detalle"

                PdfPTable tableDesgloseDetalle = new PdfPTable(3);
                int[] colWithsDesgloseDetalle = new int[3];
                string colDesgloseDetalle = "8,8,84";
                String[] arrColWidthDesgloseDetalle = colDesgloseDetalle.Split(new Char[] { ',' });

                for (int i = 0; i < arrColWidthDesgloseDetalle.Length; i++)
                {
                    colWithsDesgloseDetalle.SetValue(Convert.ToInt32(arrColWidthDesgloseDetalle[i]), i);
                }

                tableDesgloseDetalle.SetWidths(colWithsDesgloseDetalle);
                tableDesgloseDetalle.WidthPercentage = 100F;

                #endregion

                #region "Creación e Inserción de Chunks en Paragraph"

                Paragraph pFooter = new Paragraph();
                pFooter.KeepTogether = true;
                pFooter.Alignment = PdfCell.ALIGN_LEFT;
                pFooter.SetLeading(1.6f, 1.6f);

                //AZUL Font fontLbl = new Font(Font.HELVETICA, 6, Font.BOLD, new Color(43, 145, 175));
                Font fontLbl = new Font(Font.HELVETICA, 6, Font.BOLD, new Color(25, 71, 6));
                Font fontVal = new Font(Font.HELVETICA, 6, Font.NORMAL);

                string cantidadLetra = dtConfigFact.Rows[0]["cantidadLetra"].ToString();
                Chunk cCantidadLetraVal = new Chunk(cantidadLetra, new Font(Font.HELVETICA, 7, Font.BOLD));

                Chunk cTipoComprobanteLbl = new Chunk("Tipo de Comprobante: ", fontLbl);
                Chunk cTipoComprobanteVal = new Chunk(electronicDocument.Data.TipoComprobante.Value, fontVal);

                Chunk cFormaPagoLbl = new Chunk("Forma de Pago: ", fontLbl);
                Chunk cFormaPagoVal = new Chunk(electronicDocument.Data.FormaPago.Value, fontVal);

                Chunk cMetodoPagoLbl = new Chunk("Método de Pago: ", fontLbl);
                Chunk cMetodoPagoVal = new Chunk(electronicDocument.Data.MetodoPago.Value, fontVal);

                Chunk cMonedaLbl = new Chunk("Moneda: ", fontLbl);
                Chunk cMonedaVal = new Chunk(electronicDocument.Data.Moneda.Value, fontVal);

                if (electronicDocument.Data.TipoCambio.Value.Length == 0)
                    electronicDocument.Data.TipoCambio.Value = "1";

                Chunk cTasaCambioLbl = new Chunk("Tasa de Cambio: ", fontLbl);
                Chunk cTasaCambioVal = new Chunk(Convert.ToDouble(electronicDocument.Data.TipoCambio.Value).ToString("C", _ci), fontVal);

                Chunk cCertificadoLbl = new Chunk("Certificado del Emisor: ", fontLbl);
                Chunk cCertificadoVal = new Chunk(electronicDocument.Data.NumeroCertificado.Value, fontVal);

                Chunk cCadenaOriginalLbl = new Chunk("Cadena Original", fontLbl);
                Chunk cCadenaOriginalVal = new Chunk(electronicDocument.FingerPrint, fontVal);

                Chunk cCadenaOriginalPACLbl = new Chunk("Cadena Original del Complemento de Certificación Digital del SAT", fontLbl);
                Chunk cCadenaOriginalPACVal = new Chunk(electronicDocument.FingerPrintPac, fontVal);

                Chunk cSelloDigitalLbl = new Chunk("Sello Digital del Emisor", fontLbl);
                Chunk cSelloDigitalVal = new Chunk(electronicDocument.Data.Sello.Value, fontVal);

                string regimenes = "";

                for (int u = 0; u < electronicDocument.Data.Emisor.Regimenes.Count; u++)
                    regimenes += electronicDocument.Data.Emisor.Regimenes[u].Regimen.Value.ToString() + ",";

                Chunk cNoTarjetaLbl = new Chunk("No. Tarjeta: ", fontLbl);
                Chunk cNoTarjetaVal = new Chunk(electronicDocument.Data.NumeroCuentaPago.Value, fontVal);

                Chunk cExpedidoEnLbl = new Chunk("Expedido En: ", fontLbl);
                Chunk cExpedidoEnVal = new Chunk(electronicDocument.Data.LugarExpedicion.Value, fontVal);

                pFooter.Add(cCantidadLetraVal);
                pFooter.Add(cSaltoLinea);

                pFooter.Add(cTipoComprobanteLbl);
                pFooter.Add(cTipoComprobanteVal);
                pFooter.Add(cDataSpacer);
                pFooter.Add(cMonedaLbl);
                pFooter.Add(cMonedaVal);
                pFooter.Add(cDataSpacer);
                pFooter.Add(cTasaCambioLbl);
                pFooter.Add(cTasaCambioVal);
                pFooter.Add(cDataSpacer);

                if (htFacturaxion["noOrdenCompra"].ToString().Length > 0)
                {
                    Chunk cOrdenCompraLbl = new Chunk("Orden de Compra: ", fontLbl);
                    Chunk cOrdenCompraVal = new Chunk(htFacturaxion["noOrdenCompra"].ToString(), fontVal);
                    pFooter.Add(cOrdenCompraLbl);
                    pFooter.Add(cOrdenCompraVal);
                    pFooter.Add(cDataSpacer);
                }

                pFooter.Add(cFormaPagoLbl);
                pFooter.Add(cFormaPagoVal);
                pFooter.Add(cDataSpacer);
                pFooter.Add(cMetodoPagoLbl);
                pFooter.Add(cMetodoPagoVal);

                if (electronicDocument.Data.NumeroCuentaPago.Value.ToString().Length > 0)
                {
                    pFooter.Add(cDataSpacer);
                    pFooter.Add(cNoTarjetaLbl);
                    pFooter.Add(cNoTarjetaVal);
                }

                if (electronicDocument.Data.Emisor.Regimenes.Count > 0)
                {
                    Chunk cRegimenLbl = new Chunk("Régimen Fiscal: ", fontLbl);
                    Chunk cRegimenVal = new Chunk(regimenes.Substring(0, regimenes.Length - 1).ToString(), fontVal);

                    pFooter.Add(cDataSpacer);
                    pFooter.Add(cRegimenLbl);
                    pFooter.Add(cRegimenVal);
                }

                if (electronicDocument.Data.FolioFiscalOriginal.Value.ToString().Length > 0)
                {
                    Chunk cFolioOriginal1Lbl = new Chunk("Datos CFDI Original - Serie: ", fontLbl);
                    Chunk cFolioOriginal1Val = new Chunk(electronicDocument.Data.SerieFolioFiscalOriginal.Value + "   ", fontVal);

                    Chunk cFolioOriginal2Lbl = new Chunk("Folio: ", fontLbl);
                    Chunk cFolioOriginal2Val = new Chunk(electronicDocument.Data.FolioFiscalOriginal.Value + "   ", fontVal);

                    Chunk cFolioOriginal3Lbl = new Chunk("Fecha: ", fontLbl);
                    Chunk cFolioOriginal3Val = new Chunk(electronicDocument.Data.FechaFolioFiscalOriginal.Value.ToString() + "   ", fontVal);

                    Chunk cFolioOriginal4Lbl = new Chunk("Monto: ", fontLbl);
                    Chunk cFolioOriginal4Val = new Chunk(electronicDocument.Data.MontoFolioFiscalOriginal.Value.ToString(), fontVal);

                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cFolioOriginal1Lbl);
                    pFooter.Add(cFolioOriginal1Val);
                    pFooter.Add(cFolioOriginal2Lbl);
                    pFooter.Add(cFolioOriginal2Val);
                    pFooter.Add(cFolioOriginal3Lbl);
                    pFooter.Add(cFolioOriginal3Val);
                    pFooter.Add(cFolioOriginal4Lbl);
                    pFooter.Add(cFolioOriginal4Val);
                }

                pFooter.Add(cLineaDiv);

                if (htFacturaxion["observaciones"].ToString().Length > 0)
                {
                    Chunk cObsLbl = new Chunk("Observaciones ", fontLbl);
                    Chunk cObsVal = new Chunk(htFacturaxion["observaciones"].ToString(), fontVal);
                    pFooter.Add(cObsLbl);
                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cObsVal);
                    pFooter.Add(cLineaDiv);
                }

                if (electronicDocument.Data.LugarExpedicion.Value.Length > 0)
                {
                    pFooter.Add(cExpedidoEnLbl);
                    pFooter.Add(cExpedidoEnVal);
                    pFooter.Add(cLineaDiv);
                }

                pFooter.Add(cCertificadoLbl);
                pFooter.Add(cCertificadoVal);
                pFooter.Add(cLineaDiv);

                if (timbrar)
                {
                    pFooter.Add(cCadenaOriginalPACLbl);
                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cCadenaOriginalPACVal);
                }
                else
                {
                    pFooter.Add(cCadenaOriginalLbl);
                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cCadenaOriginalVal);
                }

                pFooter.Add(cLineaDiv);
                pFooter.Add(cSelloDigitalLbl);
                pFooter.Add(cSaltoLinea);
                pFooter.Add(cSelloDigitalVal);
                pFooter.Add(cLineaSpace);

                document.Add(pFooter);

                #endregion

                #region "Añadimos Código Bidimensional"

                if (timbrar)
                {
                    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;
                    document.Add(imageQRCode);
                    pFooter.Clear();

                    #region "Creación e Inserción de Chunks de Timbrado en Paragraph"

                    Chunk cFolioFiscalLbl = new Chunk("Folio Fiscal: ", fontLbl);
                    Chunk cFolioFiscalVal = new Chunk(objTimbre.Uuid.Value, fontVal);

                    Chunk cFechaTimbradoLbl = new Chunk("Fecha y Hora de Certificación: ", fontLbl);
                    DateTime fechaTimbrado = Convert.ToDateTime(objTimbre.FechaTimbrado.Value);
                    string formatoFechaTimbrado = fechaTimbrado.ToString("yyyy-MM-dd") + "T" + fechaTimbrado.ToString("HH:mm:ss");
                    Chunk cFechaTimbradoVal = new Chunk(formatoFechaTimbrado, fontVal);

                    Chunk cCertificadoSatLbl = new Chunk("Certificado SAT: ", fontLbl);
                    Chunk cCertificadoSatVal = new Chunk(objTimbre.NumeroCertificadoSat.Value, fontVal);

                    Chunk cSelloDigitalSatLbl = new Chunk("Sello Digital SAT", fontLbl);
                    Chunk cSelloDigitalSatVal = new Chunk(objTimbre.SelloSat.Value, fontVal);

                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cFolioFiscalLbl);
                    pFooter.Add(cFolioFiscalVal);
                    pFooter.Add(cDataSpacer);
                    pFooter.Add(cCertificadoSatLbl);
                    pFooter.Add(cCertificadoSatVal);
                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cFechaTimbradoLbl);
                    pFooter.Add(cFechaTimbradoVal);
                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cSelloDigitalSatLbl);
                    pFooter.Add(cSaltoLinea);
                    pFooter.Add(cSelloDigitalSatVal);

                    #endregion

                    document.Add(pFooter);
                }

                #endregion

                #region "Añadimos leyenda de CFDI"

                Paragraph pLeyendaCfdi = new Paragraph();
                string leyenda;

                if (timbrar)
                {
                    leyenda = "Este documento es una representación impresa de un CFDI";
                }
                else
                {
                    leyenda = "Este documento es una representación impresa de un Comprobante Fiscal Digital";
                }

                Chunk cLeyendaCfdi = new Chunk(leyenda, new Font(Font.HELVETICA, 8, Font.BOLD | Font.ITALIC));
                pLeyendaCfdi.Add(cLeyendaCfdi);
                pLeyendaCfdi.SetLeading(1.6f, 1.6f);
                document.Add(pLeyendaCfdi);

                #endregion

                #region "Footer"

                //Agregando Imagen de Pie de Página
                Image imgFooter = Image.GetInstance(dtConfigFact.Rows[0]["rutaTemplateFooter"].ToString());
                float imgFooterWidth = document.PageSize.Width - 70;
                float imgFooterHeight = imgFooter.Height / (imgFooter.Width / imgFooterWidth);

                imgFooter.ScaleAbsolute(imgFooterWidth, imgFooterHeight);
                imgFooter.SetAbsolutePosition(Convert.ToSingle(dtConfigFact.Rows[0]["footerPosX"]), Convert.ToSingle(dtConfigFact.Rows[0]["footerPosY"]));
                document.Add(imgFooter);

                // Si el rol del usuario es gratuito añadimos el footer las imagenes de facturaxion y r3take

                if (idRol == 16)
                {
                    Image facturaxionImgFooter = Image.GetInstance(ConfigurationManager.AppSettings["logoFacturaxion"]);
                    Image r3TakeImgFooter = Image.GetInstance(ConfigurationManager.AppSettings["logor3Take"]);

                    facturaxionImgFooter.ScaleAbsolute(70, 25);
                    r3TakeImgFooter.ScaleAbsolute(70, 25);

                    facturaxionImgFooter.SetAbsolutePosition(25, 10);
                    r3TakeImgFooter.SetAbsolutePosition(600, 10);

                    document.Add(facturaxionImgFooter);
                    document.Add(r3TakeImgFooter);
                }

                #endregion

                document.Close();
                writer.Close();
                fs.Close();

                string filePdfExt = pathPdf.Replace(_rutaDocs, _rutaDocsExt);
                string urlPathFilePdf = filePdfExt.Replace(@"\", "/");

                //Subimos Archivo al Azure
                string res = App_Code.com.Facturaxion.facturaEspecial.wAzure.azureUpDownLoad(1, pathPdf);

                return "1#" + urlPathFilePdf;
            }
            catch (Exception ex)
            {
                fs.Flush();
                fs.Close();
                File.Delete(pathPdf);

                return "0#" + ex.Message;
            }
        }
Пример #24
0
        private void generate_Click(object sender, EventArgs e)
        {
            int cena = Int32.Parse(cena_txt.Text);
            int zadatek = Int32.Parse(zadatek_txt.Text);
            int pozostala = cena - zadatek;

            var desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            var fullFileName = Path.Combine(desktopFolder, "umowa.pdf");

            FileStream fs = new FileStream(fullFileName, FileMode.Create, FileAccess.Write, FileShare.None);
            iTextSharp.text.Font timesBoldItalic = FontFactory.GetFont(FontFactory.TIMES_BOLDITALIC, BaseFont.CP1250, 11);
            iTextSharp.text.Font timesBold = FontFactory.GetFont(FontFactory.TIMES_BOLD, BaseFont.CP1250, 11);
            iTextSharp.text.Font times = FontFactory.GetFont(FontFactory.TIMES, BaseFont.CP1250, 11);
            Document doc = new Document(PageSize.A4, 40, 40, 20, 40);
            PdfWriter writer = PdfWriter.GetInstance(doc, fs);
            iTextSharp.text.Image flisy_1 = iTextSharp.text.Image.GetInstance("flisy_01.png");
            doc.Open();
            doc.SetMargins(40f, 40f, 40f, 40f);
            doc.AddTitle("Umowa Flisy");
            doc.AddAuthor("Flisy");
            // first image
            flisy_1.ScaleToFit(600f, 70f);
            flisy_1.Alignment = Element.ALIGN_CENTER;
            doc.Add(flisy_1);

            Paragraph title = new Paragraph("UMOWA O DZIEŁO", timesBoldItalic);
            title.Alignment = Element.ALIGN_CENTER;
            doc.Add(title);
            // &0
            var zero_ph = new Phrase();
            zero_ph.Add(new Chunk("Zawarta w dniu ", times));
            zero_ph.Add(new Chunk(data_txt.Text, timesBold));
            zero_ph.Add(new Chunk(" pomiędzy zespołem muzycznym FLISY reprezentowanym przez Arkadiusza Olka zamieszkałym w Gorzowie Wlkp.ul.Wiedeńska 1i / 15 zwanym w treści umowy wykonawcą, a organizatorem imprezy czyli ", times));
            zero_ph.Add(new Chunk(zlece_txt.Text, timesBold));
            zero_ph.Add(new Chunk(" zamieszkałym ", times));
            zero_ph.Add(new Chunk(adr_zlece_txt.Text, timesBold));
            zero_ph.Add(new Chunk(" zwanym w treści umowy zamawiającym.", times));

            Paragraph zero = new Paragraph(zero_ph);
            zero.Alignment = Element.ALIGN_JUSTIFIED;
            zero.SetLeading(0.0f, 1.5f);
            doc.Add(zero);

            // &1
            Paragraph one_amp = new Paragraph("&1", timesBold);
            one_amp.Alignment = Element.ALIGN_CENTER;
            one_amp.SetLeading(0.0f, 1.5f);
            doc.Add(one_amp);

            var one_ph = new Phrase();
            one_ph.Add(new Chunk("Zamawiający zamawia wykonanie a wykonawca zobowiązuje się wykonać dzieło polegające na: \na) oprawie muzyczno - wokalnej uroczystości weselnej \nb) oprawie muzyczno-wokalnej uroczystości weselnej wraz z poprawinami \nc) oprawie muzyczno-wokalnej imprezy", times));

            Paragraph one = new Paragraph(one_ph);
            one.Alignment = Element.ALIGN_JUSTIFIED;
            one.SetLeading(0.0f, 1.5f);
            doc.Add(one);

            // &2
            Paragraph two_amp = new Paragraph("&2", timesBold);
            two_amp.Alignment = Element.ALIGN_CENTER;
            two_amp.SetLeading(0.0f, 1.5f);
            doc.Add(two_amp);

            var two_ph = new Phrase();
            two_ph.Add(new Chunk("W terminie dnia ", times));
            two_ph.Add(new Chunk(termin_txt.Text, timesBold));
            two_ph.Add(new Chunk(" od godz. 16:00 do godz. 4:00 w miejscu ", times));
            two_ph.Add(new Chunk(miejsce_txt.Text, timesBold));
            two_ph.Add(new Chunk(".", times));

            Paragraph two = new Paragraph(two_ph);
            two.Alignment = Element.ALIGN_JUSTIFIED;
            two.SetLeading(0.0f, 1.5f);
            doc.Add(two);

            // &3
            Paragraph three_amp = new Paragraph("&3", timesBold);
            three_amp.Alignment = Element.ALIGN_CENTER;
            three_amp.SetLeading(0.0f, 1.5f);
            doc.Add(three_amp);

            var three_ph = new Phrase();
            three_ph.Add(new Chunk("Za wykonanie dzieła zamawiający wypłaci wykonawcy wynagrodzenie w wysokości ", times));
            three_ph.Add(new Chunk(cena_txt.Text + ",00", timesBold));
            three_ph.Add(new Chunk(" słownie ", times));
            three_ph.Add(new Chunk(String.Format("{0} {1}", Formatowanie.LiczbaSlownie(cena), Formatowanie.WalutaSlownie(cena, "PLN")), timesBold));
            three_ph.Add(new Chunk(".", times));

            Paragraph three = new Paragraph(three_ph);
            three.Alignment = Element.ALIGN_JUSTIFIED;
            three.SetLeading(0.0f, 1.5f);
            doc.Add(three);

            // &4
            Paragraph four_amp = new Paragraph("&4", timesBold);
            four_amp.Alignment = Element.ALIGN_CENTER;
            four_amp.SetLeading(0.0f, 1.5f);
            doc.Add(four_amp);

            var four_ph = new Phrase();
            four_ph.Add(new Chunk("Zadatek w kwocie ", times));
            four_ph.Add(new Chunk(zadatek_txt.Text + ",00", timesBold));
            four_ph.Add(new Chunk(" słownie ", times));
            four_ph.Add(new Chunk(String.Format("{0} {1}", Formatowanie.LiczbaSlownie(zadatek), Formatowanie.WalutaSlownie(zadatek, "PLN")), timesBold));
            four_ph.Add(new Chunk(" pobrano w dniu sporządzenia umowy. Do uregulowania pozostaje kwota ", times));
            four_ph.Add(new Chunk(pozostala.ToString() + ",00", timesBold));
            four_ph.Add(new Chunk(" słownie ", times));
            four_ph.Add(new Chunk(String.Format("{0} {1}", Formatowanie.LiczbaSlownie(pozostala), Formatowanie.WalutaSlownie(pozostala, "PLN")), timesBold));
            four_ph.Add(new Chunk(" która wypłacona będzie bezpośrednio po zakończeniu imprezy.", times));

            Paragraph four = new Paragraph(four_ph);
            four.Alignment = Element.ALIGN_JUSTIFIED;
            four.SetLeading(0.0f, 1.5f);
            doc.Add(four);

            // &5
            Paragraph five_amp = new Paragraph("&5", timesBold);
            five_amp.Alignment = Element.ALIGN_CENTER;
            five_amp.SetLeading(0.0f, 1.5f);
            doc.Add(five_amp);

            var five_ph = new Phrase();
            five_ph.Add(new Chunk("Wykonawca nie może powierzyć dzieła innym osobom bez zgody zamawiającego. ", times));

            Paragraph five = new Paragraph(five_ph);
            five.Alignment = Element.ALIGN_JUSTIFIED;
            five.SetLeading(0.0f, 1.5f);
            doc.Add(five);

            // &6
            Paragraph six_amp = new Paragraph("&6", timesBold);
            six_amp.Alignment = Element.ALIGN_CENTER;
            six_amp.SetLeading(0.0f, 1.5f);
            doc.Add(six_amp);

            var six_ph = new Phrase();
            six_ph.Add(new Chunk("Zamawiający jest jednocześnie organizatorem imprezy. ", times));

            Paragraph six = new Paragraph(six_ph);
            six.Alignment = Element.ALIGN_JUSTIFIED;
            six.SetLeading(0.0f, 1.5f);
            doc.Add(six);

            // &7
            Paragraph seven_amp = new Paragraph("&7", timesBold);
            seven_amp.Alignment = Element.ALIGN_CENTER;
            seven_amp.SetLeading(0.0f, 1.5f);
            doc.Add(seven_amp);

            var seven_ph = new Phrase();
            seven_ph.Add(new Chunk("Zamawiający ponosi odpowiedzialność materialną za zniszczenie lub uszkodzenie sprzętu powstałe z winy osób nie będących członkami zespołu.", times));

            Paragraph seven = new Paragraph(seven_ph);
            seven.Alignment = Element.ALIGN_JUSTIFIED;
            seven.SetLeading(0.0f, 1.5f);
            doc.Add(seven);

            // &8
            Paragraph eight_amp = new Paragraph("&8", timesBold);
            eight_amp.Alignment = Element.ALIGN_CENTER;
            eight_amp.SetLeading(0.0f, 1.5f);
            doc.Add(eight_amp);

            var eight_ph = new Phrase();
            eight_ph.Add(new Chunk("W przypadku rozwiązania umowy przez zamawiającego, zadatek przechodzi na rzecz wykonawcy. ", times));

            Paragraph eight = new Paragraph(eight_ph);
            eight.Alignment = Element.ALIGN_JUSTIFIED;
            eight.SetLeading(0.0f, 1.5f);
            doc.Add(eight);

            // &9
            Paragraph nine_amp = new Paragraph("&9", timesBold);
            nine_amp.Alignment = Element.ALIGN_CENTER;
            nine_amp.SetLeading(0.0f, 1.5f);
            doc.Add(nine_amp);

            var nine_ph = new Phrase();
            nine_ph.Add(new Chunk("W przypadku rozwiązania umowy przez wykonawcę, zadatek w podwójnej wysokości przechodzi na rzecz zamawiającego.", times));

            Paragraph nine = new Paragraph(nine_ph);
            nine.Alignment = Element.ALIGN_JUSTIFIED;
            nine.SetLeading(0.0f, 1.5f);
            doc.Add(nine);

            // &10
            Paragraph ten_amp = new Paragraph("&10", timesBold);
            ten_amp.Alignment = Element.ALIGN_CENTER;
            ten_amp.SetLeading(0.0f, 1.5f);
            doc.Add(ten_amp);

            var ten_ph = new Phrase();
            ten_ph.Add(new Chunk("W sprawach nie uregulowanych niniejszą umową mają zastosowanie przepisy kodeksu cywilnego.", times));

            Paragraph ten = new Paragraph(ten_ph);
            ten.Alignment = Element.ALIGN_JUSTIFIED;
            ten.SetLeading(0.0f, 1.5f);
            doc.Add(ten);

            // &11
            Paragraph eleven_amp = new Paragraph("&11", timesBold);
            eleven_amp.Alignment = Element.ALIGN_CENTER;
            eleven_amp.SetLeading(0.0f, 1.5f);
            doc.Add(eleven_amp);

            var eleven_ph = new Phrase();
            eleven_ph.Add(new Chunk("Umowę sporządzono w dwóch jednobrzmiących egzemplarzach, po jednym dla każdej ze stron.", times));

            Paragraph eleven = new Paragraph(eleven_ph);
            eleven.Alignment = Element.ALIGN_JUSTIFIED;
            eleven.SetLeading(0.0f, 1.5f);
            doc.Add(eleven);

            // signatures
            var signatures_ph = new Phrase();
            signatures_ph.Add(new Chunk("\n\n             (zamawiający)                                                                                               (wykonawca)    ", times));

            Paragraph signatures = new Paragraph(signatures_ph);
            signatures.Alignment = Element.ALIGN_JUSTIFIED;
            doc.Add(signatures);

            doc.Close();
            System.Windows.Forms.MessageBox.Show("Umowa została wygenerowana.");
        }
Пример #25
0
 /**
  * Creates a shallow clone of the Paragraph.
  * @return
  */
 public virtual Paragraph CloneShallow(bool spacingBefore) {
     Paragraph copy = new Paragraph();
     copy.Font = Font;
     copy.Alignment = Alignment;
     copy.SetLeading(Leading, multipliedLeading);
     copy.IndentationLeft = IndentationLeft;
     copy.IndentationRight = IndentationRight;
     copy.FirstLineIndent = FirstLineIndent;
     copy.SpacingAfter = SpacingAfter;
     if (spacingBefore)
         copy.SpacingBefore = SpacingBefore;
     copy.ExtraParagraphSpace = ExtraParagraphSpace;
     copy.Role = Role;
     copy.id = ID;
     if (accessibleAttributes != null)
         copy.accessibleAttributes = new Dictionary<PdfName, PdfObject>(accessibleAttributes);
     copy.TabSettings = this.TabSettings;
     copy.KeepTogether = this.KeepTogether;
     return copy;
 }
Пример #26
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;
            }
        }
Пример #27
0
 /**
  * Creates a shallow clone of the Paragraph.
  * @return
  */
 virtual public Paragraph cloneShallow(bool spacingBefore) {
     Paragraph copy = new Paragraph();
     copy.Font = Font;
     copy.Alignment = Alignment;
     copy.SetLeading(Leading, multipliedLeading);
     copy.IndentationLeft = IndentationLeft;
     copy.IndentationRight = IndentationRight;
     copy.FirstLineIndent = FirstLineIndent;
     copy.SpacingAfter = SpacingAfter;
     if (spacingBefore)
         copy.SpacingBefore = SpacingBefore;
     copy.ExtraParagraphSpace = ExtraParagraphSpace;
     return copy;
 }
Пример #28
0
        public ResultResponse SaveBarcodes(BarcodeGenarateModal barcodeGenarateModal, int userId)
        {
            ResultResponse resultResponse   = new ResultResponse();
            int            masterPrimaryKey = 0;

            try
            {
                accessManager.SqlConnectionOpen(DataBase.WorkerInsentive);
                List <SqlParameter> aParameters = new List <SqlParameter>();
                aParameters.Add(new SqlParameter("@StyleNo", barcodeGenarateModal.StyleID));
                aParameters.Add(new SqlParameter("@GenarateDate", barcodeGenarateModal.SelectDate));
                aParameters.Add(new SqlParameter("@BundleQuantity", barcodeGenarateModal.Quantity));
                aParameters.Add(new SqlParameter("@Size", barcodeGenarateModal.BundleSize));
                aParameters.Add(new SqlParameter("@Color", barcodeGenarateModal.Color));
                aParameters.Add(new SqlParameter("@CreateBy", userId));
                aParameters.Add(new SqlParameter("@CutNo", barcodeGenarateModal.CutNo));
                aParameters.Add(new SqlParameter("@ShadeNo", barcodeGenarateModal.ShadeNO));
                aParameters.Add(new SqlParameter("@BuyerId", barcodeGenarateModal.BuyerID));
                aParameters.Add(new SqlParameter("@PONumber", barcodeGenarateModal.PONumber));
                aParameters.Add(new SqlParameter("@QuantityGenarate", (barcodeGenarateModal.Quantity * barcodeGenarateModal.NoOfBundle)));
                aParameters.Add(new SqlParameter("@BusinessUnitId", barcodeGenarateModal.BusinessUnitId));
                aParameters.Add(new SqlParameter("@MachineId", barcodeGenarateModal.MachineId));
                aParameters.Add(new SqlParameter("@LotNo", barcodeGenarateModal.LotNo));
                masterPrimaryKey = accessManager.SaveDataReturnPrimaryKey("sp_SaveGenaratedMasterTable", aParameters);
            }
            catch (Exception exception)
            {
                accessManager.SqlConnectionClose(true);
                throw exception;
            }
            finally
            {
                accessManager.SqlConnectionClose();
            }
            var pgSize = new iTextSharp.text.Rectangle(225, 75);                             //225,75

            iTextSharp.text.Document doc = new iTextSharp.text.Document(pgSize, 0, 0, 2, 2); //0,0,0,0
            string   path     = HttpContext.Current.Server.MapPath("~/GenaratePDF/");
            DateTime dt       = DateTime.Now;
            string   fileName = dt.Minute.ToString() + dt.Second.ToString() + dt.Millisecond.ToString();

            PdfWriter.GetInstance(doc, new FileStream(path + fileName + ".pdf", FileMode.Create));
            //open the document for writing
            doc.Open();
            // doc.SetPageSize(new iTextSharp.text.Rectangle(100,65));
            PdfPTable pdftable = new PdfPTable(1);

            for (int i = 0; i < barcodeGenarateModal.NoOfBundle; i++)
            {
                int count = 0;
                iTextSharp.text.Font font     = FontFactory.GetFont("Calibri", 6f, BaseColor.BLACK); // from 5.0f
                iTextSharp.text.Font fontlast = FontFactory.GetFont("Calibri", 6f, BaseColor.BLACK); // from 5.0f
                //String header = "Buyer Name : " + barcodeGenarateModal.BuyerName+"\nStyle : " + barcodeGenarateModal.StyleName + "\nBundle Quantity : " + barcodeGenarateModal.Quantity +
                //        "\nBundle No : " + (i+1) + "\nColor : " + barcodeGenarateModal.Color + ", Size : " + barcodeGenarateModal.BundleSize+ "\nPO Number : " + barcodeGenarateModal.PONumber;
                //iTextSharp.text.Paragraph paraheader = new iTextSharp.text.Paragraph(header, font);
                //PdfPCell cell1 = new PdfPCell { PaddingLeft = 0, PaddingTop = 0, PaddingBottom = 0, PaddingRight = 0 };
                // cell1.AddElement(paraheader);
                // cell1.Border = 0;
                //pdftable.AddCell(cell1);
                foreach (CommonModel barcodeGenarate in barcodeGenarateModal.OprationList)
                {
                    count++;
                    int barcodeNo = BarcodePrimaryKey(masterPrimaryKey, i + 1, barcodeGenarate, barcodeGenarateModal.BusinessUnitId);
                    var bw        = new ZXing.BarcodeWriter()
                    {
                        Format = ZXing.BarcodeFormat.PDF_417
                    };
                    bw.Options = new ZXing.Common.EncodingOptions()
                    {
                        Margin = 1
                    };

                    // var encOptions = new ZXing.Common.EncodingOptions() { Margin = 0}; // margin 0 to 1

                    //bw.Format = ZXing.BarcodeFormat.CODE_128;
                    var    bitmap = bw.Write(barcodeNo + "," + barcodeGenarate.OperationSMV);
                    Bitmap result = new Bitmap(bitmap, new Size(210, 55));  //100,60 // 210,60
                    //var result = new Bitmap();
                    result.Save(path + barcodeGenarate.OperationName, System.Drawing.Imaging.ImageFormat.Png);
                    //barcodeNo + "-" +
                    string first = barcodeNo + " , " + barcodeGenarateModal.StyleName + ", " + barcodeGenarate.OperationName + "," + barcodeGenarateModal.BundleSize;
                    string last  = barcodeGenarate.OperationSMV +
                                   ", " + barcodeGenarateModal.SelectDate + ","
                                   + barcodeGenarateModal.Quantity +
                                   ", " + (i + 1) + "-" + count + ", " + barcodeGenarateModal.Color + "," + barcodeGenarateModal.PONumber;

                    iTextSharp.text.Paragraph paragraph     = new iTextSharp.text.Paragraph(first, font);
                    iTextSharp.text.Paragraph lastparagraph = new iTextSharp.text.Paragraph(last, fontlast);
                    paragraph.SetLeading(0.8f, 0.8f);
                    paragraph.SpacingAfter = 1;    //2
                    lastparagraph.SetLeading(0.8f, 0.8f);
                    iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(path + barcodeGenarate.OperationName);
                    //image.SpacingAfter = 5;// for code 128
                    //image.ScaleAbsolute(85,50);
                    // image.PaddingTop = 3.0f;
                    PdfPCell cell = new PdfPCell {
                        PaddingLeft = 0, PaddingTop = 0, PaddingBottom = 0, PaddingRight = 0
                    };
                    // cell.FixedHeight = 60;
                    cell.AddElement(paragraph);
                    cell.AddElement(image);
                    cell.AddElement(lastparagraph);
                    cell.Border = 0;
                    pdftable.AddCell(cell);
                    File.Delete(path + barcodeGenarate.OperationName);
                }
            }
            doc.Add(pdftable);
            doc.Close();
            resultResponse.isSuccess = true;
            resultResponse.data      = path + fileName + ".pdf";
            return(resultResponse);
        }
Пример #29
0
        protected override Stream Read()
        {
            Document doc = new Document(PageSize.A4, 50, 50, 50, 50);
            doc.AddTitle(Title);
            doc.AddCreationDate();
            doc.AddCreator("iTextSharp");
            doc.AddAuthor("文化中国");
            doc.AddSubject(w.Excerpt);
            doc.AddKeywords(w.Tags);
            using (MemoryStream stream = new MemoryStream())
            {
                PdfWriter writer = PdfWriter.GetInstance(doc, stream);
                writer.SetEncryption(true, null, null, 0);
                writer.PageEvent = new HeaderFooterPdfPageEventHelper();

                doc.Open();

                Paragraph p = new Paragraph(Title, font);
                p.Alignment = 1;
                doc.Add(p);

                MatchCollection matches = regex.Matches(w.Script.Text);
                foreach (Match m in matches)
                {
                    Chunk chunk = new Chunk(m.Groups["cont"].Value);
                    switch (m.Groups["tag"].Value.ToLower())
                    {
                        case "h1":
                            font.Color = BaseColor.WHITE;
                            chunk.SetBackground(BaseColor.DARK_GRAY);
                            break;
                        case "p":
                            font.Color = BaseColor.BLACK;
                            break;
                    }
                    chunk.Font = font;
                    p = new Paragraph(chunk);
                    p.SetLeading(0.0f, 2.0f);
                    p.FirstLineIndent = 20f;
                    p.Alignment = 0;
                    doc.Add(p);
                }
                doc.Close();

                return new MemoryStream(stream.GetBuffer());
            }
        }
Пример #30
0
 protected void PopulateProperties(Paragraph copy, bool spacingBefore) {
     copy.Font = Font;
     copy.Alignment = Alignment;
     copy.SetLeading(Leading, multipliedLeading);
     copy.IndentationLeft = IndentationLeft;
     copy.IndentationRight = IndentationRight;
     copy.FirstLineIndent = FirstLineIndent;
     copy.SpacingAfter = SpacingAfter;
     if (spacingBefore)
         copy.SpacingBefore = SpacingBefore;
     copy.ExtraParagraphSpace = ExtraParagraphSpace;
     copy.Role = Role;
     copy.id = ID;
     if (accessibleAttributes != null)
         copy.accessibleAttributes = new Dictionary<PdfName, PdfObject>(accessibleAttributes);
     copy.TabSettings = this.TabSettings;
     copy.KeepTogether = this.KeepTogether;
 }
 // 函数描述:插入中间的信息----
 public static Paragraph InsertTopCommonParagraph(string text)
 {
     var font = BaseFontAndSize("黑体", 14, Font.NORMAL);
     var paragraph = new Paragraph(text, font)
         {
             FirstLineIndent = 16,
             IndentationLeft = 130,
             IndentationRight = 20,
             SpacingBefore = 1,
             SpacingAfter = 1
         };
     paragraph.SetLeading(1, 2.2f);
     //paragraph.IndentationLeft = 24;
     paragraph.Alignment = 0;
     return paragraph;
 }
Пример #32
0
        private Paragraph GetAttendance(Person p)
        {
            var q = from a in p.Attends
                    where a.AttendanceFlag
                    orderby a.MeetingDate.Date descending
                    group a by a.MeetingDate.Date
                    into g
                    select g.Key;
            var list = q.ToList();

            var attstr = new StringBuilder("\n");
            var dt = Util.Now;
            var yearago = dt.AddYears(-1);
            while (dt > yearago)
            {
                var dt2 = dt.AddDays(-7);
                var indicator = ".";
                foreach (var d in list)
                {
                    if (d < dt2)
                        break;
                    if (d <= dt)
                    {
                        indicator = "P";
                        break;
                    }
                }
                attstr.Insert(0, indicator);
                dt = dt2;
            }
            var ph = new Paragraph(attstr.ToString(), monofont);
            ph.SetLeading(0, 1.2f);

            attstr = new StringBuilder();
            foreach (var d in list.Take(8))
                attstr.Insert(0, $"{d:d}  ");
            if (list.Count > 8)
            {
                attstr.Insert(0, "...  ");
                var q2 = q.OrderBy(d => d).Take(Math.Min(list.Count - 8, 3));
                foreach (var d in q2.OrderByDescending(d => d))
                    attstr.Insert(0, $"{d:d}  ");
            }
            ph.Add(new Chunk(attstr.ToString(), smallfont));
            return ph;
        }
Пример #33
0
        public MemoryStream KrijoRaportin(Dokument dokumenti)
        {
            var doc = new Document();
            doc.SetMargins(50f, 50f, 10f, 50f);

            var ms = new MemoryStream();
            PdfWriter.GetInstance(doc, ms);

            doc.Open();

            Paragraph webpage = new Paragraph("http://eid.uni-pr.edu/signaturecheck/", new Font(Font.FontFamily.UNDEFINED, 10, Font.NORMAL));
            webpage.SpacingAfter = 20f;
            webpage.Alignment = 2;
            doc.Add(webpage);

            Paragraph header = new Paragraph("Raporti i verifikimit", new Font(Font.FontFamily.UNDEFINED, 16, Font.BOLD));
            header.SpacingAfter = 30f;
            header.Alignment = 1;
            doc.Add(header);

            PdfPTable tblDokumenti = new PdfPTable(3);
            float[] widths = new float[] { 40f, 10f, 50f };
            tblDokumenti.SetWidths(widths);
            tblDokumenti.SpacingAfter = 20;

            CreateCell(tblDokumenti, "Dokumenti", 3, 0, true, new BaseColor(66, 139, 202), new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Nenshkrimi digjital", 1, 0, true, new BaseColor(255, 255, 255));

            string rezultatiVerifikimit;
            iTextSharp.text.Image img;
            if(dokumenti.Nenshkrimet.Count() == 0)
            {
                rezultatiVerifikimit = "Nuk ekziston nenshkrim digjital ne kete dokument.";
                img = ImgNot;
            }
            else if(dokumenti.Nenshkrimet.All(nenshkrim => nenshkrim.Valid))
            {
                rezultatiVerifikimit = "Nenshkrimi u verifikua me sukses.";
                img = ImgOK;
            }
            else
            {
                rezultatiVerifikimit = "Nuk u verifikua nenshkrimi digjital.";
                img = ImgNot;
            }

            img.ScaleAbsolute(25, 25);

            CreateCell(tblDokumenti, "", 1, 0, false, new BaseColor(255, 255, 255), null, img);
            CreateCell(tblDokumenti, rezultatiVerifikimit, 1, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Koha e verifikimit", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.KohaVerifikimit.ToString(), 2, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Emri i dokumentit", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.Emri, 2, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Vlera hash e dokumentit (SHA256)", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.VleraHashString, 2, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Madhesia e dokumentit", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.Madhesia, 2, 0, false, new BaseColor(255, 255, 255));

            doc.Add(tblDokumenti);

            foreach(Nenshkrim nenshkrimi in dokumenti.Nenshkrimet)
            {
                PdfPTable tblNenshkruesi = new PdfPTable(2);
                tblNenshkruesi.SpacingAfter = 20;

                CreateCell(tblNenshkruesi, "Te dhenat e nenshkruesit", 2, 0, true, new BaseColor(66, 139, 202), new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Nenshkruesi", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.Nenshkruesi, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Emri", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.Emri, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Mbiemri", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.Mbiemri, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Data e nenshkrimit", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.DataNenshkrimit.ToString(), 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Algoritmi i Hashit", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.AlgoritmiHash, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Algoritmi i Enkriptimit", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.AlgoritmiEnkriptimit, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Certifikata valide prej", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.CertifikataValidePrej, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Certifikata valide deri", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.CertifikataValideDeri, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Numri serik i certifikates", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.SerialNumber, 1, 0, false, new BaseColor(255, 255, 255));

                doc.Add(tblNenshkruesi);

                PdfPTable tblIssuer = new PdfPTable(2);

                CreateCell(tblIssuer, "Te dhenat e leshuesit te certifikates", 2, 0, true, new BaseColor(66, 139, 202), new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Emri(CN)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerCN, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Njesia organizative(OU)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerOU, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Organizata(O)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerO, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Shteti(C)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerC, 1, 0, false, new BaseColor(255, 255, 255));

                tblIssuer.SpacingAfter = 20;
                doc.Add(tblIssuer);
            }

            //vije horizontale
            Paragraph line = new Paragraph(doc.Bottom, new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));
            line.SpacingAfter = 0f;
            doc.Add(line);

            //footer
            string shenim = "Shenim: Bazuar ne Ligjin Per Sherbimet e Shoqerise Informatike, Neni 1 - Përcakton dokumentacionin në formë elektronike juridikisht të barabartë me dokumentacionin tradicional të paraqitur në format të letrës.";
            Paragraph footer = new Paragraph(shenim, new Font(Font.FontFamily.UNDEFINED, 8, Font.NORMAL, new BaseColor(32, 32, 32)));
            footer.SetLeading(12f, 0);
            footer.SpacingBefore = 0f;
            doc.Add(footer);

            doc.Close();

            return ms;
        }
Пример #34
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;
            }
        }
Пример #35
0
        public MemoryStream CreateReport(Dokument dokumenti)
        {
            var doc = new Document();
            doc.SetMargins(50f, 50f, 10f, 50f);

            var ms = new MemoryStream();
            PdfWriter.GetInstance(doc, ms);

            doc.Open();

            Paragraph webpage = new Paragraph("http://eid.uni-pr.edu/signaturecheck/", new Font(Font.FontFamily.UNDEFINED, 10, Font.NORMAL));
            webpage.SpacingAfter = 20f;
            webpage.Alignment = 2;
            doc.Add(webpage);

            Paragraph header = new Paragraph("Verification Report", new Font(Font.FontFamily.UNDEFINED, 16, Font.BOLD));
            header.SpacingAfter = 30f;
            header.Alignment = 1;
            doc.Add(header);

            PdfPTable tblDokumenti = new PdfPTable(3);
            float[] widths = new float[] { 40f, 10f, 50f };
            tblDokumenti.SetWidths(widths);
            tblDokumenti.SpacingAfter = 20;

            CreateCell(tblDokumenti, "Document", 3, 0, true, new BaseColor(66, 139, 202), new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Signature check", 1, 0, true, new BaseColor(255, 255, 255));

            string rezultatiVerifikimit;
            iTextSharp.text.Image img;
            if (dokumenti.Nenshkrimet.Count() == 0)
            {
                rezultatiVerifikimit = "This file does not have digital signature.";
                img = ImgNot;
            }
            else if (dokumenti.Nenshkrimet.All(nenshkrim => nenshkrim.Valid))
            {
                rezultatiVerifikimit = "Signature verification successful.";
                img = ImgOK;
            }
            else
            {
                rezultatiVerifikimit = "Signature verification failed.";
                img = ImgNot;
            }

            img.ScaleAbsolute(25, 25);

            CreateCell(tblDokumenti, "", 1, 0, false, new BaseColor(255, 255, 255), null, img);
            CreateCell(tblDokumenti, rezultatiVerifikimit, 1, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Verification date and time", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.KohaVerifikimit.ToString(), 2, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Name of signed file", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.Emri, 2, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Hash value of signed data (SHA256)", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.VleraHashString, 2, 0, false, new BaseColor(255, 255, 255));

            CreateCell(tblDokumenti, "Size of signed file", 1, 0, true, new BaseColor(255, 255, 255));
            CreateCell(tblDokumenti, dokumenti.Madhesia, 2, 0, false, new BaseColor(255, 255, 255));

            doc.Add(tblDokumenti);

            foreach (Nenshkrim nenshkrimi in dokumenti.Nenshkrimet)
            {
                PdfPTable tblNenshkruesi = new PdfPTable(2);
                tblNenshkruesi.SpacingAfter = 20;

                CreateCell(tblNenshkruesi, "Certificate information", 2, 0, true, new BaseColor(66, 139, 202), new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Signer", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.Nenshkruesi, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "First Name", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.Emri, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Last Name", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.Mbiemri, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Signing time", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.DataNenshkrimit.ToString(), 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Hash Algorithm", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.AlgoritmiHash, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Encryption Algorithm", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.AlgoritmiEnkriptimit, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Certificate valid from", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.CertifikataValidePrej, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Certificate valid to", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.CertifikataValideDeri, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblNenshkruesi, "Certificate serial number", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblNenshkruesi, nenshkrimi.SerialNumber, 1, 0, false, new BaseColor(255, 255, 255));

                doc.Add(tblNenshkruesi);

                PdfPTable tblIssuer = new PdfPTable(2);

                CreateCell(tblIssuer, "Info of certificate issuer", 2, 0, true, new BaseColor(66, 139, 202), new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Name(CN)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerCN, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Organizational unit(OU)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerOU, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Organization(O)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerO, 1, 0, false, new BaseColor(255, 255, 255));

                CreateCell(tblIssuer, "Country(C)", 1, 0, true, new BaseColor(255, 255, 255));
                CreateCell(tblIssuer, nenshkrimi.IssuerC, 1, 0, false, new BaseColor(255, 255, 255));

                tblIssuer.SpacingAfter = 20;
                doc.Add(tblIssuer);
            }

            //vije horizontale
            Paragraph line = new Paragraph(doc.Bottom, new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));
            line.SpacingAfter = 0f;
            doc.Add(line);

            //footer
            string shenim = "Note: Based on the Law on Information Society Services, Article 1 - Defines electronic documentation identical to Its traditional Legally counterpart in paper format.";
            Paragraph footer = new Paragraph(shenim, new Font(Font.FontFamily.UNDEFINED, 8, Font.NORMAL, new BaseColor(32, 32, 32)));
            footer.SetLeading(12f, 0);
            footer.SpacingBefore = 0f;
            doc.Add(footer);

            doc.Close();

            return ms;
        }
Пример #36
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;
            }
        }
Пример #37
0
        protected override Stream Read()
        {
            Document doc = new Document(PageSize.A4, 50, 50, 50, 50);
            doc.AddTitle(Title);
            doc.AddCreationDate();
            doc.AddCreator("iTextSharp");
            doc.AddAuthor("文化中国");
            doc.AddSubject(f.Brief);
            using (MemoryStream stream = new MemoryStream())
            {
                PdfWriter writer = PdfWriter.GetInstance(doc, stream);
                writer.SetEncryption(true, null, null, PdfWriter.ALLOW_PRINTING);
                writer.ViewerPreferences = PdfWriter.PageModeUseOutlines;
                writer.PageEvent = new HeaderFooterPdfPageEventHelper();

                doc.Open();

                foreach (var w in f.Webcasts.Where(w => w.Script != null).OrderBy(w => w.Aired))
                {
                    Paragraph p = new Paragraph(w.Title, font);
                    p.Alignment = 1;
                    Chapter chapter = new Chapter(p, 1);
                    chapter.NumberDepth = 0;
                    chapter.BookmarkTitle = w.Title;
                    chapter.TriggerNewPage = true;
                    doc.Add(chapter);

                    MatchCollection matches = regex.Matches(w.Script.Text);
                    foreach (Match m in matches)
                    {
                        Chunk chunk = new Chunk(m.Groups["cont"].Value);
                        switch (m.Groups["tag"].Value.ToLower())
                        {
                            case "h1":
                                font.Color = BaseColor.WHITE;
                                chunk.SetBackground(BaseColor.DARK_GRAY);
                                break;
                            case "p":
                                font.Color = BaseColor.BLACK;
                                break;
                        }
                        chunk.Font = font;
                        p = new Paragraph(chunk);
                        p.SetLeading(0.0f, 2.0f);
                        p.FirstLineIndent = 20f;
                        p.Alignment = 0;
                        doc.Add(p);
                    }
                }

                doc.Close();
                return new MemoryStream(stream.GetBuffer());
            }
        }
Пример #38
0
 /**
  * Sets the leading of a Paragraph object.
  * @param   paragraph   the Paragraph for which we set the leading
  * @param   leading     the String value of the leading
  */
 protected static void SetParagraphLeading(Paragraph paragraph, String leading) {
     // default leading
     if (leading == null) {
         paragraph.SetLeading(0, 1.5f);
         return;
     }
     try {
         StringTokenizer tk = new StringTokenizer(leading, " ,");
         // absolute leading
         String v = tk.NextToken();
         float v1 = float.Parse(v, CultureInfo.InvariantCulture);
         if (!tk.HasMoreTokens()) {
             paragraph.SetLeading(v1, 0);
             return;
         }
         // relative leading
         v = tk.NextToken();
         float v2 = float.Parse(v, CultureInfo.InvariantCulture);
         paragraph.SetLeading(v1, v2);
     } catch {
         // default leading
         paragraph.SetLeading(0, 1.5f);
     }
 }
Пример #39
0
        public static string generarPdf(Hashtable htFacturaxion, HttpContext hc)
        {
            string pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString();
            FileStream fs = new FileStream(pathPdf, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);

            try
            {
                DAL dal = new DAL();
                StringBuilder sbConfigFactParms = new StringBuilder();
                StringBuilder sbConfigFact = new StringBuilder();
                StringBuilder sbDataEmisor = new StringBuilder();
                StringBuilder sbOpcionalEncabezado = new StringBuilder();
                DataTable dtConfigFact = new DataTable();
                DataTable dtDataEmisor = new DataTable();
                DataTable dtOpcEncabezado = new DataTable();
                _ci.NumberFormat.CurrencyDecimalDigits = 4;
                _c2.NumberFormat.CurrencyDecimalDigits = 2;

                electronicDocument = (ElectronicDocument)htFacturaxion["electronicDocument"];
                objTimbre = (Data)htFacturaxion["objTimbre"];
                timbrar = Convert.ToBoolean(htFacturaxion["timbrar"]);
                //pathPdf = htFacturaxion["rutaDocumentoPdf"].ToString();
                Int64 idCfdi = Convert.ToInt64(htFacturaxion["idCfdi"]);

                #region "Extraemos los datos del CFDI"

                sbConfigFactParms.
                    Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idSucursalEmisor"])).
                    Append(";").
                    Append("F:I:").Append(Convert.ToInt32(htFacturaxion["tipoComprobante"])).
                    Append(";").
                    Append("F:S:").Append(electronicDocument.Data.Total.Value).
                    Append(";").
                    Append("F:I:").Append(Convert.ToInt32(htFacturaxion["idMoneda"])).
                    Append(";").
                    Append("F:I:").Append(Convert.ToInt64(htFacturaxion["idEmisor"]));

                sbConfigFact.
                    Append("DECLARE @idEmpresa AS INT; SET @idEmpresa = 0; ").
                    Append("SELECT rutaTemplateHeader, CF.rutaLogo, objDesc, posX, posY, fontSize, dbo.convertNumToTextFunction( @2, @3) AS cantidadLetra, ").
                    Append("logoPosX, logoPosY, headerPosX, headerPosY, footerPosX, footerPosY, conceptosColWidth, desgloseColWidth, S.nombreSucursal ").
                    Append("FROM configuracionFacturas CF ").
                    Append("LEFT OUTER JOIN sucursales S ON S.idSucursal = @0 ").
                    Append("LEFT OUTER JOIN configuracionFactDet CFD ON CF.idConFact = CFD.idConFact ").
                    Append("WHERE CF.ST = 1 AND CF.idEmpresa = -1 AND CF.idTipoComp = @1 AND idCFDProcedencia = 1 AND objDesc NOT LIKE 'nuevoLbl%' ");

                sbDataEmisor.
                    Append("SELECT nombreSucursal FROM sucursales WHERE idSucursal = @0 ");

                sbOpcionalEncabezado.
                    Append("SELECT campo1 AS observaciones ").
                    //Append("campo2 AS observaciones2").
                    //Append("campo3 AS observaciones3").
                    Append("FROM opcionalEncabezado WHERE idCFDI = @0 and ST = 1");

                dtConfigFact = dal.QueryDT("DS_FE", sbConfigFact.ToString(), sbConfigFactParms.ToString(), hc);
                dtDataEmisor = dal.QueryDT("DS_FE", sbDataEmisor.ToString(), "F:I:" + htFacturaxion["idSucursalEmisor"].ToString(), hc);
                dtOpcEncabezado = dal.QueryDT("DS_FE", sbOpcionalEncabezado.ToString(), "F:I:" + idCfdi, hc);

                Hashtable htDatosCfdi = new Hashtable();

                #region "Dirección Emisor"

                StringBuilder sbDirEmisor1 = new StringBuilder();
                StringBuilder sbDirEmisor2 = new StringBuilder();
                StringBuilder sbDirEmisor3 = new StringBuilder();

                if (electronicDocument.Data.Emisor.Domicilio.Calle.Value.Length > 0)
                {
                    sbDirEmisor1.Append("Calle ").Append(electronicDocument.Data.Emisor.Domicilio.Calle.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value.Length > 0)
                {
                    sbDirEmisor1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroExterior.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value.Length > 0)
                {
                    sbDirEmisor1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.Domicilio.NumeroInterior.Value);
                }

                if (electronicDocument.Data.Emisor.Domicilio.Colonia.Value.Length > 0)
                {
                    sbDirEmisor2.Append("Col. ").Append(electronicDocument.Data.Emisor.Domicilio.Colonia.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value.Length > 0)
                {
                    sbDirEmisor2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.Domicilio.CodigoPostal.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.Localidad.Value.Length > 0)
                {
                    sbDirEmisor2.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Localidad.Value);
                }

                if (electronicDocument.Data.Emisor.Domicilio.Municipio.Value.Length > 0)
                {
                    sbDirEmisor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.Domicilio.Municipio.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.Domicilio.Estado.Value.Length > 0)
                {
                    sbDirEmisor3.Append(", Estado ").Append(electronicDocument.Data.Emisor.Domicilio.Estado.Value).Append(" ");
                }

                sbDirEmisor3.Append(", ").Append(electronicDocument.Data.Emisor.Domicilio.Pais.Value);

                #endregion

                #region "Dirección Sucursal Expedido En"

                StringBuilder sbDirExpedido1 = new StringBuilder();
                StringBuilder sbDirExpedido2 = new StringBuilder();
                StringBuilder sbDirExpedido3 = new StringBuilder();

                if (electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value.Length > 0)
                {
                    sbDirExpedido1.Append("Calle ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Calle.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value.Length > 0)
                {
                    sbDirExpedido1.Append(", No. Ext ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroExterior.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value.Length > 0)
                {
                    sbDirExpedido1.Append(", No. Int ").Append(electronicDocument.Data.Emisor.ExpedidoEn.NumeroInterior.Value);
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value.Length > 0)
                {
                    sbDirExpedido2.Append("Col. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Colonia.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value.Length > 0)
                {
                    sbDirExpedido2.Append(", C.P. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.CodigoPostal.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value.Length > 0)
                {
                    sbDirExpedido2.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Localidad.Value);
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value.Length > 0)
                {
                    sbDirExpedido3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Municipio.Value).Append(" ");
                }

                if (electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value.Length > 0)
                {
                    sbDirExpedido3.Append(", Estado ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Estado.Value).Append(" ");
                }

                sbDirExpedido3.Append(", ").Append(electronicDocument.Data.Emisor.ExpedidoEn.Pais.Value);

                #endregion

                #region "Dirección Receptor"

                StringBuilder sbDirReceptor1 = new StringBuilder();
                StringBuilder sbDirReceptor2 = new StringBuilder();
                StringBuilder sbDirReceptor3 = new StringBuilder();

                if (electronicDocument.Data.Receptor.Domicilio.Calle.Value.Length > 0)
                {
                    sbDirReceptor1.Append("Calle ").Append(electronicDocument.Data.Receptor.Domicilio.Calle.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value.Length > 0)
                {
                    sbDirReceptor1.Append(", No. Ext ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroExterior.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value.Length > 0)
                {
                    sbDirReceptor1.Append(", No. Int ").Append(electronicDocument.Data.Receptor.Domicilio.NumeroInterior.Value);
                }

                if (electronicDocument.Data.Receptor.Domicilio.Colonia.Value.Length > 0)
                {
                    sbDirReceptor2.Append("Col. ").Append(electronicDocument.Data.Receptor.Domicilio.Colonia.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value.Length > 0)
                {
                    sbDirReceptor2.Append(", C.P. ").Append(electronicDocument.Data.Receptor.Domicilio.CodigoPostal.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.Localidad.Value.Length > 0)
                {
                    sbDirReceptor2.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Localidad.Value);
                }

                if (electronicDocument.Data.Receptor.Domicilio.Municipio.Value.Length > 0)
                {
                    sbDirReceptor3.Append("Mpio. / Del. ").Append(electronicDocument.Data.Receptor.Domicilio.Municipio.Value).Append(" ");
                }

                if (electronicDocument.Data.Receptor.Domicilio.Estado.Value.Length > 0)
                {
                    sbDirReceptor3.Append(", Estado ").Append(electronicDocument.Data.Receptor.Domicilio.Estado.Value).Append(" ");
                }

                sbDirReceptor3.Append(", ").Append(electronicDocument.Data.Receptor.Domicilio.Pais.Value);

                #endregion

                htDatosCfdi.Add("rfcEmisor", electronicDocument.Data.Emisor.Rfc.Value);
                htDatosCfdi.Add("rfcEmpresa", electronicDocument.Data.Emisor.Rfc.Value);

                htDatosCfdi.Add("nombreEmisor", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value);
                htDatosCfdi.Add("empresa", "Razón Social " + electronicDocument.Data.Emisor.Nombre.Value);

                htDatosCfdi.Add("rfcReceptor", electronicDocument.Data.Receptor.Rfc.Value);
                htDatosCfdi.Add("rfcCliente", electronicDocument.Data.Receptor.Rfc.Value);

                htDatosCfdi.Add("nombreReceptor", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value);
                htDatosCfdi.Add("cliente", "Razón Social " + electronicDocument.Data.Receptor.Nombre.Value);

                htDatosCfdi.Add("sucursal", "Sucursal " + dtDataEmisor.Rows[0]["nombreSucursal"]);

                htDatosCfdi.Add("serie", electronicDocument.Data.Serie.Value);
                htDatosCfdi.Add("folio", electronicDocument.Data.Folio.Value);

                htDatosCfdi.Add("fechaCfdi", electronicDocument.Data.Fecha.Value);
                htDatosCfdi.Add("fechaFactura", electronicDocument.Data.Fecha.Value);

                htDatosCfdi.Add("UUID", objTimbre.Uuid.Value.ToUpper());
                htDatosCfdi.Add("folioFiscal", objTimbre.Uuid.Value);

                htDatosCfdi.Add("direccionEmisor1", sbDirEmisor1.ToString());
                htDatosCfdi.Add("direccionEmpresa1", sbDirEmisor1.ToString());

                htDatosCfdi.Add("direccionEmisor2", sbDirEmisor2.ToString());
                htDatosCfdi.Add("direccionEmpresa2", sbDirEmisor2.ToString());

                htDatosCfdi.Add("direccionEmisor3", sbDirEmisor3.ToString());
                htDatosCfdi.Add("direccionEmpresa3", sbDirEmisor3.ToString());

                htDatosCfdi.Add("direccionExpedido1", sbDirExpedido1.ToString());
                htDatosCfdi.Add("direccionSucursal1", sbDirExpedido1.ToString());

                htDatosCfdi.Add("direccionExpedido2", sbDirExpedido2.ToString());
                htDatosCfdi.Add("direccionSucursal2", sbDirExpedido2.ToString());

                htDatosCfdi.Add("direccionExpedido3", sbDirExpedido3.ToString());
                htDatosCfdi.Add("direccionSucursal3", sbDirExpedido3.ToString());

                htDatosCfdi.Add("direccionReceptor1", sbDirReceptor1.ToString());
                htDatosCfdi.Add("direccionCliente1", sbDirReceptor1.ToString());

                htDatosCfdi.Add("direccionReceptor2", sbDirReceptor2.ToString());
                htDatosCfdi.Add("direccionCliente2", sbDirReceptor2.ToString());

                htDatosCfdi.Add("direccionReceptor3", sbDirReceptor3.ToString());
                htDatosCfdi.Add("direccionCliente3", sbDirReceptor3.ToString());

                #endregion

                #region "Creamos el Objeto Documento y Tipos de Letra"

                Document document = new Document(PageSize.LETTER, 15, 15, 15, 40);
                document.AddAuthor("Facturaxion");
                document.AddCreator("r3Take");
                document.AddCreationDate();

               //pdfPageEventHandlerProbell pageEventHandler = new pdfPageEventHandlerProbell();
                PdfWriter writer = PdfWriter.GetInstance(document, fs);
                writer.SetFullCompression();
                writer.ViewerPreferences = PdfWriter.PageModeUseNone;
                //writer.PageEvent = pageEventHandler;
                PdfPageEventHandlerSoliplas sol = new PdfPageEventHandlerSoliplas();
                writer.PageEvent = sol;
                writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_7);

                azul = new Color(22, 111, 168);
                azul1 = new Color(43, 145, 175);
                blanco = new Color(255, 255, 255);
                Link = new Color(7, 73, 208);
                gris = new Color(236, 236, 236);
                grisOX = new Color(220, 215, 220);
                rojo = new Color(230, 7, 7);
                lbAzul = new Color(43, 145, 175);

                EM = BaseFont.CreateFont(@"C:\Windows\Fonts\VERDANA.TTF", BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
                f5 = new Font(EM, 5);
                f5B = new Font(EM, 5, Font.BOLD);
                f5BBI = new Font(EM, 5, Font.BOLDITALIC);
                f6 = new Font(EM, 6);
                f6B = new Font(EM, 6, Font.BOLD);
                f6L = new Font(EM, 6, Font.BOLD, Link);
                f5L = new Font(EM, 5, Font.BOLD, lbAzul);
                titulo = new Font(EM, 6, Font.BOLD, blanco);
                folio = new Font(EM, 6, Font.BOLD, rojo);
                PdfPCell cell;
                Paragraph par;
                Cell cel;
                dSaltoLinea = new Chunk("\n\n ");

                #endregion

                PdfPTable encabezado = new PdfPTable(3);
                encabezado.WidthPercentage = 100;
                encabezado.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
                encabezado.SetWidths(new int[3] { 30, 10, 60 });
                encabezado.DefaultCell.Border = 0;
                encabezado.LockedWidth = true;

                pathIMGLOGO = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\SOLIPLAS\logoSoliplas.png";
                pathIMGFX = @"C:\Inetpub\repositorioFacturaxion\imagesFacturaEspecial\SOLIPLAS\cfdifx.png";

                Image imgLogo = Image.GetInstance(pathIMGLOGO);
                imgLogo.ScalePercent(48f);
                Image imgFx = Image.GetInstance(pathIMGFX);
                imgFx.ScalePercent(25f);

                #region "Construimos el encabezado y Detalles del documento"
                //Encabezado Folio Fiscal
                Table encabezadoFolio = new Table(3);
                float[] headerEncabezadoFolio = { 60, 10, 30 };
                encabezadoFolio.Widths = headerEncabezadoFolio;
                encabezadoFolio.WidthPercentage = 100F;
                encabezadoFolio.Padding = 1;
                encabezadoFolio.Spacing = 1;
                encabezadoFolio.BorderWidth = 0;
                encabezadoFolio.DefaultCellBorder = 0;
                encabezadoFolio.BorderColor = gris;

                cel = new Cell(imgFx);
                cel.HorizontalAlignment = Element.ALIGN_LEFT;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                encabezadoFolio.AddCell(cel);

                cel = new Cell(new Phrase("Folio Fiscal", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoFolio.AddCell(cel);

                cel = new Cell(new Phrase(htDatosCfdi["folioFiscal"].ToString().ToUpper(), f6));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 1;
                cel.BorderWidthLeft = 1;
                cel.BorderWidthRight = 1;
                cel.BorderWidthBottom = 1;
                cel.BorderColor = azul;
                encabezadoFolio.AddCell(cel);

                //Encabezado Comprobante
                Table encabezadoComprobante = new Table(6);
                float[] headerEncabezadoComprobante = { 30,40,5,5,10,10 };
                encabezadoComprobante.Widths = headerEncabezadoComprobante;
                encabezadoComprobante.WidthPercentage = 100F;
                encabezadoComprobante.Padding = 1;
                encabezadoComprobante.Spacing = 1;
                encabezadoComprobante.BorderWidth = 0;
                encabezadoComprobante.DefaultCellBorder = 0;
                encabezadoComprobante.BorderColor = gris;

                //LOGO DELA EMPRESA
                cel = new Cell(imgLogo);
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = 0;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 4;
                //cel.Colspan = 2;
                encabezadoComprobante.AddCell(cel);

                //EMISOR
                StringBuilder emisor = new StringBuilder();
                emisor.
                    Append("RFC: ").
                    Append(htDatosCfdi["rfcEmisor"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["nombreEmisor"]).Append("\n").
                    Append(htDatosCfdi["direccionEmisor1"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["direccionEmisor2"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["direccionEmisor3"].ToString().ToUpper()).Append("\n");

                cel = new Cell(new Phrase(emisor.ToString(), f6));
                cel.VerticalAlignment = Element.ALIGN_RIGHT;
                cel.BorderColor = gris;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = 0;
                cel.Rowspan = 4;
                cel.Colspan = 3;
                encabezadoComprobante.AddCell(cel);

                // Serie
                cel = new Cell(new Phrase("Serie", 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;
                encabezadoComprobante.AddCell(cel);

                // Folio
                cel = new Cell(new Phrase("Folio", 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;
                encabezadoComprobante.AddCell(cel);

                cel = new Cell(new Phrase(htDatosCfdi["serie"].ToString(), 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;
                encabezadoComprobante.AddCell(cel);

                cel = new Cell(new Phrase(htDatosCfdi["folio"].ToString(), 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;
                encabezadoComprobante.AddCell(cel);

                // Fecha de emisión del comprobante
                cel = new Cell(new Phrase("Fecha", titulo));
                cel.VerticalAlignment = Element.ALIGN_MIDDLE;
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BackgroundColor = azul;
                cel.BorderWidthTop = 0;
                cel.BorderWidthLeft = 0;
                cel.BorderWidthRight = (float).5;
                cel.BorderWidthBottom = (float).5;
                cel.BorderColor = gris;
                cel.Colspan = 2;
                encabezadoComprobante.AddCell(cel);

                cel = new Cell(new Phrase(htDatosCfdi["fechaFactura"].ToString(), 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;
                cel.Colspan = 2;
                encabezadoComprobante.AddCell(cel);

                Table encabezadoComprobante1 = new Table(2);
                float[] headerEncabezadoComprobante1 = { 50, 50 };
                encabezadoComprobante1.Widths = headerEncabezadoComprobante1;
                encabezadoComprobante1.WidthPercentage = 100F;
                encabezadoComprobante1.Padding = 1;
                encabezadoComprobante1.Spacing = 1;
                encabezadoComprobante1.BorderWidth = 0;
                encabezadoComprobante1.DefaultCellBorder = 0;
                encabezadoComprobante1.BorderColor = gris;

                //Datos discales del cliente
                cel = new Cell(new Phrase("Datos Fiscales del Cliente", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoComprobante1.AddCell(cel);

                //Expedido en:
                cel = new Cell(new Phrase("Expedido en:", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoComprobante1.AddCell(cel);

                //Receptor
                StringBuilder cliente = new StringBuilder();
                cliente.
                    Append("\nRFC: ").
                    Append(htDatosCfdi["rfcCliente"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["cliente"]).Append("\n").
                    Append(htDatosCfdi["direccionCliente1"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["direccionCliente2"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["direccionCliente3"].ToString().ToUpper()).Append("\n").
                    Append("\n");

                cel = new Cell(new Phrase(cliente.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;
                encabezadoComprobante1.AddCell(cel);

                //Expedido en:
                StringBuilder expedido = new StringBuilder();
                expedido.
                    //Append(htDatosCfdi["sucursal"]).Append("\n").
                    Append(htDatosCfdi["direccionExpedido1"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["direccionExpedido2"].ToString().ToUpper()).Append("\n").
                    Append(htDatosCfdi["direccionExpedido3"].ToString().ToUpper()).Append("\n").
                    Append("\n");

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

                #endregion

                sol.encabezado = encabezado;
                sol.dSaltoLinea = dSaltoLinea;

                #region "Tabla Detalle"

                Table encabezadoDetalle = new Table(6);
                float[] headerEncabezadoDetalle = { 7, 8, 11, 52, 13, 13 };
                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("Cantidad", titulo));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Còdigo de Barras
                cel = new Cell(new Phrase("Unidad", titulo));
                cel.HorizontalAlignment = Element.ALIGN_RIGHT;
                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.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Descripción
                cel = new Cell(new Phrase("Descripción", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                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.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Importe
                cel = new Cell(new Phrase("Importe", titulo));
                cel.HorizontalAlignment = Element.ALIGN_CENTER;
                cel.BorderColor = gris;
                cel.BackgroundColor = azul;
                encabezadoDetalle.AddCell(cel);

                // Creamos la tabla para insertar los conceptos de detalle de la factura
                PdfPTable tableConceptos = new PdfPTable(6);

                int[] colWithsConceptos = new int[6];
                //String[] arrColWidthConceptos = dtConfigFact.Rows[0]["conceptosColWidth"].ToString().Split(new Char[] { ',' });
                String[] arrColWidthConceptos = { "12", "8", "15", "51", "13", "17" };

                for (int i = 0; i < arrColWidthConceptos.Length; i++)
                {
                    colWithsConceptos.SetValue(Convert.ToInt32(arrColWidthConceptos[i]), i);
                }

                tableConceptos.SetWidths(colWithsConceptos);
                tableConceptos.WidthPercentage = 100F;

                int numConceptos = electronicDocument.Data.Conceptos.Count;
                PdfPCell cellConceptos = new PdfPCell();
                PdfPCell cellMontos = new PdfPCell();

                for (int i = 0; i < numConceptos; i++)
                {
                    cellConceptos = new PdfPCell(new Phrase("         "+ electronicDocument.Data.Conceptos[i].Cantidad.Value.ToString(), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT;
                    tableConceptos.AddCell(cellConceptos);

                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Unidad.Value, new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    cellConceptos.HorizontalAlignment = PdfCell.ALIGN_LEFT;
                    tableConceptos.AddCell(cellConceptos);

                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].NumeroIdentificacion.Value, new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    cellConceptos.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                    tableConceptos.AddCell(cellConceptos);

                    cellConceptos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Descripcion.Value, new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellConceptos.Border = 0;
                    tableConceptos.AddCell(cellConceptos);

                    cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].ValorUnitario.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellMontos.Border = 0;
                    cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT;
                    tableConceptos.AddCell(cellMontos);

                    cellMontos = new PdfPCell(new Phrase(electronicDocument.Data.Conceptos[i].Importe.Value.ToString("C", _ci), new Font(Font.HELVETICA, 7, Font.NORMAL)));
                    cellMontos.Border = 0;
                    cellMontos.HorizontalAlignment = PdfCell.ALIGN_RIGHT;
                    tableConceptos.AddCell(cellMontos);
                }
                dSaltoLinea = new Chunk("\n\n ");

                #endregion

                #region "Construimos el Comentarios"

                Table comentarios = new Table(7);
                float[] headerwidthsComentarios = { 18, 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("C", _c2), 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(dtOpcEncabezado.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 = 3;
                comentarios.AddCell(cel);

                cel = new Cell(new Phrase(dtConfigFact.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 = 3;
                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(electronicDocument.Data.Descuento.Value.ToString("C", _c2), 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.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("C", _c2), 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", _c2), 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);

                #endregion

                #region "Construimos Tabla 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.ToUpper(), 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);

                    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;
                    string regimenes = "";
                    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 + "   |   ", f5));
                    par.Add(new Chunk("MÉTODO DE PAGO: ", f5L));
                    par.Add(new Chunk(electronicDocument.Data.MetodoPago.Value, f5));

                    if (electronicDocument.Data.Emisor.Regimenes.Count > 0)
                    {
                        for (int u = 0; u < electronicDocument.Data.Emisor.Regimenes.Count; u++)
                            regimenes += electronicDocument.Data.Emisor.Regimenes[u].Regimen.Value.ToString() + ",";

                        par.Add(new Chunk("   |   ", f5));
                        par.Add(new Chunk("RÉGIMEN FISCAL: ", f5L));
                        par.Add(new Chunk(regimenes.Substring(0, regimenes.Length - 1).ToString(), f5));
                        par.Add(new Chunk("   |   ", f5));
                    }

                    if (electronicDocument.Data.CondicionesPago.Value.ToString().Length > 0)
                    {
                        par.Add(new Chunk("   |   ", f5));
                        par.Add(new Chunk("CONDICIONES DE PAGO: ", f5L));
                        par.Add(new Chunk(electronicDocument.Data.CondicionesPago.Value.ToString(), f5));
                        par.Add(new Chunk("   |   ", f5));
                    }

                    if (electronicDocument.Data.NumeroCuentaPago.Value.ToString().Length > 0)
                    {
                        par.Add(new Chunk("   |   ", f5));
                        par.Add(new Chunk("No. CUENTA: ", f5L));
                        par.Add(new Chunk(electronicDocument.Data.NumeroCuentaPago.Value, f5));
                        par.Add(new Chunk("   |   ", 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);

                    if (electronicDocument.Data.LugarExpedicion.Value.Length > 0)
                    {
                        par = new Paragraph();
                        par.SetLeading(7f, 0f);
                        par.Add(new Chunk("LUGAR EXPEDICIÓN: ", f5L));
                        par.Add(new Chunk(electronicDocument.Data.LugarExpedicion.Value, f5));
                        cel = new Cell(par);
                        cel.BorderColor = gris;
                        cel.BorderWidthTop = (float).5;
                        cel.BorderWidthRight = 0;
                        cel.BorderWidthLeft = 0;
                        cel.BorderWidthBottom = 0;
                        cel.Colspan = 3;
                        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

                sol.encFolioFiscal = encabezadoFolio;
                sol.encComprobante = encabezadoComprobante;
                sol.encComprobante1 = encabezadoComprobante1;
                sol.encTitulos = encabezadoDetalle;
                sol.adicional = adicional;
                sol.footer = footer;

                document.Open();

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

                string filePdfExt = pathPdf.Replace(_rutaDocs, _rutaDocsExt);
                string urlPathFilePdf = filePdfExt.Replace(@"\", "/");
                document.Close();
                writer.Close();
                fs.Close();

                //Subimos Archivo al Azure
                string res = App_Code.com.Facturaxion.facturaEspecial.wAzure.azureUpDownLoad(1, pathPdf);

                return "1#" + urlPathFilePdf;
            }
            catch (Exception ex)
            {
                fs.Flush();
                fs.Close();
                File.Delete(pathPdf);

                return "0#" + ex.Message;
            }
        }
        // 函数描述:对表格内容进行格式化----
        public static PdfPCell InsertTableContent(string text)
        {
            var font = BaseFontAndSize("宋体", 10, Font.NORMAL);
            var paragraph1 = new Paragraph(" ", font);
            paragraph1.SetLeading(1, 1);
            var paragraph = new Paragraph(text, font)
                {
                    FirstLineIndent = 24,
                    IndentationLeft = 20,
                    IndentationRight = 20,
                    SpacingBefore = 1,
                    SpacingAfter = 1
                };
            paragraph.SetLeading(1, 1.5f);
            paragraph.Alignment = Element.ALIGN_LEFT;

            var pdfPCell = new PdfPCell();
            pdfPCell.AddElement(paragraph1);
            pdfPCell.AddElement(paragraph1);
            pdfPCell.AddElement(paragraph);
            pdfPCell.Padding = 1;
            pdfPCell.SetLeading(1, 1);
            pdfPCell.BorderWidth=0;

            return pdfPCell;
        }