public virtual void HyphenSymbolTest01() { String outFileName = destinationFolder + "hyphenSymbolTest01.pdf"; String cmpFileName = sourceFolder + "cmp_hyphenSymbolTest01.pdf"; PdfDocument pdfDoc = new PdfDocument(new PdfWriter(outFileName)); Document doc = new Document(pdfDoc); PdfFont font = PdfFontFactory.CreateFont(fontsFolder + "FreeSans.ttf", PdfEncodings.IDENTITY_H, true); Style style = new Style(); style.SetBorder(new SolidBorder(ColorConstants.BLACK, 1)); style.SetHyphenation(new HyphenationConfig("en", "EN", 2, 2)); style.SetFont(font); style.SetBackgroundColor(ColorConstants.RED); doc.Add(new Paragraph("tre\u2011").SetWidth(19).AddStyle(style)); doc.Add(new Paragraph("tre\u2011\u2011").SetWidth(19).AddStyle(style)); doc.Add(new Paragraph("r\u2011\u2011m").SetWidth(19).AddStyle(style)); doc.Add(new Paragraph("r\u2011\u2011\u2011\u2011\u2011\u2011mmma").SetWidth(19).AddStyle(style)); style.SetBackgroundColor(ColorConstants.BLUE); doc.Add(new Paragraph("tre\u2011\u2011").SetWidth(22).AddStyle(style)); doc.Add(new Paragraph("tre\u2011\u2011m").SetWidth(22).AddStyle(style)); doc.Add(new Paragraph("\n\n\n")); style.SetBackgroundColor(ColorConstants.GREEN); doc.Add(new Paragraph("e\u2011\u2011m\u2011ma").SetWidth(20).AddStyle(style)); doc.Add(new Paragraph("tre\u2011\u2011m\u2011ma").SetWidth(20).AddStyle(style)); doc.Add(new Paragraph("tre\u2011\u2011m\u2011ma").SetWidth(35).AddStyle(style)); doc.Add(new Paragraph("tre\u2011\u2011m\u2011ma").SetWidth(40).AddStyle(style)); style.SetBackgroundColor(ColorConstants.YELLOW); doc.Add(new Paragraph("ar\u2011ma").SetWidth(22).AddStyle(style)); doc.Add(new Paragraph("ar\u2011ma").SetWidth(15).AddStyle(style)); doc.Add(new Paragraph("ar\u2011").SetWidth(14).AddStyle(style)); doc.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
public virtual void LineSeparatorBackgroundTest01() { String outFileName = destinationFolder + "lineSeparatorBackgroundTest01.pdf"; String cmpFileName = sourceFolder + "cmp_lineSeparatorBackgroundTest01.pdf"; PdfDocument pdf = new PdfDocument(new PdfWriter(outFileName)); Document document = new Document(pdf); Style style = new Style(); style.SetBackgroundColor(ColorConstants.YELLOW); style.SetMargin(10); document.Add(new LineSeparator(new SolidLine()).AddStyle(style)); document.Add(new LineSeparator(new DashedLine()).SetBackgroundColor(ColorConstants.RED)); document.Close(); NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder , "diff")); }
private static Table GetGraficoIndividual(Grafico grafico) { // 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 de las celdas de encabezado. iText.Layout.Style estiloEncabezados = new iText.Layout.Style(); estiloEncabezados.SetBackgroundColor(new DeviceRgb(112, 173, 71)) .SetBold() .SetFontSize(8); // Creamos la tabla float[] ancho = new float[] { 10, 10, 60, 10, 10 }; Table tabla = new Table(UnitValue.CreatePercentArray(ancho)); // Asignamos el estilo a la tabla. tabla.AddStyle(estiloTabla); // Añadimos las celdas de encabezado. tabla.AddHeaderCell(new Cell().Add(new Paragraph("Inicio")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Línea")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Descripción")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Final")).AddStyle(estiloEncabezados)); tabla.AddHeaderCell(new Cell().Add(new Paragraph("Tiempo")).AddStyle(estiloEncabezados)); // Añadimos los datos del gráfico int indice = 1; foreach (var valoracion in grafico.ListaValoraciones) { // 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++; // Escribimos el grafico. tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(valoracion.Inicio, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(valoracion.Linea == 0 ? "" : valoracion.Linea.ToString())}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{valoracion.Descripcion}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(valoracion.Final, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); tabla.AddCell(new Cell().Add(new Paragraph($"{(string)cnvHora.Convert(valoracion.Tiempo, null, VerValores.NoCeros, null)}")) .AddStyle(estiloFondo)); } // Ponemos los bordes de la tabla. tabla.GetHeader().SetBorder(new SolidBorder(1)); tabla.SetBorder(new SolidBorder(1)); // Devolvemos la tabla. return(tabla); }
// ==================================================================================================== #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); }