public TextElement(string content, float fontSize, PdfFont font, PdfColor color) { Content = content; FontSize = fontSize; Font = font; Color = color; }
/// <summary> /// Writes PDF font into file stream /// </summary> /// <param name="font">PDF font</param> internal void Write(PdfFont font) { writeBeginObject(font.ObjectId); writeBeginDictionary(); writeDictionaryEntry("/Type", "/Font"); writeDictionaryEntry("/Subtype", "/TrueType"); writeDictionaryEntry("/Name", font.GetResourceReference()); writeDictionaryEntry("/BaseFont", BASE_FONT_FORMAT.Args(font.Name)); writeDictionaryEntry("/Encoding", "/WinAnsiEncoding"); writeEndDictionary(); writeEndObject(); }
public bool Equals(PdfFont other) { if (other == null) return false; return m_Name.EqualsOrdSenseCase(other.m_Name); }
public TextElement(string content, float fontSize, PdfFont font) : this(content, fontSize, font, PdfColor.Black) { }
/// <summary> /// Add raw text to the page /// </summary> public TextElement AddText(string text, float fontSize, PdfFont font, PdfColor foreground) { var element = new TextElement(text, fontSize, font, foreground); Add(element); return element; }
/// <summary> /// Add raw text to the page /// </summary> public TextElement AddText(string text, float fontSize, PdfFont font) { return this.AddText(text, fontSize, font, PdfColor.Black); }
public bool Equals(PdfFont other) { if (other == null) return false; return string.Equals(this.m_Name, other.m_Name, StringComparison.Ordinal); }
/// <summary> /// Add raw text to the page /// </summary> public TextElement AddText(string text, float fontSize, PdfFont font) { return(this.AddText(text, fontSize, font, PdfColor.Black)); }
private void button7_Click(object sender, EventArgs e) { var document = new PdfDocument(); document.Fonts.Add(PdfFont.Helvetica); document.Fonts.Add(PdfFont.HelveticaBold); document.Fonts.Add(PdfFont.HelveticaOblique); document.Fonts.Add(PdfFont.HelveticaBoldOblique); document.Fonts.Add(PdfFont.Courier); document.Fonts.Add(PdfFont.CourierBold); document.Fonts.Add(PdfFont.CourierOblique); document.Fonts.Add(PdfFont.CourierBoldOblique); document.Fonts.Add(PdfFont.Times); document.Fonts.Add(PdfFont.TimesBold); document.Fonts.Add(PdfFont.TimesItalic); document.Fonts.Add(PdfFont.TimesBoldItalic); var arial = new PdfFont("Arial"); var verdana = new PdfFont("Verdana"); var calibri = new PdfFont("Calibri"); var segoeUI = new PdfFont("SegoeUI"); var tahoma = new PdfFont("Tahoma"); var stencil = new PdfFont("Stencil"); var castellar = new PdfFont("Castellar"); var monaco = new PdfFont("Monaco"); document.Fonts.Add(arial); document.Fonts.Add(verdana); document.Fonts.Add(calibri); document.Fonts.Add(segoeUI); document.Fonts.Add(tahoma); document.Fonts.Add(stencil); document.Fonts.Add(castellar); document.Fonts.Add(monaco); var page = document.AddPage(); var predefinedFonts = new Dictionary<string, PdfFont> { { "Helvetica", PdfFont.Helvetica }, { "Helvetica-Bold", PdfFont.HelveticaBold }, { "Helvetica-Oblique", PdfFont.HelveticaOblique }, { "Helvetica-BoldOblique", PdfFont.HelveticaBoldOblique }, { "Courier", PdfFont.Courier }, { "Courier-Bold", PdfFont.CourierBold }, { "Courier-Oblique", PdfFont.CourierOblique }, { "Courier-BoldOblique", PdfFont.CourierBoldOblique }, { "Times-Roman", PdfFont.Times }, { "Times-Bold", PdfFont.TimesBold }, { "Times-Italic", PdfFont.TimesItalic }, { "Times-BoldItalic", PdfFont.TimesBoldItalic } }; var otherFonts = new Dictionary<string, PdfFont> { { "Arial", arial }, { "Verdana", verdana }, { "Calibri", calibri }, { "SegoeUI", segoeUI }, { "Tahoma", tahoma }, { "Stencil", stencil }, { "Castellar", castellar }, { "Monaco", monaco } }; var text = page.AddText(@"Predefined Fonts (Courier is monospaced):", 20, PdfFont.Times); text.X = 30; text.Y = 730; var top = text.Y - 10; foreach (var font in predefinedFonts) { top -= 12; text = page.AddText(font.Key + ": ", 10, PdfFont.Times); text.X = 30; text.Y = top; text = page.AddText("Lenin is alive", 10, font.Value); text.X = 140; text.Y = top; } top -= 40; text = page.AddText(@"Some other Fonts (Monaco is monospaced):", 20, PdfFont.Times); text.X = 50; text.Y = top; top -= 10; foreach (var font in otherFonts) { top -= 12; text = page.AddText(font.Key + ": ", 10, PdfFont.Times); text.X = 30; text.Y = top; text = page.AddText("Lenin is alive", 10, font.Value); text.X = 140; text.Y = top; } document.Save(@"test.pdf"); Process.Start(@"test.pdf"); }