示例#1
0
        public virtual void StylesTest01()
        {
            Style myStyle = new Style();

            myStyle.SetFontColor(Color.RED);
            Paragraph p = new Paragraph("text").AddStyle(myStyle).SetFontColor(Color.GREEN);

            NUnit.Framework.Assert.AreEqual(Color.GREEN, p.GetRenderer().GetProperty <Color>(Property.FONT_COLOR));
        }
示例#2
0
        public virtual void StylesTest02()
        {
            Style myStyle = new Style();

            myStyle.SetFontColor(ColorConstants.RED);
            Paragraph p = new Paragraph("text").AddStyle(myStyle);

            NUnit.Framework.Assert.AreEqual(ColorConstants.RED, p.GetRenderer().GetProperty <TransparentColor>(Property
                                                                                                               .FONT_COLOR).GetColor());
        }
示例#3
0
        // ====================================================================================================
        #region MÉTODOS PRIVADOS (ITEXT 7)
        // ====================================================================================================

        private static Table GetTablaGraficos(ListCollectionView listaGraficos, DateTime fecha)
        {
            // Fuente a utilizar en la tabla.
            PdfFont arial = PdfFontFactory.CreateFont("c:/windows/fonts/calibri.ttf", true);

            // Estilo de la tabla.
            iText.Layout.Style estiloTabla = new iText.Layout.Style();
            estiloTabla.SetTextAlignment(TextAlignment.CENTER)
            .SetVerticalAlignment(VerticalAlignment.MIDDLE)
            .SetMargins(0, 0, 0, 0)
            .SetPaddings(0, 0, 0, 0)
            .SetWidth(UnitValue.CreatePercentValue(100))
            .SetFont(arial)
            .SetFontSize(8);
            // Estilo titulos
            iText.Layout.Style estiloTitulos = new iText.Layout.Style();
            estiloTitulos.SetBold()
            .SetBorder(iText.Layout.Borders.Border.NO_BORDER)
            .SetFontSize(14);
            // Estilo de las celdas de encabezado.
            iText.Layout.Style estiloEncabezados = new iText.Layout.Style();
            estiloEncabezados.SetBackgroundColor(new DeviceRgb(112, 173, 71))
            .SetBold()
            .SetFontSize(8);
            // Estilo de las celdas de izq.
            iText.Layout.Style estiloIzq = new iText.Layout.Style();
            estiloIzq.SetBorderLeft(new SolidBorder(1));
            // Estilo de las celdas de med.
            iText.Layout.Style estiloMed = new iText.Layout.Style();
            estiloMed.SetBorderTop(new SolidBorder(1))
            .SetBorderBottom(new SolidBorder(1));
            // Estilo de las celdas de der.
            iText.Layout.Style estiloDer = new iText.Layout.Style();
            estiloDer.SetBorderRight(new SolidBorder(1));
            // Creamos la tabla
            float[] ancho = new float[] { 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3 };
            Table   tabla = new Table(UnitValue.CreatePercentArray(ancho));

            // Asignamos el estilo a la tabla.
            tabla.AddStyle(estiloTabla);

            string textoEncabezado = $"GRÁFICOS\n{fecha:dd - MMMM - yyyy} ({App.Global.CentroActual})".ToUpper();
            Table  tablaEncabezado = InformesServicio.GetTablaEncabezadoSindicato(textoEncabezado);

            tabla.AddHeaderCell(new Cell(1, 17).Add(tablaEncabezado).AddStyle(estiloTitulos));

            // Añadimos las celdas de encabezado.
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Número")).AddStyle(estiloEncabezados).AddStyle(estiloIzq).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Turno")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Inicio")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Final")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Ini. Partido")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Fin. Partido")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Valoracion")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Trabajadas")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Dif.")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Acumuladas")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Nocturnas")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Desayuno")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Comida")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Cena")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Plus Cena")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Limpieza")).AddStyle(estiloEncabezados).AddStyle(estiloMed));
            tabla.AddHeaderCell(new Cell().Add(new Paragraph("Paquetería")).AddStyle(estiloEncabezados).AddStyle(estiloDer).AddStyle(estiloMed));
            // Añadimos las celdas con los calendarios.
            int indice = 1;

            foreach (Object obj in listaGraficos)
            {
                Grafico g = obj as Grafico;
                if (g == null)
                {
                    continue;
                }
                // Estilo Fondo Alternativo
                iText.Layout.Style estiloFondo = new iText.Layout.Style().SetBackgroundColor(ColorConstants.WHITE);
                if (indice % 2 == 0)
                {
                    estiloFondo.SetBackgroundColor(new DeviceRgb(226, 239, 218));
                }
                indice++;
                // Estilo Valoracion Diferente
                iText.Layout.Style estiloValDif = new iText.Layout.Style();
                if (g.DiferenciaValoracion.Ticks != 0)
                {
                    estiloValDif.SetFontColor(new DeviceRgb(255, 20, 147));
                }
                // Escribimos el grafico.
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvNumGrafico.Convert(g.Numero, null, null, null)}"))
                              .AddStyle(estiloIzq).AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{g.Turno.ToString("0")}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Inicio, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Final, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.InicioPartido, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.FinalPartido, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Valoracion, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo).AddStyle(estiloValDif));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Trabajadas, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo).AddStyle(estiloValDif));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.DiferenciaValoracion, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo).AddStyle(estiloValDif));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Acumuladas, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(g.Nocturnas, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.Desayuno, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.Comida, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.Cena, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvDecimal.Convert(g.PlusCena, null, VerValores.NoCeros, null)}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(g.PlusLimpieza ? "X" : "")}"))
                              .AddStyle(estiloFondo));
                tabla.AddCell(new Cell().Add(new Paragraph($"{(g.PlusPaqueteria ? "X" : "")}"))
                              .AddStyle(estiloDer).AddStyle(estiloFondo));
            }
            // Ponemos los bordes de la tabla.
            tabla.SetBorderBottom(new SolidBorder(1));
            // Devolvemos la tabla.
            return(tabla);
        }
示例#4
0
        private void ExportComparison(object title)
        {
            // Must have write permissions to the path folder
            FileInfo file = new FileInfo(titlePDF.ToString() + ".pdf");

            file.Delete();
            var fileStream = file.Create();

            fileStream.Close();
            PdfDocument pdfdoc      = new PdfDocument(new PdfWriter(file));
            PdfFont     font        = PdfFontFactory.CreateFont(StandardFonts.TIMES_BOLD);
            PdfFont     cellFont    = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont     OKFont      = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            PdfFont     NOKFont     = PdfFontFactory.CreateFont(StandardFonts.TIMES_ROMAN);
            Style       headerStyle = new Style();

            headerStyle.SetFont(font).SetFontSize(11);
            headerStyle.SetBold();
            Style cellStyle = new Style();

            cellStyle.SetFont(cellFont).SetFontSize(10);
            Style OKStyle = new Style();

            OKStyle.SetFont(OKFont).SetFontSize(10);
            OKStyle.SetFontColor(ColorConstants.GREEN, 1);
            Style NOKStyle = new Style();

            NOKStyle.SetFont(NOKFont).SetFontSize(10);
            NOKStyle.SetFontColor(ColorConstants.RED, 1);

            pdfdoc.SetDefaultPageSize(PageSize.A2.Rotate());
            pdfdoc.SetTagged();
            using (Document document = new Document(pdfdoc))
            {
                iText.Layout.Element.Cell cell;
                Table table = CreateHeaders(document, headerStyle, title.ToString());
                for (int i = 0; i < documentationImportList.Count; i++)
                {
                    cell = new iText.Layout.Element.Cell(1, 1);
                    cell.Add(new Paragraph(documentationImportList[i].deviceName)).AddStyle(cellStyle);
                    table.AddCell(cell);
                    foreach (string iconName in documentationImportList[i].iconNames)
                    {
                        // documentationImportList[i].iconNames;
                        if (File.Exists(imagesDir + "icono" + iconName + ".png"))
                        {
                            ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png");
                            iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData);
                            pdfImg.SetHeight(32);
                            pdfImg.SetWidth(32);
                            table.AddCell(pdfImg);
                        }
                        else
                        {
                            table.AddCell("X");
                        }
                    }

                    for (int j = documentationImportList[i].iconNames.Count; j < 17; j++)
                    {
                        table.AddCell("");
                    }

                    DeviceIconGroup databaseItem = databaseImportList.Find(x => x.deviceName.Equals(documentationImportList[i].deviceName));
                    cell = new iText.Layout.Element.Cell(1, 1);
                    cell.Add(new Paragraph(databaseItem.deviceName)).AddStyle(cellStyle);
                    table.AddCell(cell);//.AddStyle(cellStyle);


                    foreach (string iconName in databaseItem.iconNames)
                    {
                        if (File.Exists(imagesDir + "icono" + iconName + ".png"))
                        {
                            // documentationImportList[i].iconNames;
                            ImageData imageData = ImageDataFactory.Create(imagesDir + "icono" + iconName + ".png");
                            iText.Layout.Element.Image pdfImg = new iText.Layout.Element.Image(imageData);
                            pdfImg.SetHeight(32);
                            pdfImg.SetWidth(32);
                            table.AddCell(pdfImg);
                        }
                        else
                        {
                            table.AddCell("X");
                        }
                    }


                    for (int j = 19 + databaseItem.iconNames.Count; j < 36; j++)
                    {
                        table.AddCell("");
                    }

                    if (documentationImportList[i].IsEqualTo(databaseItem))
                    {
                        cell = new iText.Layout.Element.Cell(1, 1);
                        cell.Add(new Paragraph("OK")).AddStyle(OKStyle);
                        table.AddCell(cell);
                    }
                    else
                    {
                        cell = new iText.Layout.Element.Cell(1, 1);
                        cell.Add(new Paragraph("NOK")).AddStyle(NOKStyle);
                        table.AddCell(cell);
                    }

                    this.Dispatcher.Invoke(
                        new UpdatePgBar(this.updatePgBar),
                        new object[] { (double.Parse(i.ToString()) / double.Parse(documentationImportList.Count().ToString())) * 100 }
                        );
                }

                //Create table
                document.Add(table);


                this.Dispatcher.Invoke(
                    new FinishReading(EnableWindowOptions),
                    new object[] { }
                    );
            }
        }