private Phrase Render(HeadingBlock block) { var fonts = new iTextSharp.text.Font[] { Header1Font, Header2Font, Header3Font, Header4Font, Header5Font, Header6Font }; var colors = new iTextSharp.text.Color[] { new iTextSharp.text.Color(0x9B1C47), new iTextSharp.text.Color(0, 0, 0), new iTextSharp.text.Color(0, 0, 0), new iTextSharp.text.Color(0, 0, 0), new iTextSharp.text.Color(0, 0, 0), new iTextSharp.text.Color(0, 0, 0) }; return(CreateFormatted(block.Inline, fonts[block.Level - 1], 0, colors[block.Level - 1])); }
public static TextElement Parse(PdfDocument pdfDocument, Models.Text.TextElement bTextElement) { Font font = new Font(pdfDocument.Fonts[bTextElement.FontStyle.Font.Key + "_" + bTextElement.FontStyle.Key].Font); font.Size = bTextElement.FontSize.Points; iTextSharp.text.Color color = pdfDocument.Colors[bTextElement.Color.Key].RGBColor; return(new TextElement(font, bTextElement, color)); }
public PdfCell(PdfPTable table, string data, Color color, int columnSpan) { this.AddData(data, defaultFont); this.SetAllBorders(); this.BackgroundColor = color; this.Colspan = columnSpan; table.AddCell(this.CreatePdfPCell()); }
private PdfPCell getNewCell(string Texto, iTextSharp.text.Font Fonte, int Alinhamento, float Espacamento, int Borda, Color CorBorda) { return(getNewCell(Texto, Fonte, Alinhamento, Espacamento, Borda, CorBorda, Color.BLACK)); }
private PdfPCell getNewCell(string Texto, iTextSharp.text.Font Fonte, int Alinhamento, float Espacamento, int Borda, Color CorBorda, Color CorFundo) { var cell = new PdfPCell(new Phrase(Texto, Fonte)); cell.HorizontalAlignment = Alinhamento; cell.Padding = Espacamento; cell.Border = Borda; cell.BorderColor = CorBorda; cell.BackgroundColor = CorFundo; return(cell); }
/// <summary> /// Fonts the multiplier. /// This will rewrite a font which inherited from a parent style. /// </summary> /// <param name="textProperties">The text properties.</param> /// <param name="font">The font.</param> /// <returns>The new font.</returns> public static Font FontMultiplier(TextProperties textProperties, Font font) { try { string fontName = ""; if (textProperties.FontName != null) { fontName = textProperties.FontName; } else { fontName = font.Familyname; } string colorStr = "#000000"; int iTextFontStyle = 0; //normal int bold = (textProperties.Bold != null && textProperties.Bold.ToLower() == "bold") ? 1 : 0; int italic = (textProperties.Italic != null && textProperties.Bold.ToLower() == "italic") ? 1 : 0; float size = font.Size; // up to now, standard todo: do it better if (textProperties.FontSize != null) { if (textProperties.FontSize.ToLower().EndsWith("%")) { try { float percent = (float)Convert.ToDouble(textProperties.FontSize.ToLower().Replace("%", "")); size *= (percent / 100.0f); } catch (Exception) { throw; } } } if (textProperties.FontColor != null) { colorStr = textProperties.FontColor; } if (bold == 1 && italic == 1) { iTextFontStyle = Font.BOLDITALIC; } if (bold == 1 && italic == 0) { iTextFontStyle = Font.BOLD; } if (bold == 0 && italic == 1) { iTextFontStyle = Font.ITALIC; } // TODO: underline strike through iTextSharp.text.Color color = RGBColorConverter.GetColorFromHex(colorStr); font = FontFactory.GetFont(fontName, size, iTextFontStyle, color); return(font); } catch (Exception) { throw; } }
/// <summary> /// Gets the font object. /// </summary> /// <param name="textProperties">The text properties.</param> /// <returns>The font object</returns> public static Font GetFont(TextProperties textProperties) { try { Font font = new Font(); if (textProperties != null) { string fontName = ""; if (textProperties.FontName != null) { fontName = textProperties.FontName; } else { fontName = DefaultDocumentStyles.Instance().DefaultTextFont.Familyname; } if (FontFactory.Contains(fontName)) { string colorStr = "#000000"; int iTextFontStyle = 0; //normal int bold = (textProperties.Bold != null && textProperties.Bold.ToLower() == "bold") ? 1 : 0; int italic = (textProperties.Italic != null && textProperties.Bold.ToLower() == "italic") ? 1 : 0; int textLineThrough = (textProperties.TextLineThrough != null) ? 1 : 0; int underline = (textProperties.Underline != null) ? 1 : 0; float size = 12.0f; // up to now, standard todo: do it better if (textProperties.FontSize != null) { if (textProperties.FontSize.ToLower().EndsWith("pt")) { try { size = (float)Convert.ToDouble(textProperties.FontSize.ToLower().Replace("pt", "")); } catch (Exception) { throw; } } } if (textProperties.FontColor != null) { colorStr = textProperties.FontColor; } if (bold == 1 && italic == 1) { iTextFontStyle = Font.BOLDITALIC; } if (bold == 1 && italic == 0) { iTextFontStyle = Font.BOLD; } if (bold == 0 && italic == 1) { iTextFontStyle = Font.ITALIC; } // TODO: underline strike through iTextSharp.text.Color color = RGBColorConverter.GetColorFromHex(colorStr); font = FontFactory.GetFont(fontName, size, iTextFontStyle, color); } } return(font); } catch (Exception) { throw; } }
public void DrawLine(PdfWriter writer, float x1, float y1, float x2, float y2, iTextSharp.text.Color color) { PdfContentByte contentByte = writer.DirectContent; contentByte.SetColorStroke(color); contentByte.MoveTo(x1, y1); contentByte.LineTo(x2, y2); contentByte.Stroke(); }
private void EscrevaProcessosNoDocumentoSintetico() { var tabela = new Table(4); tabela.Widths = new Single[] { 60, 100, 60, 100 }; tabela.Padding = 1; tabela.Spacing = 0; tabela.Width = 100; tabela.AutoFillEmptyCells = true; var corBackgroudHeader = new Color(211, 211, 211); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Número do processo", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Marca", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Despacho", _Fonte2, Cell.ALIGN_CENTER, 0, corBackgroudHeader, true)); tabela.AddCell(iTextSharpUtilidades.CrieCelula("Cliente", _Fonte2, Cell.ALIGN_LEFT, 0, corBackgroudHeader, true)); tabela.EndHeaders(); foreach (var processo in _processos) { tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Processo.ToString(), _Fonte1, Cell.ALIGN_CENTER, 0, false)); if (processo.Marca != null && !string.IsNullOrEmpty(processo.Marca.DescricaoDaMarca)) tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.DescricaoDaMarca, _Fonte1, Cell.ALIGN_LEFT, 0, false)); else tabela.AddCell(iTextSharpUtilidades.CrieCelula(string.Empty, _Fonte1, Cell.ALIGN_LEFT, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Despacho != null ? processo.Despacho.CodigoDespacho : "", _Fonte1, Cell.ALIGN_CENTER, 0, false)); tabela.AddCell(iTextSharpUtilidades.CrieCelula(processo.Marca.Cliente.Pessoa.Nome, _Fonte1, Cell.ALIGN_LEFT, 0, false)); } _documento.Add(tabela); }
private Phrase CreateFormatted(ContainerInline inlines, iTextSharp.text.Font fontFamily, int fontStyle, iTextSharp.text.Color fontColor) { var phrase = new Phrase(); foreach (var inline in inlines) { var spans = CreateChunks(inline, fontFamily, fontStyle, fontColor); if (spans != null) { foreach (var span in spans) { phrase.Add(span); } } } return(phrase); }
public static void AdicionaCelula(Tabela tabela, string texto, string BaseFont_, int tamanho, iTextSharp.text.Color cor, int colunas) { Chunk chunk = new Chunk(texto, FontFactory.GetFont(BaseFont_, tamanho)); PdfPCell cell = new PdfPCell(new Paragraph(chunk)); cell.BackgroundColor = cor; cell.Colspan = colunas; tabela.AddCell(cell); }
/// <summary> /// Constructs a Font-object. /// </summary> /// <param name="fontname">the name of the font</param> /// <param name="size">the size of this font</param> /// <param name="color">the Color of this font</param> /// <returns>a Font object</returns> public virtual Font GetFont(string fontname, float size, Color color) { return GetFont(fontname, defaultEncoding, defaultEmbedding, size, Font.UNDEFINED, color); }
/// <summary> /// Constructs a Font-object. /// </summary> /// <param name="fontname">the name of the font</param> /// <param name="size">the size of this font</param> /// <param name="style">the style of this font</param> /// <param name="color">the Color of this font</param> /// <returns>a Font object</returns> public virtual Font GetFont(string fontname, float size, int style, Color color) { return GetFont(fontname, defaultEncoding, defaultEmbedding, size, style, color); }
/// <summary> /// Constructs a Font-object. /// </summary> /// <param name="attributes">the attributes of a Font object</param> /// <returns>a Font object</returns> public virtual Font GetFont(Properties attributes) { string fontname = null; string encoding = defaultEncoding; bool embedded = defaultEmbedding; float size = Font.UNDEFINED; int style = Font.NORMAL; Color color = null; string value = attributes[Markup.HTML_ATTR_STYLE]; if (value != null && value.Length > 0) { Properties styleAttributes = Markup.ParseAttributes(value); if (styleAttributes.Count == 0) { attributes.Add(Markup.HTML_ATTR_STYLE, value); } else { fontname = styleAttributes[Markup.CSS_KEY_FONTFAMILY]; if (fontname != null) { string tmp; while (fontname.IndexOf(',') != -1) { tmp = fontname.Substring(0, fontname.IndexOf(',')); if (IsRegistered(tmp)) { fontname = tmp; } else { fontname = fontname.Substring(fontname.IndexOf(',') + 1); } } } if ((value = styleAttributes[Markup.CSS_KEY_FONTSIZE]) != null) { size = Markup.ParseLength(value); } if ((value = styleAttributes[Markup.CSS_KEY_FONTWEIGHT]) != null) { style |= Font.GetStyleValue(value); } if ((value = styleAttributes[Markup.CSS_KEY_FONTSTYLE]) != null) { style |= Font.GetStyleValue(value); } if ((value = styleAttributes[Markup.CSS_KEY_COLOR]) != null) { color = Markup.DecodeColor(value); } attributes.AddAll(styleAttributes); } } if ((value = attributes[ElementTags.ENCODING]) != null) { encoding = value; } if ("true".Equals(attributes[ElementTags.EMBEDDED])) { embedded = true; } if ((value = attributes[ElementTags.FONT]) != null) { fontname = value; } if ((value = attributes[ElementTags.SIZE]) != null) { size = float.Parse(value, System.Globalization.NumberFormatInfo.InvariantInfo); } if ((value = attributes[Markup.HTML_ATTR_STYLE]) != null) { style |= Font.GetStyleValue(value); } if ((value = attributes[ElementTags.STYLE]) != null) { style |= Font.GetStyleValue(value); } string r = attributes[ElementTags.RED]; string g = attributes[ElementTags.GREEN]; string b = attributes[ElementTags.BLUE]; if (r != null || g != null || b != null) { int red = 0; int green = 0; int blue = 0; if (r != null) red = int.Parse(r); if (g != null) green = int.Parse(g); if (b != null) blue = int.Parse(b); color = new Color(red, green, blue); } else if ((value = attributes[ElementTags.COLOR]) != null) { color = Markup.DecodeColor(value); } if (fontname == null) { return GetFont(null, encoding, embedded, size, style, color); } return GetFont(fontname, encoding, embedded, size, style, color); }
/** * Constructs a Font-object. * * @param fontname the name of the fontparam * @param encoding the encoding of the font * @param embedded true if the font is to be embedded in the PDF * @param size the size of this font * @param style the style of this font * @param color the Color of this font * @param cached true if the font comes from the cache or is added to the cache if new, false if the font is always created new * @returns a Font object */ public virtual Font GetFont(string fontname, string encoding, bool embedded, float size, int style, Color color, bool cached) { if (fontname == null) return new Font(Font.UNDEFINED, size, style, color); string lowercasefontname = fontname.ToLower(CultureInfo.InvariantCulture); ArrayList tmp = (ArrayList) fontFamilies[lowercasefontname]; if (tmp != null) { // some bugs were fixed here by Daniel Marczisovszky int fs = Font.NORMAL; bool found = false; int s = style == Font.UNDEFINED ? Font.NORMAL : style; foreach (string f in tmp) { string lcf = f.ToLower(CultureInfo.InvariantCulture); fs = Font.NORMAL; if (lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("bold") != -1) fs |= Font.BOLD; if (lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("italic") != -1 || lcf.ToLower(CultureInfo.InvariantCulture).IndexOf("oblique") != -1) fs |= Font.ITALIC; if ((s & Font.BOLDITALIC) == fs) { fontname = f; found = true; break; } } if (style != Font.UNDEFINED && found) { style &= ~fs; } } BaseFont basefont = null; try { try { // the font is a type 1 font or CJK font basefont = BaseFont.CreateFont(fontname, encoding, embedded, cached, null, null, true); } catch (DocumentException) { } if (basefont == null) { // the font is a true type font or an unknown font fontname = trueTypeFonts[fontname.ToLower(CultureInfo.InvariantCulture)]; // the font is not registered as truetype font if (fontname == null) return new Font(Font.UNDEFINED, size, style, color); // the font is registered as truetype font basefont = BaseFont.CreateFont(fontname, encoding, embedded, cached, null, null); } } catch (DocumentException de) { // this shouldn't happen throw de; } catch (System.IO.IOException) { // the font is registered as a true type font, but the path was wrong return new Font(Font.UNDEFINED, size, style, color); } catch { // null was entered as fontname and/or encoding return new Font(Font.UNDEFINED, size, style, color); } return new Font(basefont, size, style, color); }
/// <summary> /// Constructs a Font-object. /// </summary> /// <param name="fontname">the name of the font</param> /// <param name="encoding">the encoding of the font</param> /// <param name="embedded">true if the font is to be embedded in the PDF</param> /// <param name="size">the size of this font</param> /// <param name="style">the style of this font</param> /// <param name="color">the Color of this font</param> /// <returns>a Font object</returns> public virtual Font GetFont(string fontname, string encoding, bool embedded, float size, int style, Color color) { return GetFont(fontname, encoding, embedded, size, style, color, true); }
// protected void AddFontsToDocument(iTS.Document doc, iTS.pdf.PdfWriter pdfWriter) //{ //} protected static iTS.Font GetFont(String fontFamily, float size, iTS.Color color) { return(GetFont(fontFamily, size, iTS.Font.NORMAL, color)); }
protected static iTS.Font GetFont(String fontFamily, float size, int style, iTS.Color color) { return(iTS.FontFactory.GetFont(fontFamily, size, style, color)); }
private IEnumerable <Chunk> CreateChunks(Inline inline, iTextSharp.text.Font fontFamily, int fontStyle, iTextSharp.text.Color fontColor) { switch (inline) { case LiteralInline literal: return(new Chunk[] { new Chunk() { Content = literal.Content.Text.Substring(literal.Content.Start, literal.Content.Length), Font = new iTextSharp.text.Font(fontFamily.BaseFont, fontFamily.Size, fontStyle, fontColor) } }); case EmphasisInline emphasis: var childStyle = fontStyle | (emphasis.DelimiterCount == 2 ? iTextSharp.text.Font.BOLD : iTextSharp.text.Font.ITALIC); var espans = emphasis.SelectMany(x => CreateChunks(x, fontFamily, childStyle, fontColor)); return(espans.ToArray()); case LineBreakInline breakline: return(new Chunk[] { Chunk.NEWLINE }); case LinkInline link: return(link.SelectMany(x => CreateChunks(x, fontFamily, fontStyle, fontColor))); case CodeInline code: case HtmlInline html: default: return(new Chunk[] { }); } //var cb = stamper.GetOverContent(1); ////ColumnText.ShowTextAligned(cb, iTextSharp.text.Element.ALIGN_LEFT, new Phrase("Galefrin"), 40, 40, 0); //ColumnText ct = new ColumnText(cb); //ct.SetSimpleColumn(10f, 48f, 200f, 600f); //Font f = new Font(); //Paragraph pz = new Paragraph(new Phrase(20, "Hello World!", f)); //ct.AddElement(pz); //ct.Go(); //BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, "Cp1252", BaseFont.EMBEDDED); //f = new Font(bf, 13); //ct = new ColumnText(cb); //ct.SetSimpleColumn(10f, 48f, 200f, 700f); //pz = new Paragraph("Hello World!", f); //ct.AddElement(pz); //ct.Go(); //return; /* * var text = block.ToMarkdownString(); * //DrawText(content, md, null, 100, 100, 300, 300, 0); * * float x = 10; * float y = 10; * float width = 300; * float height = 300; * cb.SetRGBColorFill(127, 127, 127); * //cb.Rectangle(x, y, width, height); * //cb.Stroke(); * ColumnText ct = new ColumnText(cb); * ct.SetSimpleColumn(x, y, x + width, y + height); * * Font font = new Font(BaseFont.CreateFont()); * //int rectWidth = 80; * //float maxFontSize = getMaxFontSize(BaseFont.CreateFont(), "text", rectWidth); * font.Size = 20; * * * var p = new Paragraph(text, font); * //p.Alignment = alignment; * ct.AddElement(p); * ct.Go(); * * * * //var style = this.Theme.Paragraph; * //var foregroundColor = isQuoted ? this.Theme.Quote.ForegroundColor : style.ForegroundColor; * //var label = new Label * //{ * // FormattedText = CreateFormatted(block.Inline, style.FontFamily, style.Attributes, foregroundColor, style.BackgroundColor, style.FontSize), * //}; * //AttachLinks(label); * //this.stack.Children.Add(label); */ }
private void CreatePDFFile(string p) { if (new Java.IO.File(p).Exists()) { new Java.IO.File(p).Delete(); } try { Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(p, FileMode.Create)); document.Open(); document.SetPageSize(PageSize.A4); document.AddCreationDate(); //document.AddAuthor("DebWeb"); //document.AddCreator("Deb"); Color colorAccesnt = new Color(0, 32, 64, 96); float fontSize = 24.0f, valueFontSize = 26.0f; BaseFont fontName = BaseFont.CreateFont(Common.GetFilePath(this, "nunitosans.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED); //BaseFont fontName = FontFactory.GetFont(Common.GetFilePath(this, "PlayfairDisplay-Regular.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); //Font f1 = FontFactory.GetFont(Common.GetFilePath(this, "PlayfairDisplay-Regular.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12); Font titleFont = new Font(fontName, 33.0f, Font.NORMAL, colorAccesnt); Font expenseNameFont = new Font(fontName, fontSize, Font.NORMAL, Color.BLACK); Font expenseValueFont = new Font(fontName, valueFontSize, Font.NORMAL, colorAccesnt); AddNewItem(document, "REPORT", Element.ALIGN_CENTER, titleFont); AddNewItem(document, "Report for the month/year: " + SelectedMonth + " " + SelectedYear, Element.ALIGN_LEFT, expenseNameFont); AddNewItem(document, "Report date: " + DateTime.UtcNow.ToString(), Element.ALIGN_LEFT, expenseNameFont); AddNewItem(document, "Report generated by: " + CurrentUserDisplayName, Element.ALIGN_LEFT, expenseNameFont); AddLineSeparator(document); AddNewItem(document, "Expense Details", Element.ALIGN_CENTER, titleFont); foreach (var item in lstPieChartData) { AddNewItemWithLeftAndRight(document, item.ExpenseCategory, prefs.GetString("CurrencySymbolSelected", "") + item.Amount, expenseValueFont, expenseValueFont); AddNewItem(document, item.ExpenseDescription, Element.ALIGN_LEFT, expenseNameFont); string[] datevalue = item.ExpenseDate.Split(","); AddNewItem(document, datevalue[0] + " " + datevalue[1], Element.ALIGN_LEFT, expenseNameFont); AddLineSeparator(document); } AddLineSpace(document); AddLineSpace(document); AddNewItemWithLeftAndRight(document, "Total Expense", prefs.GetString("CurrencySymbolSelected", "") + lstPieChartDataValue.Sum(x => Convert.ToDouble(x.Total)).ToString(), titleFont, titleFont); document.Close(); PrintPDF(); } catch (FileNotFoundException e) { Log.Debug("", e.Message); } catch (DocumentException e) { Log.Debug("", e.Message); } catch (IOException e) { Log.Debug("", e.Message); } }
/// <summary> /// Obtiene la tabla de datos de la programacion de corte /// </summary> /// <param name="datos"></param> /// <returns></returns> private PdfPTable ObtenerTablaProgramacion(ImpresionProgramacionCorteInfo datos) { var tabla = new PdfPTable(10); //Tamaño de las culumnas float[] medidaCeldas = { 0.07f, 0.08f, 0.30f, 0.07f, 0.05f, 0.05f, 0.13f, 0.05f, 0.10f, 0.10f }; tabla.SetWidths(medidaCeldas); var cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncCorral, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncPartida, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncOrigen, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncCabezas, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncMachos, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncHembras, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncFechaEntrada, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncDias, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncEvaluacion, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncGarrapata, fuenteTitulo)); cell.Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; tabla.AddCell(cell); //Llenado de datos int i = 0; int res = 0; var color1 = new Color(250, 250, 250); var color2 = new Color(237, 237, 237); foreach (var prog in datos.ProgramacionCorte) { res = i % 2; cell = new PdfPCell(new Phrase(prog.CodigoCorral, fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.FolioEntradaID.ToString(), fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.OrganizacionNombre, fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.CabezasRecibidas.ToString(), fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.Machos.ToString(), fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.Hembras.ToString(), fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.FechaEntrada, fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.Dias.ToString(), fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.Evaluacion, fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(prog.LeyendaNivelGarrapata, fuenteDatos)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); i++; } res = i % 2; //Resumen cell = new PdfPCell(new Phrase(String.Empty, fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(String.Empty, fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(ResourceServices.ProgramacionCorteImpresion_EncTotalTitulo, fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_LEFT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(datos.TotalRecibidas.ToString(), fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(datos.TotalMachos.ToString(), fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(datos.TotalHembras.ToString(), fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_RIGHT; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(String.Empty, fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(String.Empty, fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(String.Empty, fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); cell = new PdfPCell(new Phrase(String.Empty, fuenteTitulo)); cell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER; cell.BorderWidth = 1; cell.HorizontalAlignment = Element.ALIGN_CENTER; cell.BackgroundColor = res == 0 ? color1 : color2; tabla.AddCell(cell); return(tabla); }
private void GenerateDocument(FormModel form, string file, string fontFile) { try { Document document = new Document(); PdfWriter.GetInstance(document, new FileStream(file, FileMode.Create)); document.Open(); document.SetPageSize(PageSize.A4); document.SetMargins(0f, 0f, 0f, 0f); document.AddCreationDate(); document.AddCreator("WalkOut"); iTextSharp.text.Color fontColor = new iTextSharp.text.Color(System.Drawing.Color.Black); BaseFont fontName = BaseFont.CreateFont(fontFile, "UTF-8", BaseFont.EMBEDDED); iTextSharp.text.Font boldFont = new iTextSharp.text.Font(fontName, 10.0f, iTextSharp.text.Font.BOLD, fontColor); iTextSharp.text.Font standardFont = new iTextSharp.text.Font(fontName, 10.0f, iTextSharp.text.Font.NORMAL, fontColor); iTextSharp.text.Font titleFont = new iTextSharp.text.Font(fontName, 16.0f, iTextSharp.text.Font.BOLD, fontColor); iTextSharp.text.Font paragraphFont = new iTextSharp.text.Font(fontName, 10.0f, iTextSharp.text.Font.NORMAL, fontColor); iTextSharp.text.Font spaceFont = new iTextSharp.text.Font(fontName, 6.0f, iTextSharp.text.Font.NORMAL, fontColor); AddNewItem(document, "DECLARATIE PE PROPRIE RASPUNDERE", iTextSharp.text.Element.ALIGN_CENTER, titleFont); AddSpace(document, paragraphFont); AddNewItem(document, "Nume, prenume: " + form.NumePrenume, iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); AddNewItem(document, "Data nasterii: " + form.DataNasterii, iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); AddNewItem(document, "Adresa locuintei: " + form.Adresa, iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); AddNewItem(document, "Locul/locurile deplasarii: " + form.LocDeplasare, iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); AddSpace(document, paragraphFont); AddNewItem(document, "Motivul deplasarii:", iTextSharp.text.Element.ALIGN_LEFT, boldFont); if (form.InteresProfesional) { AddNewItem(document, " >> Interes profesional, inclusiv intre locuinta/gospodarie si locul/locurile de desfasurare a activitatii profesionale si inapoi", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.AsigurareBunuri) { AddNewItem(document, " >> Asigurarea de bunuri care acopera necesitatile de baza ale persoanelor si animalelor de companie/domestice", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.AsistentaMedicala) { AddNewItem(document, " >> Asistenta medicala care nu poate fi amanata si nici realizata de la distanta", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.MotiveJustificate) { AddNewItem(document, " >> Motive justificate, precum ingrijirea/insotirea unui minor/copilului, asistenta persoanelor varstnice, bolnave sau cu dizabilitati ori deces al unui membru de familie", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.ActivitateFizica) { AddNewItem(document, " >> Activitate fizica individuala (cu excluderea oricaror activitati sportive de echipa/colective) sau pentru nevoile animalelor de companie/domestice, in apropierea locuintei", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.ActivitatiAgricole) { AddNewItem(document, " >> Realizarea de activitati agricole", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.DonareSange) { AddNewItem(document, " >> Donarea de sange, la centrele de transfuzie sanguina", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.ScopuriUmanitare) { AddNewItem(document, " >> Scopuri umanitare sau de voluntariat", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.ComertAgricole) { AddNewItem(document, " >> Comercializarea de produse agroalimentare (in cazul producatorilor agricoli)", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } if (form.BunuriActivitateProfesionala) { AddNewItem(document, " >> Asigurarea de bunuri necesare desfasurarii activitatii profesionale", iTextSharp.text.Element.ALIGN_LEFT, paragraphFont); } AddSpace(document, paragraphFont); AddNewItemLeftAndRight(document, "Data declaratiei: " + form.DataDeclaratiei, "Semnatura", boldFont); AddImage(document, CommonData._folderPath + "img.png"); document.Close(); Toast.MakeText(MainActivity.AppContext, "Declaratie generata", ToastLength.Short).Show(); PrintDocument(file); } catch (FileNotFoundException e) { Log.Debug("PDF Printer", e.Message); } catch (DocumentException e) { Log.Debug("PDF Printer", e.Message); } catch (IOException e) { Log.Debug("PDF Printer", e.Message); } }