Exemple #1
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            var doc = new Document(PageSize.A4);

            using (System.IO.MemoryStream outputPdfStream = new System.IO.MemoryStream())
            {
                var writer = PdfWriter.GetInstance(doc, outputPdfStream);
                doc.Open();
                int       tableColumns = 5;
                PdfPTable aTable       = new PdfPTable(tableColumns);
                aTable.SetWidthPercentage(new[] { 100f, 100f, 100f, 100f, 100f }, PageSize.A4);
                for (int i = 0; i < 36; i++)
                {
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                }
                doc.Add(aTable);
                doc.Close();
                Response.Clear();
                Response.AddHeader("content-disposition", "inline;filename=Empty.pdf");
                Response.ContentType = "application/pdf";
                Response.BinaryWrite(outputPdfStream.ToArray());
                Response.End();
            }
        }
Exemple #2
0
        /// <summary>
        /// Recebe os textos e aplica as formatações para a inclusão do grupo
        /// </summary>
        /// <param name="Campo1">Nome do grupo</param>
        /// <param name="Campo2"> valor do grupo</param>
        /// <returns>texto formatado para ser incluído no documento pdf</returns>
        private PdfPTable AddGrupo(string Campo1, string Campo2)
        {
            PdfPTable tabelaG = new PdfPTable(2);

            try
            {
                PdfPCell celulaG = new PdfPCell();
                celulaG.BackgroundColor = BaseColor.BLACK;
                celulaG.BorderColor     = BaseColor.WHITE;

                Font FCabeca = FontFactory.GetFont("Verdana", 11, BaseColor.WHITE);
                celulaG.Phrase = new Phrase(Campo1, FCabeca);
                tabelaG.AddCell(celulaG);

                celulaG.Phrase = new Phrase(Campo2, FCabeca);
                tabelaG.AddCell(celulaG);
                float[] flutuante = new float[2] {
                    238f, 357f
                };
                tabelaG.SetWidthPercentage(flutuante, PageSize.A4);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Um erro ocorreu com este projeto. Entre em contato com seu desenvolvedor informando o erro: \r\n" +
                                Ex.Message);
            }

            return(tabelaG);
        }
Exemple #3
0
    private void Creo_Cabecera(iTextSharp.text.pdf.PdfWriter writer, iTextSharp.text.Document document)
    {
        PdfPTable t = new PdfPTable(2);

        Single[] arrAnchosC = { 20F, 80F };
        t.SetWidthPercentage(arrAnchosC, iTextSharpText.PageSize.A4);
        t.WidthPercentage = 100;

        iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance(AppDomain.CurrentDomain.BaseDirectory + "App_Themes\\imagenes\\logo_impresion.png");
        PdfPCell c = new PdfPCell(png);

        c.HorizontalAlignment = iTextSharpText.Element.ALIGN_LEFT;
        c.BorderWidth         = 0;

        iTextSharpText.Phrase texto = new iTextSharpText.Phrase();
        texto.Font = iTextSharpText.FontFactory.GetFont("Arial", 14, iTextSharpText.Element.ALIGN_CENTER);
        texto.Add(new iTextSharpText.Phrase("Reporte de Solicitudes de Prestamos a Liquidar\n\n"));

        texto.Font = iTextSharpText.FontFactory.GetFont("Arial", 8, iTextSharpText.Element.ALIGN_CENTER);
        texto.Add(new iTextSharpText.Phrase("Fecha Reporte: " + lst[0].Fecha_Informe.ToString("dd/MM/yyyy") + "   N° Reporte: " + lst[0].nroInforme));

        PdfPCell c1 = new PdfPCell(texto);

        c1.HorizontalAlignment = iTextSharpText.Element.ALIGN_CENTER;
        c1.BorderWidth         = 0;

        t.AddCell(c);
        t.AddCell(c1);

        iTextSharpText.Paragraph Cabecera = new iTextSharpText.Paragraph();
        Cabecera.Add(t);

        document.Add(Cabecera);
        document.Add(iTextSharpText.Chunk.NEWLINE);
    }
Exemple #4
0
        /// <summary>
        /// Recebe os textos e aplica as formatações para a inclusão do subgrupo
        /// </summary>
        /// <param name="Campo1">Nome do grupo</param>
        /// <param name="Campo2">valor do subgrupo</param>
        /// <returns>texto formatado para ser incluído no documento pdf</returns>
        private PdfPTable AddSubgrupo(string Campo1, string Campo2)
        {
            float[] flutuante = new float[2] {
                238f, 357f
            };
            PdfPTable tabelaS = new PdfPTable(flutuante);

            try
            {
                PdfPCell celulaS = new PdfPCell();
                //celulaS.Width = 20;
                celulaS.BackgroundColor = BaseColor.LIGHT_GRAY;
                celulaS.BorderColor     = BaseColor.WHITE;

                celulaS.Phrase = new Phrase(Campo1);
                celulaS.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                tabelaS.AddCell(celulaS);

                celulaS.Phrase = new Phrase(Campo2);
                celulaS.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
                tabelaS.AddCell(celulaS);
                tabelaS.SetWidthPercentage(flutuante, PageSize.A4);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Um erro ocorreu com este projeto. Entre em contato com seu desenvolvedor informando o erro: \r\n" +
                                Ex.Message);
            }
            return(tabelaS);
        }
Exemple #5
0
        void pdf()
        {
            try
            {
                SaveFileDialog h = new SaveFileDialog();
                h.Filter   = "Pdf(*.pdf)|*.pdf";
                h.FileName = "pdf";
                if (h.ShowDialog() == DialogResult.OK)
                {
                    Document  doc = new Document(PageSize.LETTER);
                    PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream(h.FileName, FileMode.Create));
                    doc.Open();



                    doc.Add(new Paragraph(" "));
                    PdfPTable c = new PdfPTable(dataGridView1.Columns.Count);
                    doc.Add(c);
                    var chartimage = new MemoryStream();
                    chart1.SaveImage(chartimage, ChartImageFormat.Png);
                    iTextSharp.text.Image Chart_image = iTextSharp.text.Image.GetInstance(chartimage.GetBuffer());
                    doc.Add(Chart_image);


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

                    PdfPTable table = new PdfPTable(dataGridView1.Columns.Count);

                    for (int j = 0; j < dataGridView1.Columns.Count; j++)
                    {
                        table.AddCell(new Phrase(dataGridView1.Columns[j].HeaderText));
                        table.SetWidthPercentage(new float[] { 40, 80 }, PageSize.LETTER);
                    }

                    table.HeaderRows = 1;
                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        for (int k = 0; k < dataGridView1.Columns.Count; k++)
                        {
                            if (dataGridView1[k, i].Value != null)
                            {
                                table.AddCell(new Phrase(dataGridView1[k, i].Value.ToString()));
                            }
                        }
                    }

                    doc.Add(table);

                    doc.Add(new Paragraph(" "));
                    Paragraph pie = new Paragraph("¡GRACIAS POR CONSULTAR!", FontFactory.GetFont("Arial", 9, iTextSharp.text.Font.BOLD));
                    pie.Alignment = Element.ALIGN_CENTER;
                    doc.Add(pie);
                    doc.Close();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error al exportar la informacion debido a: " + e.ToString());
            }
        }
        public bool CreateReport(DataView theData)
        {
            bool isSuccessful = false;
            var  document     = new iTextSharp.text.Document(PageSize.HALFLETTER.Rotate());

            try
            {
                //set up RunReport event overrides & create doc
                PartialPaymentDetailReport events = this;

                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(reportTempFileFullName, FileMode.Create));
                writer.PageEvent = events;

                //set up tables, etc...
                var   table = new PdfPTable(10);
                var   cell  = new PdfPCell();
                Image gif   = Image.GetInstance(Resources.logo, BaseColor.WHITE);

                _reportFont          = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL);
                _reportFontLargeBold = FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD);

                gif.ScalePercent(35);

                document.SetPageSize(PageSize.HALFLETTER.Rotate());
                document.SetMargins(5, 5, 10, 45);
                document.AddTitle(_title + ": " + DateTime.Now.ToString("MM/dd/yyyy"));

                ReportHeader(table, gif);

                CustomerData(table, theData);
                PartialPaymentData(table, theData);
                table.SetWidthPercentage(new float[]
                {
                    50F, 100F, 20F, 70F, 90F, 50F, 50F, 50F, 70F, 70F
                }, PageSize.HALFLETTER.Rotate());

                ReportDetailHeader(table);

                ReportDetail(table, theData);

                ReportLines(table, true, string.Empty, true, _reportFont);
                document.Open();
                document.Add(table);
                document.Close();

                isSuccessful = true;
            }
            catch (DocumentException de)
            {
                ReportError      = de.Message;
                ReportErrorLevel = (int)LogLevel.ERROR;
            }
            catch (IOException ioe)
            {
                ReportError      = ioe.Message;
                ReportErrorLevel = (int)LogLevel.ERROR;
            }

            return(isSuccessful);
        }
Exemple #7
0
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            base.OnStartPage(writer, document);

            var       contentByte = writer.DirectContent;
            Rectangle pageSize    = document.PageSize;

            var header = new PdfPTable(2);

            header.TotalWidth = pageSize.Width - document.LeftMargin - document.RightMargin;
            header.SetWidthPercentage(new float[] { 20, 80 }, pageSize);

            var logoCell = new PdfPCell(HeaderLogo, true);

            logoCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            logoCell.Border = Rectangle.NO_BORDER;
            header.AddCell(logoCell);

            var headerText = new PdfPCell(new Phrase(5, HeaderText, HeaderFont));

            headerText.HorizontalAlignment = Element.ALIGN_LEFT;
            headerText.VerticalAlignment   = Element.ALIGN_BOTTOM;
            headerText.Border = Rectangle.NO_BORDER;
            header.AddCell(headerText);

            contentByte.SetRGBColorFill(0, 0, 0);
            header.WriteSelectedRows(0, -1, pageSize.GetLeft(document.LeftMargin), pageSize.GetTop(40), contentByte);
        }
Exemple #8
0
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            base.OnStartPage(writer, document);
            Rectangle pageSize = document.PageSize;

            if (Title != string.Empty)
            {
                cb.BeginText();
                cb.SetFontAndSize(bf, 15);
                cb.SetRGBColorFill(50, 50, 200);
                cb.SetTextMatrix(pageSize.GetLeft(40), pageSize.GetTop(40));
                cb.ShowText(Title);
                cb.EndText();
            }
            if (HeaderLeft + HeaderRight != string.Empty)
            {
                PdfPTable HeaderTable = new PdfPTable(2);
                HeaderTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                HeaderTable.TotalWidth = pageSize.Width - 80;
                HeaderTable.SetWidthPercentage(new float[] { 45, 45 }, pageSize);
                PdfPCell HeaderLeftCell = new PdfPCell(new Phrase(8, HeaderLeft, HeaderFont));
                HeaderLeftCell.Padding          = 5;
                HeaderLeftCell.PaddingBottom    = 8;
                HeaderLeftCell.BorderWidthRight = 0;
                HeaderTable.AddCell(HeaderLeftCell);
                PdfPCell HeaderRightCell = new PdfPCell(new Phrase(8, HeaderRight, HeaderFont));
                HeaderRightCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                HeaderRightCell.Padding             = 5;
                HeaderRightCell.PaddingBottom       = 8;
                HeaderRightCell.BorderWidthLeft     = 0;
                HeaderTable.AddCell(HeaderRightCell);
                cb.SetRGBColorFill(0, 0, 0);
                HeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(40), pageSize.GetTop(50), cb);
            }
        }
            public async Task <Stream> Handle(Consulta request, CancellationToken cancellationToken)
            {
                Font fuenteTitulo = new Font(Font.HELVETICA, 8f, Font.BOLD, BaseColor.Blue);
                Font fuenteHeader = new Font(Font.HELVETICA, 7f, Font.BOLD, BaseColor.Black);
                Font fuenteData   = new Font(Font.HELVETICA, 7f, Font.NORMAL, BaseColor.Black);

                var cursos = await _context.Curso.ToListAsync();

                MemoryStream workStream = new MemoryStream();
                Rectangle    rect       = new Rectangle(PageSize.A4);

                Document  document = new Document(rect, 20, 0, 50, 100);
                PdfWriter writer   = PdfWriter.GetInstance(document, workStream);

                writer.CloseStream = false;

                document.Open();
                document.AddTitle("Lista de cursos");

                PdfPTable tabla = new PdfPTable(1);

                tabla.WidthPercentage = 90;
                PdfPCell celda = new PdfPCell(new Phrase("Lista de cursos", fuenteTitulo));

                celda.Border = Rectangle.NO_BORDER;
                tabla.AddCell(celda);
                document.Add(tabla);

                PdfPTable tablaCursos = new PdfPTable(2);

                float[] widths = new float[] { 40, 60 };
                tablaCursos.SetWidthPercentage(widths, rect);

                PdfPCell celdaHeaderTitulo = new PdfPCell(new Phrase("Curso", fuenteHeader));

                tablaCursos.AddCell(celdaHeaderTitulo);

                PdfPCell celdaHeaderDescripcion = new PdfPCell(new Phrase("Descripcion", fuenteHeader));

                tablaCursos.AddCell(celdaHeaderDescripcion);
                tablaCursos.WidthPercentage = 90;

                foreach (var cursoElemento in cursos)
                {
                    PdfPCell celdaDataTitulo = new PdfPCell(new Phrase(cursoElemento.Titulo, fuenteData));
                    tablaCursos.AddCell(celdaDataTitulo);

                    PdfPCell celdaDataDescripcion = new PdfPCell(new Phrase(cursoElemento.Descripcion, fuenteData));
                    tablaCursos.AddCell(celdaDataDescripcion);
                }

                document.Add(tablaCursos);
                document.Close();

                byte[] byteData = workStream.ToArray();
                workStream.Write(byteData, 0, byteData.Length);
                workStream.Position = 0;
                return(workStream);
            }
        public bool CreateReport(System.Data.DataSet theData)
        {
            bool isSuccessful = false;

            iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.LETTER.Rotate());

            try
            {
                //set up RunReport event overrides & create doc
                LoanListingReport events = this;

                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(reportTempFileFullName, FileMode.Create));
                writer.PageEvent = events;

                //set up tables, etc...
                PdfPTable table = new PdfPTable(18);
                PdfPCell  cell  = new PdfPCell();
                Image     gif   = Image.GetInstance(Resources.logo, BaseColor.WHITE);

                _reportFont          = FontFactory.GetFont("Arial", 8, iTextSharp.text.Font.NORMAL);
                _reportFontLargeBold = FontFactory.GetFont("Arial", 10, iTextSharp.text.Font.BOLD);

                gif.ScalePercent(35);

                document.SetPageSize(PageSize.LETTER.Rotate());
                document.SetMargins(20, 20, 10, 45);
                document.AddTitle("Loan Inquiry Listing Report : " + DateTime.Now.ToString("MM/dd/yyyy"));

                ReportHeader(table, gif);
                ColumnHeaders(table);

                table.SetWidthPercentage(new float[] { 35F, 45F, 45F, 45F, 75F, 40F, 45F, 55F, 40F, 55F, 45F, 45F, 40F, 50F, 25F, 25F, 25F, 25F },
                                         PageSize.LETTER.Rotate());

                table.HeaderRows = 8;

                ReportDetail(table, theData);
                ReportLines(table, true, "", true, _reportFont);

                document.Open();
                document.Add(table);
                document.Close();

                isSuccessful = true;
            }
            catch (DocumentException de)
            {
                ReportError      = de.Message;
                ReportErrorLevel = (int)LogLevel.ERROR;
            }
            catch (IOException ioe)
            {
                ReportError      = ioe.Message;
                ReportErrorLevel = (int)LogLevel.ERROR;
            }

            return(isSuccessful);
        }
Exemple #11
0
        /// <summary>
        /// Creates the table with the basic information.
        /// </summary>
        /// <returns>The created table.</returns>
        public PdfPTable CreateRallyLengthTable()
        {
            PdfPTable table = new PdfPTable(10);

            float[]   widths = new float[] { 1.8f, 2.3f, 1.1f, 1.1f, 1.1f, 1.1f, 2.1f, 2.1f, 2.1f, 2.1f };
            Rectangle rect   = new Rectangle(17, 1);

            table.SetWidthPercentage(widths, rect);

            PdfPCell cell1 = GetCell(string.Empty, 1, 1, 1);

            cell1.MinimumHeight = 30.0f;
            table.AddCell(cell1);
            table.AddCell(GetCell("Total Rally Length", 1, 1, 2));
            table.AddCell(GetCell("Serv A", 1, 1, 2));
            table.AddCell(GetCell("Serv B", 1, 1, 2));
            table.AddCell(GetCell("Win A", 1, 1, 2));
            table.AddCell(GetCell("Win B", 1, 1, 2));
            table.AddCell(GetCell("Service A\nWinner A", 1, 1, 2));
            table.AddCell(GetCell("Service A\nWinner B", 1, 1, 2));
            table.AddCell(GetCell("Service B\nWinner A", 1, 1, 2));
            table.AddCell(GetCell("Service B\nWinner B", 1, 1, 3));

            RallyLengthStatistics stats = this.report.RallyLength;

            PdfPCell cell2 = GetCell("Mean", 4);

            cell2.MinimumHeight = 20.0f;
            table.AddCell(cell2);
            table.AddCell(GetCell(Convert.ToString(0), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.ServiceA.Mean, 2)), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.ServiceB.Mean, 2)), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.WinnerA.Mean, 2)), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.WinnerB.Mean, 2)), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.WinnerAWithServiceA.Mean, 2)), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.WinnerBWithServiceA.Mean, 2)), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.WinnerAWithServiceB.Mean, 2)), 5));
            table.AddCell(GetCell(Convert.ToString(Math.Round(stats.WinnerBWithServiceB.Mean, 2)), 5));

            PdfPCell cell3 = GetCell("Median", 4);

            cell3.MinimumHeight = 20.0f;
            table.AddCell(cell3);
            table.AddCell(GetCell(Convert.ToString(0), 5));
            table.AddCell(GetCell(Convert.ToString(stats.ServiceA.Median), 5));
            table.AddCell(GetCell(Convert.ToString(stats.ServiceB.Median), 5));
            table.AddCell(GetCell(Convert.ToString(stats.WinnerA.Median), 5));
            table.AddCell(GetCell(Convert.ToString(stats.WinnerB.Median), 5));
            table.AddCell(GetCell(Convert.ToString(stats.WinnerAWithServiceA.Median), 5));
            table.AddCell(GetCell(Convert.ToString(stats.WinnerBWithServiceA.Median), 5));
            table.AddCell(GetCell(Convert.ToString(stats.WinnerAWithServiceB.Median), 5));
            table.AddCell(GetCell(Convert.ToString(stats.WinnerBWithServiceB.Median), 5));

            return(table);
        }
Exemple #12
0
    public override void OnStartPage(PdfWriter writer, Document document)
    {
        base.OnStartPage(writer, document);
        var  pageSize   = document.PageSize;
        Font fontNormal = new Font(bf, 7, Font.NORMAL);
        Font fontH3     = new Font(bf, 13, Font.NORMAL);
        Font fontH1     = new Font(bf, 15, Font.BOLD);

        var table = new PdfPTable(3)
        {
            TotalWidth  = pageSize.Width - 80,
            LockedWidth = true
        };

        table.SetWidthPercentage(new float[] { (float)(table.TotalWidth * 0.25), (float)(table.TotalWidth * 0.40), (float)(table.TotalWidth * 0.35) }, pageSize);

        var nested = new PdfPTable(1);

        PdfPCell nesthousing = new PdfPCell(nested);

        nesthousing.Border        = 0;
        nesthousing.Padding       = 0f;
        nesthousing.PaddingBottom = 20f;
        table.AddCell(nesthousing);

        var tcell = new PdfPCell(new Phrase(Title, fontH1));

        tcell.Border = 0;
        tcell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
        tcell.VerticalAlignment   = PdfPCell.ALIGN_BOTTOM;
        //tcell.PaddingBottom = 20f;
        table.AddCell(tcell);
        document.Add(table);
        if (jpg != null)
        {
            Paragraph paragraph = new Paragraph("");
            document.Add(jpg);
            document.Add(paragraph);
        }
        if (jpg2 != null)
        {
            Paragraph paragraph = new Paragraph("");
            document.Add(jpg2);
            document.Add(paragraph);
        }
        if (jpg3 != null)
        {
            Paragraph paragraph = new Paragraph("");
            document.Add(jpg3);
            document.Add(paragraph);
        }
    }
        //在pdf文件中每一页的末尾写入页脚
        public override void OnEndPage(PdfWriter writer, Document document)
        {
            base.OnEndPage(writer, document);
            var table = new PdfPTable(1);

            table.SetWidthPercentage(new float[] { 100f }, PageSize.LETTER);
            table.WidthPercentage    = 90f;
            table.DefaultCell.Border = 0;

            var cell = new PdfPCell(new Phrase("@ " + DateTime.Now.Year + ". Grand Channel Inc. All Rights Reserved."));

            cell.VerticalAlignment = Element.ALIGN_CENTER;
            table.AddCell(cell);
            table.WriteSelectedRows(0, -1, 0, document.Bottom, writer.DirectContent);
        }
Exemple #14
0
    public PdfPTable retornarTabla()
    {
        PdfPTable tablaBecarios = new PdfPTable(2);

        tablaBecarios.SetWidthPercentage(new float[] { 200, 200 }, PageSize.LETTER);
        tablaBecarios.AddCell(new Paragraph("Nombre"));
        tablaBecarios.AddCell(new Paragraph("Carnet"));
        //para darle formato a las columnas del nombre y carnet
        foreach (PdfPCell celda in tablaBecarios.Rows[0].GetCells())
        {
            celda.BackgroundColor     = BaseColor.LIGHT_GRAY;
            celda.HorizontalAlignment = 1;
            celda.Padding             = 3;
            celda.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
        }
        return(tablaBecarios);
    }
Exemple #15
0
        public void CreatePDF(string filename, ObservableCollection <Models.TableModelN> models)
        {
            PdfPTable pdfDoc = new PdfPTable(1);

            pdfDoc.DefaultCell.Border = 0;
            pdfDoc.SetWidthPercentage(new float[] { PageSize.A4.Width - 50 }, PageSize.A4);

            foreach (var i in models)
            {
                PdfPTable data = new PdfPTable(5);

                data.KeepTogether       = true;
                data.DefaultCell.Phrase = new Phrase {
                    Font = fontTxt
                };
                data.DefaultCell.Border = 2;
                data.SetWidths(width);

                data.AddCell(WriteData(i.Persons));
                data.AddCell(WriteData(i.School.Name + "\n" + i.Team.Class));

                data.AddCell(WriteData(i.Location.Name, Element.ALIGN_CENTER));
                data.AddCell(WriteData(i.Team.Date, Element.ALIGN_CENTER));
                data.AddCell(WriteData(i.Team.Time, Element.ALIGN_CENTER));

                pdfDoc.AddCell(data);
            }

            try
            {
                Document  doc    = new Document(PageSize.A4, 0f, 0f, 40f, 40f);
                var       fs     = new FileStream(filename, FileMode.Create);
                PdfWriter writer = PdfWriter.GetInstance(doc, fs);

                writer.PageEvent = this;

                doc.Open();
                doc.Add(pdfDoc);
                doc.Close();
            }
            catch (Exception)
            {
                Console.WriteLine("Error!");
            }
        }
Exemple #16
0
        /// <summary>
        /// Recebe os textos e aplica as formatações para a inclusão da classe e dos valores
        /// </summary>
        /// <param name="Campo1">Nome da classe</param>
        /// <param name="Campo2">Valor da classe (area)</param>
        /// <returns>texto formatado para ser incluído no documento pdf</returns>
        private PdfPTable AddClasse(string Campo1, string Campo2)
        {
            float[] flutuante = new float[3] {
                60f, 297f, 238f
            };
            PdfPTable tabelaCl = new PdfPTable(flutuante);

            try
            {
                PdfPCell celulaCl = new PdfPCell();
                celulaCl.BorderColor = BaseColor.WHITE;

                BaseColor Collor = new BaseColor(240, 255, 240);

                celulaCl.Phrase = new Phrase("");
                tabelaCl.AddCell(celulaCl);


                if (linhas)
                {
                    celulaCl.BackgroundColor = BaseColor.WHITE;
                    linhas = false;
                }
                else
                {
                    celulaCl.BackgroundColor = Collor;
                    linhas = true;
                }

                celulaCl.Phrase = new Phrase(Campo1);
                tabelaCl.AddCell(celulaCl);

                celulaCl.Phrase = new Phrase(Campo2);
                celulaCl.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                tabelaCl.AddCell(celulaCl);
                tabelaCl.SetWidthPercentage(flutuante, PageSize.A4);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Um erro ocorreu com este projeto. Entre em contato com seu desenvolvedor informando o erro: \r\n" +
                                Ex.Message);
            }

            return(tabelaCl);
        }
        //在PDF文件中每一页的右下角写入页码
        public void OnEndPageNumber(PdfWriter pw, Document doc, int currentPage, int pageCount)
        {
            var table = new PdfPTable(1);

            table.SetWidthPercentage(new float[] { 100f }, PageSize.LETTER);
            table.WidthPercentage = 90f;

            var footer = new Paragraph("Page " + currentPage.ToString() + "/" + pageCount.ToString());

            footer.Alignment = Element.ALIGN_RIGHT;
            var cell = new PdfPCell(footer);

            cell.HorizontalAlignment = 1;
            cell.Border = Rectangle.NO_BORDER;
            table.AddCell(cell);
            //doc.Add(table);
            table.WriteSelectedRows(0, -1, doc.Right - 100f, doc.Bottom, pw.DirectContent);
        }
Exemple #18
0
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            base.OnStartPage(writer, document);

            Rectangle pageSize = document.PageSize;

            pdfContentByte.BeginText();
            pdfContentByte.SetFontAndSize(BaseFont.CreateFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 15f);
            pdfContentByte.SetRGBColorFill(50, 50, 200);
            pdfContentByte.SetTextMatrix(pageSize.GetLeft(10), pageSize.GetTop(10));
            pdfContentByte.ShowText("This is the title I wrote on start page event.");
            pdfContentByte.EndText();

            PdfPTable pdfPTableHeaderTable = new PdfPTable(2);

            pdfPTableHeaderTable.TotalWidth = pageSize.Width - 80;
            pdfPTableHeaderTable.SetWidthPercentage(new float[] { 45, 45 }, pageSize);

            pdfPTableHeaderTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
            pdfPTableHeaderTable.DefaultCell.AddElement(new Phrase("Default cell text"));

            PdfPCell pdfPCellLeft = new PdfPCell(new Phrase(8, "Header on the left", new Font(Font.FontFamily.TIMES_ROMAN, 10f)));

            pdfPCellLeft.Padding       = 5;
            pdfPCellLeft.PaddingBottom = 8;
            // pdfPCellLeft.BorderWidthRight = 0;
            pdfPCellLeft.Border = 0;
            pdfPTableHeaderTable.AddCell(pdfPCellLeft);

            PdfPCell pdfCellRight = new PdfPCell(new Phrase(8, "Header on the right", new Font(Font.FontFamily.HELVETICA, 10f, 0, BaseColor.GREEN)));

            pdfCellRight.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
            pdfCellRight.Padding             = 5;
            pdfCellRight.PaddingBottom       = 8;
            // pdfCellRight.BorderWidthLeft = 0;
            pdfCellRight.Border = 0;
            pdfPTableHeaderTable.AddCell(pdfCellRight);

            pdfContentByte.SetRGBColorFill(0, 0, 100);
            pdfContentByte.SetRGBColorStroke(200, 100, 9);

            pdfPTableHeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(40), pageSize.GetTop(50), pdfContentByte);
        }
Exemple #19
0
        void PrintHeader(Document document)
        {
            var headerTable = new PdfPTable(3);

            headerTable.SetWidthPercentage(new float[] { 20, 60, 20 }, document.PageSize);

            headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
            headerTable.TotalWidth         = document.PageSize.Width - document.LeftMargin - document.RightMargin;

            var headerLeftCell = new PdfPCell(new Phrase(8, headerLeft, font));

            headerLeftCell.Border = Rectangle.NO_BORDER;
            headerTable.AddCell(headerLeftCell);

            var headerCenterCell = new PdfPCell(new Phrase(8, header, font));

            headerCenterCell.HorizontalAlignment = Element.ALIGN_CENTER;
            headerCenterCell.Border = Rectangle.NO_BORDER;
            headerTable.AddCell(headerCenterCell);

            var headerRightCell = new PdfPCell(new Phrase(8, headerRight, font));

            headerRightCell.Border = Rectangle.NO_BORDER;
            headerRightCell.HorizontalAlignment = Element.ALIGN_RIGHT;
            headerTable.AddCell(headerRightCell);

            contentByte.MoveTo(
                document.PageSize.GetLeft(document.LeftMargin),
                document.PageSize.GetTop(document.TopMargin - 5 - (HasTitleAndSubjet ? 65 : 0))
                );
            contentByte.LineTo(
                document.PageSize.GetRight(document.RightMargin),
                document.PageSize.GetTop(document.TopMargin - 5 - (HasTitleAndSubjet ? 65 : 0))
                );
            contentByte.Stroke();

            headerTable.WriteSelectedRows(
                0, -1,
                document.PageSize.GetLeft(document.LeftMargin),
                document.PageSize.GetTop(document.TopMargin - 20 - (HasTitleAndSubjet ? 65 : 0)),
                contentByte
                );
        }
Exemple #20
0
// ---------------------------------------------------------------------------

        /**
         * Creates a table; widths are set with special setWidthPercentage() method.
         * @return a PdfPTable
         */
        public static PdfPTable CreateTable4()
        {
            PdfPTable table = new PdfPTable(3);
            Rectangle rect  = new Rectangle(523, 770);

            table.SetWidthPercentage(new float[] { 144, 72, 72 }, rect);
            PdfPCell cell;

            cell         = new PdfPCell(new Phrase("Table 4"));
            cell.Colspan = 3;
            table.AddCell(cell);
            cell         = new PdfPCell(new Phrase("Cell with rowspan 2"));
            cell.Rowspan = 2;
            table.AddCell(cell);
            table.AddCell("row 1; cell 1");
            table.AddCell("row 1; cell 2");
            table.AddCell("row 2; cell 1");
            table.AddCell("row 2; cell 2");
            return(table);
        }
        private void AttachTableFoot(Rectangle size, BaseFont font, PdfContentByte cb, IList <FBABOLDetail> list, float xPosition, float yPosition)
        {
            var tableFoot = new PdfPTable(7);

            float[] columnWidth = { 30f, 14f, 14f, 10f, 10f, 10f, 12f };
            tableFoot.SetWidthPercentage(columnWidth, size);
            tableFoot.TotalWidth = 521.3f;

            //表脚部分

            AddNewCell(tableFoot, "Grand Total", 10f, font);
            AddNewCell(tableFoot, " ", 10f, font);
            AddNewCell(tableFoot, " ", 10f, font);
            AddNewCell(tableFoot, list.Sum(x => x.Weight).ToString(), 10f, font);
            AddNewCell(tableFoot, list.Sum(x => x.CartonQuantity).ToString(), 10f, font);
            AddNewCell(tableFoot, list.Where(x => x.ActualPallets != 99999).Sum(x => x.ActualPallets).ToString(), 10f, font);
            AddNewCell(tableFoot, " ", 10f, font);

            tableFoot.WriteSelectedRows(0, -1, xPosition, yPosition, cb);
        }
Exemple #22
0
        /// <summary>
        /// Recebe os textos e aplica as formatações para a inclusão da linha título da classe
        /// </summary>
        /// <param name="Campo1">Nome do da classe</param>
        /// <param name="Campo2"> Indicação do valor da área e a unidade de medida discriminada</param>
        /// <returns>texto formatado para ser incluído no documento pdf</returns>
        private PdfPTable AddTClasse(string Campo1, string Campo2)
        {
            float[] flutuante = new float[3] {
                60f, 297f, 238f
            };
            PdfPTable tabelaCl = new PdfPTable(flutuante);

            try
            {
                PdfPCell celulaCl = new PdfPCell();
                celulaCl.BorderColor       = BaseColor.WHITE;
                celulaCl.VerticalAlignment = Element.ALIGN_TOP;


                celulaCl.Phrase = new Phrase("");
                tabelaCl.AddCell(celulaCl);

                celulaCl.BorderColorBottom = BaseColor.BLACK;
                celulaCl.BorderColorTop    = BaseColor.BLACK;
                celulaCl.BorderWidthBottom = 1f;
                celulaCl.BorderWidthTop    = 1f;
                celulaCl.Phrase            = new Phrase(Campo1);
                tabelaCl.AddCell(celulaCl);


                celulaCl.Phrase = new Phrase(Campo2);
                celulaCl.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                tabelaCl.SetWidthPercentage(flutuante, PageSize.A4);
                tabelaCl.AddCell(celulaCl);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Um erro ocorreu com este projeto. Entre em contato com seu desenvolvedor informando o erro: \r\n" +
                                Ex.Message);
            }

            return(tabelaCl);
        }
            public override void OnStartPage(PdfWriter writer, Document document)
            {
                base.OnStartPage(writer, document);

                iTextSharp.text.Rectangle pageSize = document.PageSize;

                if (HeaderRight != string.Empty)
                {
                    PdfPTable HeaderTable = new PdfPTable(2);
                    HeaderTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                    HeaderTable.TotalWidth = pageSize.Width - 10;
                    HeaderTable.SetWidthPercentage(new float[] { 45, 45 }, pageSize);

                    PdfPCell HeaderRightCell = new PdfPCell(new Phrase(8, HeaderRight, HeaderFont));
                    HeaderRightCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                    HeaderRightCell.Border  = 0;
                    HeaderRightCell.Colspan = 2;
                    HeaderTable.AddCell(HeaderRightCell);

                    cb.SetRGBColorFill(0, 0, 0);
                    HeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(0), pageSize.GetTop(10), cb);
                }
            }
Exemple #24
0
        private static PdfPTable createTable4()
        {
            var table = new PdfPTable(3);
            var rect  = new Rectangle(523, 770);

            table.SetWidthPercentage(new float[] { 144, 72, 72 }, rect);
            var cell = new PdfPCell(new Phrase("Table 4"))
            {
                Colspan = 3
            };

            table.AddCell(cell);
            cell = new PdfPCell(new Phrase("Cell with rowspan 2"))
            {
                Rowspan = 2
            };
            table.AddCell(cell);
            table.AddCell("row 1; cell 1");
            table.AddCell("row 1; cell 2");
            table.AddCell("row 2; cell 1");
            table.AddCell("row 2; cell 2");
            return(table);
        }
        public void CreatePdf(string HtmlName, string PdfName)
        {
            //PdfName = "sample.pdf";

            iTextSharp.text.Rectangle rect = PageSize.LETTER;
            iTextSharp.text.Document  doc  = new iTextSharp.text.Document(PageSize.A4);
            var output = new FileStream(PdfName, FileMode.Create);
            var writer = PdfWriter.GetInstance(doc, output);

            doc.Open();


            string          htmlContent = System.IO.File.ReadAllText(HtmlName);
            List <IElement> ie          = HTMLWorker.ParseToList(new StringReader(htmlContent), null);

            float pageWidth = rect.Width;

            foreach (IElement element in ie)
            {
                PdfPTable table = element as PdfPTable;

                if (table != null)
                {
                    table.SetWidthPercentage(
                        new float[] {
                        (float).25 * pageWidth,
                        (float).50 * pageWidth,
                        (float).25 * pageWidth
                    },
                        rect
                        );
                }
                doc.Add(element);
            }
            doc.Close();
        }
Exemple #26
0
        private MemoryStream GetDocumentStream()
        {
            var doc = new Document(PageSize.A4);

            using (System.IO.MemoryStream outputPdfStream = new System.IO.MemoryStream())
            {
                var writer = PdfWriter.GetInstance(doc, outputPdfStream);
                doc.Open();
                int       tableColumns = 5;
                PdfPTable aTable       = new PdfPTable(tableColumns);
                aTable.SetWidthPercentage(new[] { 100f, 100f, 100f, 100f, 100f }, PageSize.A4);
                for (int i = 0; i < 36; i++)
                {
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                    aTable.AddCell(GetBarcodeImage());
                }
                doc.Add(aTable);
                doc.Close();
                return(outputPdfStream);
            }
        }
Exemple #27
0
        protected void imgbtnPDF_OnClick(object sender, EventArgs e)
        {
            try
            {
                string text  = Session[ApplicationSession.OrganisationName].ToString();
                string text1 = Session[ApplicationSession.OrganisationAddress].ToString();
                string text2 = "Dryer Production Log Report";

                using (StringWriter sw = new StringWriter())
                {
                    using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                    {
                        StringBuilder sb = new StringBuilder();
                        sb.Append("<div align='center' style='font-size:16px;font-weight:bold;color:Black;'>");
                        sb.Append(text);
                        sb.Append("</div>");
                        sb.Append("<br/>");
                        sb.Append("<div align='center' style='font-size:13px;font-weight:bold;color:Black;'>");
                        sb.Append(text1);
                        sb.Append("</div>");
                        sb.Append("<br/>");
                        sb.Append("<div align='center' style='font-size:26px;color:Maroon;'><b>");
                        sb.Append(text2);
                        sb.Append("</b></div>");
                        sb.Append("<br/>");

                        string content = "<table style='display: table;width: 900px; clear:both;'> <tr> <th colspan='10' style='float: left;padding-left: 110px;'><div align='left'><strong>Start Date: </strong>" + txtFromDate.Text + "</div></th>";

                        content += "<th style='float:left; padding-left:-180px;'></th>";

                        content += "<th style='float:left; padding-left:-210px;'></th>";

                        content += "<th colspan='1' align='left' style=' float: left; padding-left:-200px;'><strong> End Date: </strong>" + //colspan='4'
                                   txtToDate.Text + "</th>" +
                                   "</tr></table>";
                        sb.Append(content);
                        sb.Append("<br/>");

                        PdfPTable pdfPTable = new PdfPTable(gvDryingProductionLog.HeaderRow.Cells.Count);

                        //TableCell headerCell = new TableCell();

                        PdfPCell headerCell = new PdfPCell(new Phrase("Sr"));
                        headerCell.Padding             = 5;
                        headerCell.BorderWidth         = 1.5f;
                        headerCell.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell);

                        PdfPCell headerCell1 = new PdfPCell(new Phrase("Date"));
                        headerCell1.Padding             = 5;
                        headerCell1.BorderWidth         = 1.5f;
                        headerCell1.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell1.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell1);

                        PdfPCell headerCell2 = new PdfPCell(new Phrase("Steam(Kg)"));
                        headerCell2.Padding             = 5;
                        headerCell2.BorderWidth         = 1.5f;
                        headerCell2.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell2.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell2);

                        PdfPCell headerCell3 = new PdfPCell(new Phrase("Power Dryer(KW)"));
                        headerCell3.Padding             = 5;
                        headerCell3.BorderWidth         = 1.5f;
                        headerCell3.HorizontalAlignment = Element.ALIGN_CENTER;
                        headerCell3.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        pdfPTable.AddCell(headerCell3);



                        float[] widthsTAS = { 180f, 180f, 180f, 180f };
                        pdfPTable.SetWidths(widthsTAS);

                        for (int i = 0; i < gvDryingProductionLog.Rows.Count; i++)
                        {
                            if (gvDryingProductionLog.Rows[i].RowType == DataControlRowType.DataRow)
                            {
                                for (int j = 0; j < gvDryingProductionLog.Columns.Count; j++)
                                {
                                    string cellText = Server.HtmlDecode(gvDryingProductionLog.Rows[i].Cells[j].Text);

                                    DateTime dDate;
                                    double   dbvalue;
                                    int      intvalue;

                                    if (DateTime.TryParse(cellText, out dDate))
                                    {
                                        PdfPCell CellTwoHdr = new PdfPCell(new Phrase(cellText));
                                        CellTwoHdr.HorizontalAlignment = Element.ALIGN_CENTER;
                                        CellTwoHdr.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                        CellTwoHdr.Padding             = 5;
                                        pdfPTable.AddCell(CellTwoHdr);
                                    }
                                    else if (double.TryParse(cellText, out dbvalue) || Int32.TryParse(cellText, out intvalue))
                                    {
                                        PdfPCell CellTwoHdr = new PdfPCell(new Phrase(cellText));
                                        CellTwoHdr.HorizontalAlignment = Element.ALIGN_CENTER;
                                        CellTwoHdr.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                        CellTwoHdr.Padding             = 5;
                                        pdfPTable.AddCell(CellTwoHdr);
                                    }
                                    else
                                    {
                                        PdfPCell CellTwoHdr = new PdfPCell(new Phrase(cellText));
                                        CellTwoHdr.HorizontalAlignment = Element.ALIGN_CENTER;
                                        CellTwoHdr.VerticalAlignment   = Element.ALIGN_MIDDLE;
                                        CellTwoHdr.Padding             = 5;
                                        pdfPTable.AddCell(CellTwoHdr);
                                    }
                                }
                                pdfPTable.HeaderRows = 1;
                            }
                        }

                        var imageURL = Server.MapPath(".") + "\\GEAProcess_large_20122024.jpg";
                        iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);

                        jpg.Alignment = Element.ALIGN_CENTER;
                        jpg.SetAbsolutePosition(30, 1060);

                        //For IDMC Logo
                        var imageURL1 = Server.MapPath(".") + "\\GEAProcess_large_20122024.jpg";
                        iTextSharp.text.Image jpg1 = iTextSharp.text.Image.GetInstance(imageURL1);

                        jpg1.Alignment = Element.ALIGN_RIGHT;
                        jpg1.SetAbsolutePosition(700, 1060);

                        StringReader sr = new StringReader(sb.ToString());

                        Document pdfDoc = new Document(PageSize.A4, -50f, -50f, 20f, 30f);

                        HTMLWorker          htmlparser      = new HTMLWorker(pdfDoc);
                        PdfWriter           writer          = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                        PDFBackgroundHelper pageEventHelper = new PDFBackgroundHelper();
                        writer.PageEvent = pageEventHelper;
                        pdfDoc.Open();
                        htmlparser.Parse(sr);
                        pdfDoc.Add(jpg);
                        pdfDoc.Add(jpg1);
                        pdfDoc.Add(pdfPTable);
                        //htmlparser.Parse(sr1);

                        //----------- FOOTER -----------
                        PdfPTable footer        = new PdfPTable(2);
                        PdfPTable footer2       = new PdfPTable(2);
                        PdfPCell  footer_Cell1  = new PdfPCell(new Phrase("Shift"));
                        PdfPCell  footer2_Cell1 = new PdfPCell(new Phrase("Shift Incharge"));
                        PdfPCell  common_Cell   = new PdfPCell(new Phrase(": ____________________"));

                        float[] cols = new float[] { 100, 300 };

                        footer.SetWidthPercentage(cols, PageSize.A3);
                        footer2.SetWidthPercentage(cols, PageSize.A3);
                        footer_Cell1.Border  = 0;
                        footer2_Cell1.Border = 0;
                        common_Cell.Border   = 0;
                        footer.AddCell(footer_Cell1);
                        footer.AddCell(common_Cell);
                        footer2.AddCell(footer2_Cell1);
                        footer2.AddCell(common_Cell);
                        footer.WriteSelectedRows(0, -1, pdfDoc.LeftMargin + 125, 90, writer.DirectContent);
                        footer2.WriteSelectedRows(0, -1, pdfDoc.LeftMargin + 125, 70, writer.DirectContent);
                        //----------- /FOOTER -----------

                        pdfDoc.Close();
                        Response.ContentType = "application/pdf";

                        Response.AddHeader("content-disposition", "attachment;" + "filename=DryerProductionLogReport" + DateTime.Now.Date.ToString("dd-MM-yyyy") + ".pdf");
                        Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        Response.Write(pdfDoc);
                        Response.Flush();
                        Response.Clear();
                        Response.End();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("Error", ex);
                ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp",
                                                   "<script>alert('Oops! There is some technical Problem. Contact to your Administrator.');</script>");
            }
        }
Exemple #28
0
        /// <summary>
        /// Create the PDF using the defined page size, label type and content provided
        /// Ensure you have added something first using either AddImage() or AddText()
        /// </summary>
        /// <returns></returns>
        public Stream CreatePDF()
        {
            //Get the itext page size
            Rectangle pageSize;

            switch (_labelDefinition.PageSize)
            {
            case Enums.PageSize.A4:
                pageSize = iTextSharp.text.PageSize.A4;
                break;

            case Enums.PageSize.Letter:
                pageSize = iTextSharp.text.PageSize.LETTER;
                break;

            default:
                pageSize = iTextSharp.text.PageSize.A4;
                break;
            }

            //Create a new iText document object, define the paper size and the margins required
            var doc = new Document(pageSize,
                                   _labelDefinition.PageMarginLeft,
                                   _labelDefinition.PageMarginRight,
                                   _labelDefinition.PageMarginTop,
                                   _labelDefinition.PageMarginBottom);

            //Create a stream to write the PDF to
            var output = new MemoryStream();

            //Creates the document tells the PdfWriter to use the output stream when Document.Close() is called
            var writer = PdfWriter.GetInstance(doc, output);

            //Ensure stream isn't closed when done - we need to return it
            writer.CloseStream = false;

            //Open the document to begin adding elements
            doc.Open();

            //Create a new table with label and gap columns
            var numOfCols = _labelDefinition.LabelsPerRow + (_labelDefinition.LabelsPerRow - 1);
            // var tbl = new PdfPTable(numOfCols);

            //Build the column width array, even numbered index columns will be gap columns
            var colWidths = new List <float>();

            for (int i = 1; i <= numOfCols; i++)
            {
                if (i % 2 > 0)
                {
                    colWidths.Add(_labelDefinition.Width);
                }
                else
                {
                    //Even numbered columns are gap columns
                    colWidths.Add(_labelDefinition.HorizontalGapWidth);
                }
            }

            /* The next 3 lines are the key to making SetWidthPercentage work */
            /* "size" specifies the size of the page that equates to 100% - even though the values passed are absolute not relative?! */
            /* (I will never get those 3 hours back) */
            var w    = pageSize.Width - (doc.LeftMargin + doc.RightMargin);
            var h    = pageSize.Height - (doc.TopMargin + doc.BottomMargin);
            var size = new iTextSharp.text.Rectangle(w, h);


            // loop over the labels

            var rowNumber = 0;
            var colNumber = 0;


            PdfPTable tbl = null;

            foreach (var label in _labels)
            {
                if (rowNumber == 0)
                {
                    tbl = new PdfPTable(numOfCols);
                    tbl.SetWidthPercentage(colWidths.ToArray(), size);
                    rowNumber = 1; // so we start with row 1
                    doc.NewPage();
                }
                colNumber++; // so we start with col 1

                // add the label cell.
                var cell = FormatCell(label.GetLabelCell());

                //Add to the row
                tbl.AddCell(cell);

                //Create a empty cell to use as a gap
                if (colNumber < numOfCols)
                {
                    tbl.AddCell(CreateGapCell());
                    colNumber++; // increment for the gap row
                }

                //On all but the last row, after the last column, add a gap row if needed
                if (colNumber == numOfCols && ((rowNumber) < _labelDefinition.LabelRowsPerPage && _labelDefinition.VerticalGapHeight > 0))
                {
                    tbl.Rows.Add(CreateGapRow(numOfCols));
                }


                if (colNumber == numOfCols)
                {
                    // add the row to the table and re-initialize
                    tbl.CompleteRow();

                    rowNumber++;
                    colNumber = 0;
                }


                if (rowNumber > _labelDefinition.LabelRowsPerPage)
                {
                    //Add the table to the document
                    doc.Add(tbl);
                    rowNumber = 0;
                    colNumber = 0;
                }
            }

            if (colNumber < numOfCols)
            {
                // finish the row that was being built
                while (colNumber < numOfCols)
                {
                    if (colNumber % 2 == 1)
                    {
                        tbl.AddCell(CreateEmptyLabelCell());
                    }
                    else
                    {
                        tbl.AddCell(CreateGapCell());
                    }
                    colNumber++;
                }


                tbl.CompleteRow();
            }

            // make sure the last table gets added to the document
            if (rowNumber > 0)
            {
                //Add the table to the document
                doc.Add(tbl);
            }

            //Close the document, writing to the stream we specified earlier
            doc.Close();

            //Set the stream back to position 0 so we can use it when it's returned
            output.Position = 0;

            return(output);
        }
        public override void OnStartPage(PdfWriter writer, Document document)
        {
            base.OnStartPage(writer, document);
            Rectangle pageSize = document.PageSize;

            string imageURL = HttpContext.Current.Server.MapPath("~/Reportes/img/LogoRep.jpg");

            iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL);
            //Resize image depend upon your need
            jpg.ScaleToFit(100f, 100f);
            //Give space before image
            jpg.SpacingBefore = 10f;
            //Give some space after the image
            jpg.SpacingAfter = 1f;
            jpg.Alignment    = Element.ALIGN_LEFT;

            PdfPTable headerTbl = new PdfPTable(1);

            headerTbl.TotalWidth = 400;

            headerTbl.HorizontalAlignment = Element.ALIGN_CENTER;

            PdfPCell cell11 = new PdfPCell(jpg);
            PdfPCell cell2  = new PdfPCell();

            cell2.Border  = 0;
            cell11.Border = 0;

            cell11.PaddingLeft = 10;
            cell2.PaddingLeft  = 10;
            headerTbl.AddCell(cell11);
            headerTbl.AddCell(cell2);

            headerTbl.WriteSelectedRows(0, -1, pageSize.GetLeft(40), pageSize.GetTop(10), writer.DirectContent);

            if (Title != string.Empty)
            {
                cb.BeginText();
                cb.SetFontAndSize(BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 15);
                cb.SetRGBColorFill(50, 50, 200);
                cb.SetTextMatrix(pageSize.GetLeft(250), pageSize.GetTop(95));
                cb.ShowText(Title);
                cb.EndText();
            }
            if (HeaderLeft + HeaderRight != string.Empty)
            {
                PdfPTable HeaderTable = new PdfPTable(2);
                HeaderTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
                HeaderTable.TotalWidth = pageSize.Width - 80;
                HeaderTable.SetWidthPercentage(new float[] { 45, 45 }, pageSize);

                PdfPCell HeaderLeftCell = new PdfPCell(new Phrase(8, HeaderLeft, HeaderFont));
                HeaderLeftCell.Padding          = 5;
                HeaderLeftCell.PaddingBottom    = 8;
                HeaderLeftCell.BorderWidthRight = 0;
                HeaderTable.AddCell(HeaderLeftCell);
                PdfPCell HeaderRightCell = new PdfPCell(new Phrase(8, HeaderRight, HeaderFont));
                HeaderRightCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
                HeaderRightCell.Padding             = 5;
                HeaderRightCell.PaddingBottom       = 8;
                HeaderRightCell.BorderWidthLeft     = 0;
                HeaderTable.AddCell(HeaderRightCell);
                cb.SetRGBColorFill(0, 0, 0);
                HeaderTable.WriteSelectedRows(0, -1, pageSize.GetLeft(40), pageSize.GetTop(130), cb);
            }
        }
Exemple #30
0
        public void crearPDF(CartaD v, string spr, bool aprob)
        {
            using (TAT001Entities db = new TAT001Entities())
            {
                HeaderFooterD hfClass       = new HeaderFooterD(v);
                DateTime      fechaCreacion = DateTime.Now;
                string        nombreArchivo = string.Format("{0}.pdf", fechaCreacion.ToString(@"yyyyMMdd") + "_" + fechaCreacion.ToString(@"HHmmss"));
                string        rutaCompleta  = HttpContext.Current.Server.MapPath("~/PdfTemp/" + nombreArchivo);
                FileStream    fsDocumento   = new FileStream(rutaCompleta, FileMode.Create);
                //PASO UNO DEMINIMOS EL TIPO DOCUMENTO CON LOS RESPECTIVOS MARGENES (A4,IZQ,DER,TOP,BOT)
                Document  pdfDoc    = new Document(PageSize.A4, 30f, 30f, 40f, 100f);
                PdfWriter pdfWriter = PdfWriter.GetInstance(pdfDoc, fsDocumento);
                pdfWriter.PageEvent = new HeaderFooterD();
                var text = db.TEXTOCVs.Where(x => x.SPRAS_ID == spr);

                try
                {
                    pdfDoc.Open();
                    Paragraph frase1, frase2;

                    if (v.company_x == true)
                    {
                        frase1 = new Paragraph(v.company, negritaPeque);
                        a      = 18;
                    }
                    else
                    {
                        frase1 = new Paragraph("", negritaPeque);
                        a      = 0;
                    }

                    if (!aprob)
                    {
                        float          fontSize  = 250;
                        float          xPosition = 300;
                        float          yPosition = 400;
                        float          angle     = 45;
                        PdfContentByte under     = pdfWriter.DirectContentUnder;
                        BaseFont       baseFont  = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
                        under.BeginText();
                        under.SetColorFill(BaseColor.LIGHT_GRAY);
                        under.SetFontAndSize(baseFont, fontSize);
                        under.ShowTextAligned(PdfContentByte.ALIGN_CENTER, text.Where(x => x.CAMPO == "agua").First().TEXTO, xPosition, yPosition, angle);
                        under.EndText();
                    }


                    frase1.Alignment = Element.ALIGN_RIGHT;
                    pdfDoc.Add(frase1);
                    pdfDoc.Add(new Chunk(""));

                    if (v.taxid_x == true)
                    {
                        frase2 = new Paragraph(v.taxid, negritaPeque);
                        b      = 18;
                    }
                    else
                    {
                        frase2 = new Paragraph("", negritaPeque);
                        b      = 0;
                    }
                    frase2.Alignment = Element.ALIGN_RIGHT;
                    pdfDoc.Add(frase2);
                    r = a + b;

                    //AQUI VA LA LINEA 2
                    pdfDoc.Add(new Chunk(""));
                    PdfPTable tabColor    = new PdfPTable(5);
                    PdfPCell  celdaColor  = new PdfPCell(new Paragraph(""));
                    PdfPCell  celdaColor2 = new PdfPCell(new Paragraph(""));
                    PdfPCell  celdaColor3 = new PdfPCell(new Paragraph(""));
                    PdfPCell  celdaColor4 = new PdfPCell(new Paragraph(""));
                    PdfPCell  celdaColor5 = new PdfPCell(new Paragraph(""));
                    celdaColor.BackgroundColor  = new BaseColor(181, 25, 70);
                    celdaColor2.BackgroundColor = new BaseColor(150, 23, 46);
                    celdaColor3.BackgroundColor = new BaseColor(238, 175, 48);
                    celdaColor4.BackgroundColor = new BaseColor(224, 0, 52);
                    celdaColor5.BackgroundColor = new BaseColor(252, 217, 0);
                    celdaColor.FixedHeight      = 10f;
                    tabColor.AddCell(celdaColor);
                    tabColor.AddCell(celdaColor2);
                    tabColor.AddCell(celdaColor3);
                    tabColor.AddCell(celdaColor4);
                    tabColor.AddCell(celdaColor5);
                    tabColor.SetWidthPercentage(new float[] { 400, 50, 80, 25, 110 }, PageSize.A4);
                    for (int i = 0; i < tabColor.Rows.Count; i++)
                    {
                        if (i <= 4)
                        {
                            hfClass.quitaBordes(i, tabColor);
                        }
                    }
                    pdfDoc.Add(tabColor);

                    //AQUI EMPIEZA APARTADO DE DATOS
                    pdfDoc.Add(new Chunk(""));
                    tablaDatos1.HorizontalAlignment = Element.ALIGN_LEFT;
                    tablaDatos1.SetWidthPercentage(new float[] { 298, 298 }, PageSize.A4);

                    if (v.concepto_x == true)
                    {
                        PdfPCell celda1 = new PdfPCell(new Paragraph(v.concepto, negritaPeque)); celda1.Border = 0; tablaDatos1.AddCell(celda1);
                    }
                    else
                    {
                        PdfPCell celda1 = new PdfPCell(new Paragraph("", negritaPeque)); celda1.Border = 0; tablaDatos1.AddCell(celda1);
                    }

                    if (v.folio_x == true)
                    {
                        PdfPCell celda2 = new PdfPCell(new Paragraph(text.Where(x => x.CAMPO == "folio").Select(x => x.TEXTO).First() + " " + v.folio, negritaPeque)); celda2.HorizontalAlignment = Element.ALIGN_RIGHT; celda2.Border = 0; tablaDatos1.AddCell(celda2);
                    }
                    else
                    {
                        PdfPCell celda2 = new PdfPCell(new Paragraph("", normalPeque)); celda2.HorizontalAlignment = Element.ALIGN_RIGHT; celda2.Border = 0; tablaDatos1.AddCell(celda2);
                    }

                    PdfPCell celdaB1 = new PdfPCell(new Paragraph("\n", negritaPeque)); celdaB1.Border = 0; tablaDatos1.AddCell(celdaB1);
                    PdfPCell celdaB2 = new PdfPCell(new Paragraph("\n", negritaPeque)); celdaB2.Border = 0; tablaDatos1.AddCell(celdaB2);

                    if (v.payerNom_x == true)
                    {
                        PdfPCell celda3 = new PdfPCell(new Paragraph(v.payerNom, negritaPeque)); celda3.Border = 0; tablaDatos1.AddCell(celda3);
                    }
                    else
                    {
                        PdfPCell celda3 = new PdfPCell(new Paragraph("", normalPeque)); celda3.Border = 0; tablaDatos1.AddCell(celda3);
                    }

                    if (v.lugarFech_x == true)
                    {
                        PdfPCell celda4 = new PdfPCell(new Paragraph(v.lugarFech, negritaPeque)); celda4.HorizontalAlignment = Element.ALIGN_RIGHT; celda4.Border = 0; tablaDatos1.AddCell(celda4);
                    }
                    else
                    {
                        PdfPCell celda4 = new PdfPCell(new Paragraph("", normalPeque)); celda4.HorizontalAlignment = Element.ALIGN_RIGHT; celda4.Border = 0; tablaDatos1.AddCell(celda4);
                    }

                    if (v.cliente_x == true)
                    {
                        PdfPCell celda5 = new PdfPCell(new Paragraph(v.cliente, negritaPeque)); celda5.Border = 0; tablaDatos1.AddCell(celda5);
                    }
                    else
                    {
                        PdfPCell celda5 = new PdfPCell(new Paragraph("", negritaPeque)); celda5.Border = 0; tablaDatos1.AddCell(celda5);
                    }

                    if (v.lugar_x == true)
                    {
                        PdfPCell celda6 = new PdfPCell(new Paragraph(v.lugar, negritaPeque)); celda6.HorizontalAlignment = Element.ALIGN_RIGHT; celda6.Border = 0; tablaDatos1.AddCell(celda6);
                    }
                    else
                    {
                        PdfPCell celda6 = new PdfPCell(new Paragraph("", negritaPeque)); celda6.HorizontalAlignment = Element.ALIGN_RIGHT; celda6.Border = 0; tablaDatos1.AddCell(celda6);
                    }

                    if (v.puesto_x == true)
                    {
                        PdfPCell celda7 = new PdfPCell(new Paragraph(v.puesto, normalPeque)); celda7.Border = 0; tablaDatos1.AddCell(celda7);
                    }
                    else
                    {
                        PdfPCell celda7 = new PdfPCell(new Paragraph("", normalPeque)); celda7.Border = 0; tablaDatos1.AddCell(celda7);
                    }

                    if (v.payerId_x == true)
                    {
                        PdfPCell celda8 = new PdfPCell(new Paragraph(text.Where(x => x.CAMPO == "control").Select(x => x.TEXTO).First(), negritaPeque)); celda8.BackgroundColor = new BaseColor(204, 204, 204); tablaDatos1.AddCell(celda8);
                    }
                    else
                    {
                        PdfPCell celda8 = new PdfPCell(new Paragraph("", negritaPeque)); celda8.Border = 0; tablaDatos1.AddCell(celda8);
                    }

                    if (v.direccion_x == true)
                    {
                        PdfPCell celda9 = new PdfPCell(new Paragraph(v.direccion, normalPeque)); celda9.Border = 0; tablaDatos1.AddCell(celda9);
                    }
                    else
                    {
                        PdfPCell celda9 = new PdfPCell(new Paragraph("", normalPeque)); celda9.Border = 0; tablaDatos1.AddCell(celda9);
                    }

                    if (v.payerId_x == true)
                    {
                        PdfPCell celda10 = new PdfPCell(new Paragraph(text.Where(x => x.CAMPO == "payer").Select(x => x.TEXTO).First() + " " + v.payerId, normalPeque)); tablaDatos1.AddCell(celda10);
                    }
                    else
                    {
                        PdfPCell celda10 = new PdfPCell(new Paragraph("", normalPeque)); celda10.Border = 0; tablaDatos1.AddCell(celda10);
                    }

                    float var = tablaDatos1.TotalHeight;
                    pdfDoc.Add(tablaDatos1);

                    //APARTIR DE AQUI VA EL ESTIMADO
                    pdfDoc.Add(new Chunk("\n"));
                    Phrase fraseEstimado = new Phrase();

                    if (v.estimado_x == true)
                    {
                        fraseEstimado.Add(new Paragraph(text.Where(x => x.CAMPO == "estimado").Select(x => x.TEXTO).First() + " " + v.estimado, negritaPeque));
                    }
                    else
                    {
                        fraseEstimado.Add("");
                    }
                    pdfDoc.Add(fraseEstimado);

                    //APARTIR DE AQUI VA LA MECANICA
                    pdfDoc.Add(new Chunk("\n"));
                    pdfDoc.Add(new Chunk("\n"));
                    Phrase miFrase = new Phrase();

                    if (v.mecanica_x == true)
                    {
                        miFrase.Add(new Paragraph(v.mecanica, normalPeque));
                    }
                    else
                    {
                        miFrase.Add("");
                    }
                    pdfDoc.Add(miFrase);

                    //AQUI COMIENZAN LAS TABLAS
                    //1.- TABLA DE MATERIALES
                    int tablas = v.listaFechas.Count;      //SE RECIBE LA N CANTIDAD DE TABLAS A GENERAR
                    int cols   = v.numColEncabezado.Count; // SE RECIBE LA CANTIDAD DE COLUMNAS A CONTENER LA TABLA
                    int tamaño = 0;
                    try                                    //B20180720P MGC 2018.07.25
                    {
                        tamaño = 600 / cols;
                    }
                    catch (Exception)
                    {
                        tamaño = 0;
                    }

                    for (int a = 0; a < tablas; a++)
                    {
                        PdfPTable tablasN = new PdfPTable(cols);

                        if (cols == 1)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño }, PageSize.A4);
                        }
                        else if (cols == 2)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 3)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 4)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 5)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño, tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 6)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño, tamaño, tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 7)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 8)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 9)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño }, PageSize.A4);
                        }
                        else if (cols == 10)
                        {
                            tablasN.SetWidthPercentage(new float[] { tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño, tamaño }, PageSize.A4);
                        }

                        PdfPCell rangoFecha = new PdfPCell(new Paragraph(text.Where(x => x.CAMPO == "de").Select(x => x.TEXTO).First() + " " + v.listaFechas[a].Remove(10) + " " + text.Where(x => x.CAMPO == "a").Select(x => x.TEXTO).First() + " " + (v.listaFechas[a].Remove(0, v.listaFechas[a].Length / 2)).Remove(10)));
                        rangoFecha.Border  = 0;
                        rangoFecha.Colspan = cols;
                        tablasN.AddCell(rangoFecha);

                        foreach (var celCabecera in v.numColEncabezado)
                        {
                            PdfPCell celdaCabeza = new PdfPCell();
                            celdaCabeza.AddElement(new Paragraph(celCabecera, letraTabNegrita));
                            celdaCabeza.BackgroundColor = new BaseColor(204, 204, 204);
                            tablasN.AddCell(celdaCabeza);
                        }

                        int columnas = 0;
                        int filas    = 0;
                        columnas = cols;
                        filas    = v.numfilasTabla[a];

                        for (int i = 0; i < filas; i++)
                        {
                            for (int j = 0; j < columnas; j++)
                            {
                                tablasN.AddCell(new Paragraph(v.listaCuerpo[pos], letraTab));
                                pos++;
                            }
                        }

                        pdfDoc.Add(tablasN);
                        pdfDoc.Add(new Chunk("\n"));
                    }

                    //APARTIR DE AQUI VA EL MONTO
                    miFrase.Clear();
                    if (v.monto_x == true)
                    {
                        //pdfDoc.Add(new Chunk("\n"));
                        miFrase.Add(new Paragraph(text.Where(x => x.CAMPO == "monto").Select(x => x.TEXTO).First() + " " + v.monto + " " + v.moneda, normalPeque));
                    }
                    else
                    {
                        miFrase.Add("");
                    }
                    pdfDoc.Add(miFrase);

                    //APARTIR DE AQUI VA LA SEGUNDA TABLA
                    //2.- TABLA DE RECURRENCIAS
                    if (v.secondTab_x == true)
                    {
                        int       cols2    = v.numColEncabezado2.Count();
                        int       tamaño2  = 600 / cols2;
                        PdfPTable tablasN2 = new PdfPTable(cols2);

                        tablasN2.SetWidthPercentage(new float[] { tamaño2, tamaño2, tamaño2, tamaño2, tamaño2 }, PageSize.A4);

                        foreach (var celCabecera2 in v.numColEncabezado2)
                        {
                            PdfPCell celdaCabeza2 = new PdfPCell();
                            celdaCabeza2.AddElement(new Paragraph(celCabecera2, letraTabNegrita));
                            celdaCabeza2.BackgroundColor = new BaseColor(204, 204, 204);
                            tablasN2.AddCell(celdaCabeza2);
                        }

                        for (int i = 0; i < v.numfilasTabla2; i++)
                        {
                            for (int j = 0; j < cols2; j++)
                            {
                                tablasN2.AddCell(new Paragraph(v.listaCuerpoRec[pos2], letraTab));
                                pos2++;
                            }
                        }

                        pdfDoc.Add(tablasN2);
                        pdfDoc.Add(new Chunk("\n"));
                    }


                    //APARTIR DE AQUI VAN LAS FIRMAS
                    //LINEAS PARA LA FIRMA EN UNA TABLA
                    //pdfDoc.Add(new Chunk("\n"));
                    PdfPCell celFirma1 = new PdfPCell();
                    PdfPCell celFirma2 = new PdfPCell();

                    PdfPTable tabFirma1   = new PdfPTable(1);
                    PdfPCell  celFirmita1 = new PdfPCell();
                    if (v.nombreE_x == true | v.puestoE_x == true | v.companyC_x == true)
                    {
                        celFirmita1.AddElement(new Paragraph("\n", normalPeque)); celFirmita1.Border = 2;
                    }
                    else
                    {
                        celFirmita1.AddElement(new Paragraph("", normalPeque)); celFirmita1.Border = 0;
                    }
                    tabFirma1.AddCell(celFirmita1);
                    tabFirma1.SetWidthPercentage(new float[] { 450 }, PageSize.A4);

                    PdfPTable tabFirma2   = new PdfPTable(1);
                    PdfPCell  celFirmita2 = new PdfPCell();
                    if (v.nombreC_x == true | v.puestoC_x == true | v.companyCC_x == true)
                    {
                        celFirmita2.AddElement(new Paragraph("\n", normalPeque)); celFirmita2.Border = 2;
                    }
                    else
                    {
                        celFirmita2.AddElement(new Paragraph("", normalPeque)); celFirmita2.Border = 0;
                    }
                    tabFirma2.AddCell(celFirmita2);
                    tabFirma2.SetWidthPercentage(new float[] { 450 }, PageSize.A4);

                    celFirma1.AddElement(tabFirma1);
                    celFirma1.Border = 0;

                    celFirma2.AddElement(tabFirma2);
                    celFirma2.Border = 0;

                    tablaDatos2.AddCell(celFirma1);
                    tablaDatos2.AddCell(celFirma2);
                    tablaDatos2.SetWidthPercentage(new float[] { 300, 300 }, PageSize.A4);

                    pdfDoc.Add(tablaDatos2);

                    //DATOS PARA LAS FIRMAS
                    tablaDatos3.HorizontalAlignment = Element.ALIGN_LEFT;
                    tablaDatos3.SetWidthPercentage(new float[] { 298, 298 }, PageSize.A4);

                    if (v.nombreE_x == true)
                    {
                        PdfPCell celda1Dat3 = new PdfPCell(new Paragraph(v.nombreE, negritaPeque)); celda1Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda1Dat3);
                    }
                    else
                    {
                        PdfPCell celda1Dat3 = new PdfPCell(new Paragraph("", negritaPeque)); celda1Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda1Dat3);
                    }

                    if (v.nombreC_x == true)
                    {
                        PdfPCell celda2Dat3 = new PdfPCell(new Paragraph(v.nombreC, negritaPeque)); celda2Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda2Dat3);
                    }
                    else
                    {
                        PdfPCell celda2Dat3 = new PdfPCell(new Paragraph("", negritaPeque)); celda2Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda2Dat3);
                    }

                    if (v.puestoE_x == true)
                    {
                        PdfPCell celda3Dat3 = new PdfPCell(new Paragraph(v.puestoE, normalPeque)); celda3Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda3Dat3);
                    }
                    else
                    {
                        PdfPCell celda3Dat3 = new PdfPCell(new Paragraph("", normalPeque)); celda3Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda3Dat3);
                    }

                    if (v.puestoC_x == true)
                    {
                        PdfPCell celda4Dat3 = new PdfPCell(new Paragraph(v.puestoC, normalPeque)); celda4Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda4Dat3);
                    }
                    else
                    {
                        PdfPCell celda4Dat3 = new PdfPCell(new Paragraph("", normalPeque)); celda4Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda4Dat3);
                    }

                    if (v.companyC_x == true)
                    {
                        PdfPCell celda5Dat3 = new PdfPCell(new Paragraph(v.companyC, negritaPeque)); celda5Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda5Dat3);
                    }
                    else
                    {
                        PdfPCell celda5Dat3 = new PdfPCell(new Paragraph("", negritaPeque)); celda5Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda5Dat3);
                    }

                    if (v.companyCC_x == true)
                    {
                        PdfPCell celda6Dat3 = new PdfPCell(new Paragraph(v.companyCC, negritaPeque)); celda6Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda6Dat3);
                    }
                    else
                    {
                        PdfPCell celda6Dat3 = new PdfPCell(new Paragraph("", negritaPeque)); celda6Dat3.HorizontalAlignment = Element.ALIGN_CENTER; tablaDatos3.AddCell(celda6Dat3);
                    }

                    for (int i = 0; i < tablaDatos3.Rows.Count; i++)
                    {
                        if (i <= 4)
                        {
                            hfClass.quitaBordes(i, tablaDatos3);
                        }
                    }
                    pdfDoc.Add(tablaDatos3);


                    //TABLA PARA LOS COMENTARIOS
                    pdfDoc.Add(new Chunk("\n"));
                    tabComentarios.HorizontalAlignment = Element.ALIGN_LEFT;
                    tabComentarios.SetWidthPercentage(new float[] { 300, 300 }, PageSize.A4);

                    if (v.comentarios_x == true)
                    {
                        PdfPCell celda1 = new PdfPCell(new Paragraph(v.comentarios, normalPeque)); celda1.Border = 0; tabComentarios.AddCell(celda1);
                    }
                    else
                    {
                        PdfPCell celda1 = new PdfPCell(new Paragraph("", normalPeque)); celda1.Border = 0; tabComentarios.AddCell(celda1);
                    }

                    if (v.compromisoK_x == true)
                    {
                        PdfPCell celda2 = new PdfPCell(new Paragraph(v.compromisoK, normalPeque)); celda2.Border = 0; tabComentarios.AddCell(celda2);
                    }
                    else
                    {
                        PdfPCell celda2 = new PdfPCell(new Paragraph("", normalPeque)); celda2.Border = 0; tabComentarios.AddCell(celda2);
                    }

                    if (v.compromisoC_x == true)
                    {
                        PdfPCell celda3 = new PdfPCell(new Paragraph("\n" + v.compromisoC, normalPeque)); celda3.Border = 0; tabComentarios.AddCell(celda3);
                    }
                    else
                    {
                        PdfPCell celda3 = new PdfPCell(new Paragraph("", normalPeque)); celda3.Border = 0; tabComentarios.AddCell(celda3);
                    }

                    PdfPCell celVacia = new PdfPCell(new Paragraph("", normalPeque));
                    celVacia.Border = 0;
                    tabComentarios.AddCell(celVacia);

                    pdfDoc.Add(tabComentarios);
                    pdfDoc.Close();
                    HttpContext.Current.Session["rutaCompletaV"] = "/PdfTemp/" + nombreArchivo;
                }
                catch (Exception ex)
                {
                    ex.Message.ToString();
                }
            }
        }