static void Main(string[] args) { // Create a new PDF document PdfDocument document = new PdfDocument(); // Create an empty page PdfPage page = document.AddPage(); //page.Contents.CreateSingleContent().Stream.UnfilteredValue; // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); // Create a font XFont font = new XFont("Arial", 20, XFontStyle.Bold, options); // Draw the text gfx.DrawString("Hello, World!", font, XBrushes.Black, new XRect(0, 0, page.Width, page.Height), XStringFormats.Center); // Save the document... string filename = "HelloWorld.pdf"; document.Save(filename); // ...and start a viewer. Process.Start(filename); }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string facename = "Times"; XFont fontR = new XFont(facename, 40); XFont fontB = new XFont(facename, 40, XFontStyle.Bold); XFont fontI = new XFont(facename, 40, XFontStyle.Italic); XFont fontBI = new XFont(facename, 40, XFontStyle.Bold | XFontStyle.Italic); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); double x = 80; XPen pen = XPens.SlateBlue; gfx.DrawLine(pen, x, 100, x, 600); gfx.DrawLine(pen, x - 50, 200, 400, 200); gfx.DrawLine(pen, x - 50, 300, 400, 300); gfx.DrawLine(pen, x - 50, 400, 400, 400); gfx.DrawLine(pen, x - 50, 500, 400, 500); double lineSpace = fontR.GetHeight(gfx); int cellSpace = fontR.FontFamily.GetLineSpacing(fontR.Style); int cellAscent = fontR.FontFamily.GetCellAscent(fontR.Style); int cellDescent = fontR.FontFamily.GetCellDescent(fontR.Style); double cyAscent = lineSpace * cellAscent / cellSpace; XFontMetrics metrics = fontR.Metrics; XSize size; gfx.DrawString("Times 40", fontR, this.properties.Font1.Brush, x, 200); size = gfx.MeasureString("Times 40", fontR); gfx.DrawLine(this.properties.Pen3.Pen, x, 200, x + size.Width, 200); gfx.DrawString("Times bold 40", fontB, this.properties.Font1.Brush, x, 300); size = gfx.MeasureString("Times bold 40", fontB); //gfx.DrawLine(this.properties.Pen3.Pen, x, 300, x + size.Width, 300); gfx.DrawString("Times italic 40", fontI, this.properties.Font1.Brush, x, 400); size = gfx.MeasureString("Times italic 40", fontI); //gfx.DrawLine(this.properties.Pen3.Pen, x, 400, x + size.Width, 400); gfx.DrawString("Times bold italic 40", fontBI, this.properties.Font1.Brush, x, 500); size = gfx.MeasureString("Times bold italic 40", fontBI); //gfx.DrawLine(this.properties.Pen3.Pen, x, 500, x + size.Width, 500); #if true___ // Check Malayalam XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont Kartika = new XFont("Kartika", 20, XFontStyle.Regular, options); XFont AnjaliOldLipi = new XFont("AnjaliOldLipi", 20, XFontStyle.Regular, options); gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", Kartika, this.properties.Font1.Brush, x, 600); gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", AnjaliOldLipi, this.properties.Font1.Brush, x, 650); #endif }
static void Main() { // Create new document PdfDocument document = new PdfDocument(); // Set font encoding to unicode XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options); // Draw text in different languages for (int idx = 0; idx < texts.Length; idx++) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XTextFormatter tf = new XTextFormatter(gfx); tf.Alignment = XParagraphAlignment.Left; tf.DrawString(texts[idx], font, XBrushes.Black, new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft); } const string filename = "Unicode_tempfile.pdf"; // Save the document... document.Save(filename); // ...and start a viewer. Process.Start(filename); }
/// <summary> /// New... /// </summary> public OpenTypeDescriptor(string fontDescriptorKey, string name, XFontStyle stlye, OpenTypeFontface fontface, XPdfFontOptions options) : base(fontDescriptorKey) { FontFace = fontface; FontName = name; Initialize(); }
public BadgePdfBuilder(List<Badge> badges) { this.allBadges = badges; this.allRects = new List<XRect>(); this.badgeCount = 0; this.badgeWidth = Unit.FromInch(3.3); this.badgeHeight = Unit.FromInch(2.1); // Each badge area is split into 9 even rows and 13 even columns. this.rowHeight = this.badgeHeight / 9; this.columnWidth = this.badgeWidth / 13; var fontOptions = new XPdfFontOptions(PdfFontEmbedding.Always); this.fontNormal = new XFont("Verdana", 7, XFontStyle.Regular, fontOptions); this.fontItalic = new XFont("Verdana", 7, XFontStyle.Italic, fontOptions); this.fontWingdings = new XFont("Wingdings 2", 9, XFontStyle.Bold, fontOptions); this.fontLogo = new XFont("Times New Roman", 30, XFontStyle.Regular, fontOptions); this.fontLocal = new XFont("Times New Roman", 15, XFontStyle.Regular, fontOptions); this.centerLeft = new XStringFormat(); this.centerLeft.LineAlignment = XLineAlignment.Center; this.centerLeft.Alignment = XStringAlignment.Near; }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string text = "TgfÄÖÜWi9"; if (this.properties.Font1.Text != "") text = this.properties.Font1.Text; float x = 100, y = 300; string familyName = properties.Font1.FamilyName; XFontStyle style = this.properties.Font1.Style; float emSize = this.properties.Font1.Size; //familyName = "Verdana"; //style = XFontStyle.Regular; //emSize = 20; //text = "X"; XFont font = CreateFont(familyName, emSize, style); //font = this.properties.Font1.Font; XSize size = gfx.MeasureString(text, font); double lineSpace = font.GetHeight(gfx); int cellSpace = font.FontFamily.GetLineSpacing(style); int cellAscent = font.FontFamily.GetCellAscent(style); int cellDescent = font.FontFamily.GetCellDescent(style); int cellLeading = cellSpace - cellAscent - cellDescent; double ascent = lineSpace * cellAscent / cellSpace; gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent); double descent = lineSpace * cellDescent / cellSpace; gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent); double leading = lineSpace * cellLeading / cellSpace; gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading); //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height); //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); #if true_ XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true); font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions); text = "Hallo"; text = chinese; #endif gfx.DrawString(text, font, this.properties.Font1.Brush, x, y); #if true XFont font2 = CreateFont(familyName, emSize, XFontStyle.Italic); gfx.DrawString(text, font2, this.properties.Font1.Brush, x, y+50); #endif //gfx.DrawLine(XPens.Red, x, y + 10, x + 13.7, y + 10); //gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20); }
private void AddFields() { XPdfFontOptions o = new XPdfFontOptions(PdfFontEncoding.Unicode); XFont font = new XFont("Times New Roman", 14, XFontStyle.Regular, o); gfx.DrawString("Бланк фиксации результатов теста", font, XBrushes.Black, new XRect(0, XUnit.FromMillimeter(17).Point, _page.Width, 5), XStringFormats.Center); this.DrawLeftString("Подразделение_______________", 10, 21, 60, 10); this.DrawLeftString("Ф.И.О._____________________________________", 70, 21, 90, 10); this.DrawLeftString("Образование_________________", 150, 21, 30, 10); this.DrawLeftString("Дата рождения_______________", 10, 26, 60, 10); this.DrawLeftString("Дата тестирования_____________", 150, 26, 30, 10); this.DrawLeftString("M", 203, 26, 5, 14); this.DrawRectangle(4, 210, 29); this.DrawLeftString("Ж", 214, 26, 5, 14); this.DrawRectangle(4, 221, 29); this.DrawLeftString("Пример заполнения бланка", 225, 26, 50, 10); this.DrawRectangle(4, 269, 29); this.DrawLeftString("Х", 267, 26, 5, 14); this.DrawLine(0, (int)_page.Width.Millimeter, 33); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.Font. /// </summary> /// <param name="font">A System.Drawing.Font.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(Font font, XPdfFontOptions pdfOptions) { if (font.Unit != GraphicsUnit.World) { throw new ArgumentException("Font must use GraphicsUnit.World."); } this.font = font; this.familyName = font.Name; this.emSize = font.Size; this.style = FontStyleFrom(font); this.pdfOptions = pdfOptions; Initialize(); }
//#if public TrueTypeDescriptor(XFont font, XPdfFontOptions options, XPrivateFontCollection privateFontCollection) { try { this.fontData = new FontData(font, options); this.fontName = font.Name; Initialize(); } catch (Exception ex) { throw ex; } }
protected XFont CreateFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions options) { XFont font; try { font = new XFont(familyName, emSize, style, options); } catch { font = new XFont("Courier", emSize, style, options); } return font; }
public OpenTypeDescriptor(XFont font, XPdfFontOptions options) { try { this.fontData = new FontData(font, options); this.fontName = font.Name; Initialize(); } catch { throw; } }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.Font. /// </summary> /// <param name="font">The System.Drawing.Font.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(GdiFont font, XPdfFontOptions pdfOptions) { if (font.Unit != GraphicsUnit.World) { throw new ArgumentException("Font must use GraphicsUnit.World."); } _gdiFont = font; Debug.Assert(font.Name == font.FontFamily.Name); _familyName = font.Name; _emSize = font.Size; _style = FontStyleFrom(font); _pdfOptions = pdfOptions; InitializeFromGdi(); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.FontFamily. /// </summary> /// <param name="fontFamily">The System.Windows.Media.FontFamily.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(WpfFontFamily fontFamily, double emSize, XFontStyle style, XPdfFontOptions pdfOptions) { #if !SILVERLIGHT _familyName = fontFamily.FamilyNames[XmlLanguage.GetLanguage("en-US")]; #else // Best we can do in Silverlight. _familyName = fontFamily.Source; #endif _wpfFontFamily = fontFamily; _emSize = emSize; _style = style; _pdfOptions = pdfOptions; InitializeFromWpf(); }
/// <summary> /// Converts a DOM Font to an XFont. /// </summary> internal static XFont FontToXFont(Font font, PdfFontEncoding encoding) { XPdfFontOptions options = new XPdfFontOptions(encoding); XFontStyle style = GetXStyle(font); #if DEBUG if (StringComparer.OrdinalIgnoreCase.Compare(font.Name, "Segoe UI Semilight") == 0 && (style & XFontStyle.BoldItalic) == XFontStyle.Italic) font.GetType(); #endif XFont xFont = new XFont(font.Name, font.Size, style, options); #if DEBUG CreateFontCounter++; #endif return xFont; }
static void RenderTextStyles(XGraphics gfx) { gfx.TranslateTransform(15, 20); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); const string facename = "Times New Roman"; XFont fontRegular = new XFont(facename, 20, XFontStyle.Regular, options); XFont fontBold = new XFont(facename, 20, XFontStyle.Bold, options); XFont fontItalic = new XFont(facename, 20, XFontStyle.Italic, options); XFont fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic, options); // The default alignment is baseline left (that differs from GDI+) gfx.DrawString(facename +" (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30); gfx.DrawString(facename + " (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65); gfx.DrawString(facename + " (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100); gfx.DrawString(facename +" (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135); }
private void AddFields(PdfRectangle rect) { float offset = (float)XUnit.FromPoint(rect.X1).Millimeter; XPdfFontOptions o = new XPdfFontOptions(PdfFontEncoding.Unicode); XFont font = new XFont("Times New Roman", 14, XFontStyle.Regular, o); gfx.DrawString("Бланк фиксации результатов теста", font, XBrushes.Black, new XRect(rect.X1, rect.Y1+XUnit.FromMillimeter(17).Point, rect.X2-rect.X1, 5), XStringFormats.Center); this.DrawLeftString("Подразделение_______________", 10 + offset, 25, 60, 10); this.DrawLeftString("Ф.И.О._____________________________________", 70 + offset, 25, 90, 10); this.DrawLeftString("Дата рождения_______________", 10 + offset, 30, 60, 10); this.DrawLeftString("Образование_________________", 10 + offset, 35, 30, 10); this.DrawLeftString("Дата тестирования__________________________", 70 + offset, 35, 30, 10); this.DrawLeftString("M", 10 + offset, 40, 5, 14); this.DrawRectangle(4, 17 + offset, 42); this.DrawLeftString("Ж", 20 + offset, 40, 5, 14); this.DrawRectangle(4, 27 + offset, 42); this.DrawLeftString("Пример заполнения бланка", 40 + offset, 40, 50, 10); this.DrawRectangle(4, 85 + offset, 42); this.DrawLeftString("Х", 83 + offset, 40, 5, 14); this.DrawLine(0, (int)_page.Width.Millimeter, 45); }
/// <summary> /// Initializes a new instance of the <see cref="FontData"/> class. /// </summary> public FontData(XFont font, XPdfFontOptions options) { #if GDI && !WPF CreateGdiFontImage(font, options, font.privateFontCollection); #endif #if WPF && !GDI CreateWpfFontData(font, options); #endif #if WPF && GDI System.Drawing.Font gdiFont = font.RealizeGdiFont(); if (font.font != null) CreateGdiFontImage(font, options, font.privateFontCollection); else if (font.typeface != null) CreateWpfFontData(font, options); #endif if (this.data == null) throw new InvalidOperationException("Cannot allocate font image."); Read(); }
/// <summary> /// This is an external helper function. /// </summary> public static byte[] F74167FFE4044F53B28A4AF049E9EF25(XFont font, XPdfFontOptions options, bool subset) { byte[] data = null; if (subset) { OpenTypeDescriptor descriptor = new OpenTypeDescriptor(font, options); FontData image = descriptor.fontData; CMapInfo cmapInfo = new CMapInfo(descriptor); cmapInfo.AddAnsiChars(); image = image.CreateFontSubSet(cmapInfo.GlyphIndices, false); data = image.Data; } else { FontData fontData = new FontData(font, options); data = fontData.Data; } return data; }
/// <summary> /// Draws text in different styles. /// </summary> void DrawText(XGraphics gfx, int number) { BeginBox(gfx, number, "Text Styles"); const string facename = "Times New Roman"; //XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.WinAnsi, PdfFontEmbedding.Default); XFont fontRegular = new XFont(facename, 20, XFontStyle.Regular, options); XFont fontBold = new XFont(facename, 20, XFontStyle.Bold, options); XFont fontItalic = new XFont(facename, 20, XFontStyle.Italic, options); XFont fontBoldItalic = new XFont(facename, 20, XFontStyle.BoldItalic, options); // The default alignment is baseline left (that differs from GDI+) gfx.DrawString("Times (regular)", fontRegular, XBrushes.DarkSlateGray, 0, 30); gfx.DrawString("Times (bold)", fontBold, XBrushes.DarkSlateGray, 0, 65); gfx.DrawString("Times (italic)", fontItalic, XBrushes.DarkSlateGray, 0, 100); gfx.DrawString("Times (bold italic)", fontBoldItalic, XBrushes.DarkSlateGray, 0, 135); EndBox(gfx); }
/// <summary> /// Initializes a new instance of the <see cref="FontImage"/> class. /// </summary> public FontImage(System.Drawing.Font font, XPdfFontOptions options) { #if DEBUG_ NativeMethods.LOGFONT logFont = new NativeMethods.LOGFONT(); font.ToLogFont(logFont); #endif int error; IntPtr hfont = font.ToHfont(); IntPtr hdc = NativeMethods.GetDC(IntPtr.Zero); error = Marshal.GetLastWin32Error(); IntPtr oldFont = NativeMethods.SelectObject(hdc, hfont); error = Marshal.GetLastWin32Error(); // size is exactly the size of the font file. int size = NativeMethods.GetFontData(hdc, 0, 0, null, 0); error = Marshal.GetLastWin32Error(); this.bytes = new byte[size]; int xx = NativeMethods.GetFontData(hdc, 0, 0, this.bytes, this.bytes.Length); NativeMethods.SelectObject(hdc, oldFont); NativeMethods.ReleaseDC(IntPtr.Zero, hdc); error.GetType(); Read(); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class. /// </summary> /// <param name="family">The font family.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> /// <param name="privateFontCollection">The private font collection.</param> public XFont(System.Drawing.FontFamily family, double emSize, XFontStyle style, XPdfFontOptions pdfOptions, XPrivateFontCollection privateFontCollection) { this.familyName = null; this.gdifamily = family; this.size = emSize; this.style = style; this.pdfOptions = pdfOptions; this.privateFontCollection = privateFontCollection; Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class. /// </summary> /// <param name="family">The font family.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(System.Drawing.FontFamily family, double emSize, XFontStyle style, XPdfFontOptions pdfOptions /*, * XPrivateFontCollection privateFontCollection*/ ) { this.familyName = null; this.gdifamily = family; this.emSize = emSize; this.style = style; this.pdfOptions = pdfOptions; Initialize(); }
public override void RenderPage(XGraphics gfx) { base.RenderPage(gfx); string text = "TgfÄÖÜWi9"; if (this.properties.Font1.Text != "") text = this.properties.Font1.Text; string familyName1 = properties.Font1.FamilyName; string familyName2 = properties.Font2.FamilyName; //XFontStyle style = this.properties.Font1.Style; float emSize1 = this.properties.Font1.Size; float emSize2 = this.properties.Font2.Size; XPdfFontOptions options1 = new XPdfFontOptions( this.properties.Font1.Unicode ? PdfFontEncoding.Unicode : PdfFontEncoding.WinAnsi, this.properties.Font1.Embed ? PdfFontEmbedding.Always : PdfFontEmbedding.None); XFont font1R = CreateFont(familyName1, emSize1, XFontStyle.Regular, options1); XFont font1B = CreateFont(familyName1, emSize1, XFontStyle.Bold, options1); XFont font1I = CreateFont(familyName1, emSize1, XFontStyle.Italic, options1); XFont font1BI = CreateFont(familyName1, emSize1, XFontStyle.BoldItalic, options1); XFont font1U = CreateFont(familyName1, emSize1, XFontStyle.Underline, options1); XFont font1S = CreateFont(familyName1, emSize1, XFontStyle.Strikeout, options1); XPdfFontOptions options2 = new XPdfFontOptions( this.properties.Font2.Unicode ? PdfFontEncoding.Unicode : PdfFontEncoding.WinAnsi, this.properties.Font2.Embed ? PdfFontEmbedding.Always : PdfFontEmbedding.None); XFont font2R = CreateFont(familyName2, emSize2, XFontStyle.Regular, options2); XFont font2B = CreateFont(familyName2, emSize2, XFontStyle.Bold, options2); XFont font2I = CreateFont(familyName2, emSize2, XFontStyle.Italic, options2); XFont font2BI = CreateFont(familyName2, emSize2, XFontStyle.BoldItalic, options2); XFont font2U = CreateFont(familyName2, emSize2, XFontStyle.Underline, options2); XFont font2S = CreateFont(familyName2, emSize2, XFontStyle.Strikeout, options2); //XSize size = gfx.MeasureString(text, font); //double lineSpace = font.GetHeight(gfx); //int cellSpace = font.FontFamily.GetLineSpacing(style); //int cellAscent = font.FontFamily.GetCellAscent(style); //int cellDescent = font.FontFamily.GetCellDescent(style); //int cellLeading = cellSpace - cellAscent - cellDescent; double x = 100, y = 50, d = 50; gfx.DrawString(text, font1R, this.properties.Font1.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font1B, this.properties.Font1.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font1I, this.properties.Font1.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font1BI, this.properties.Font1.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font1U, this.properties.Font1.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font1S, this.properties.Font1.Brush, new XPoint(x, y += d)); y += 50; gfx.DrawString(text, font2R, this.properties.Font2.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font2B, this.properties.Font2.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font2I, this.properties.Font2.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font2BI, this.properties.Font2.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font2U, this.properties.Font2.Brush, new XPoint(x, y += d)); gfx.DrawString(text, font2S, this.properties.Font2.Brush, new XPoint(x, y += d)); //double ascent = lineSpace * cellAscent / cellSpace; //gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent); //double descent = lineSpace * cellDescent / cellSpace; //gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent); //double leading = lineSpace * cellLeading / cellSpace; //gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading); //gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height); //gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y); //gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200); #if true_ XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true); font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions); text = "Hallo"; text = chinese; #endif //gfx.DrawString(text, font, this.properties.Font1.Brush, x, y); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class from a System.Drawing.Font. /// </summary> /// <param name="font">A System.Drawing.Font.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(Font font, XPdfFontOptions pdfOptions) { if (font.Unit != GraphicsUnit.World) throw new ArgumentException("Font must use GraphicsUnit.World."); this.font = font; this.familyName = font.Name; this.size = font.Size; this.style = FontStyleFrom(font); this.pdfOptions = pdfOptions; Initialize(); }
/// <summary> /// Initializes a new instance of the <see cref="XFont"/> class. /// </summary> /// <param name="familyName">Name of the font family.</param> /// <param name="emSize">The em size.</param> /// <param name="style">The font style.</param> /// <param name="pdfOptions">Additional PDF options.</param> public XFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions pdfOptions) { this.familyName = familyName; this.size = emSize; this.style = style; this.pdfOptions = pdfOptions; Initialize(); }
public static void SaveTest() { XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); initialize(); PdfPage page = _document.AddPage(); XGraphics X = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend); page.Size = PageSize.A4; double width = page.Width; double height = page.Height; double top = _margins.Top; double bottom = _margins.Bottom; double left = _margins.Left; double right = _margins.Right*2; double y = top; double x = left; XFont titleFont = new XFont("Calibri", 14F, XFontStyle.Bold,options); XFont fontW = new XFont("Calibri", 100F, XFontStyle.Regular, options); XFont fontQ = new XFont("Calibri", 12F, XFontStyle.Regular,options); XFont fontA = new XFont("Calibri", 11F, XFontStyle.Regular, options); var img = new Bitmap(1, 1); XGraphics E = XGraphics.FromGraphics(Graphics.FromImage(img), new XSize()); X.DrawStringML(_title, titleFont, XBrushes.Black, x, ref y, width - right); y += titleFont.GetHeight() + 20; X.DrawString("Date: " + _date, fontQ, Brushes.Black, width - right - 40, y); X.DrawString("First Name: ___________________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Last Name: ___________________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Class: ________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Points:________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 35; X.DrawString("Choose the correct answer. There might be more than one correct answers.", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 20; for (int i = 0; i < _test.Count; i++) { string question = (i + 1) + ". " + _test[i].question; //Ipologismos gia allagi selidas double tempY = y; E.DrawStringML(question, fontQ, Brushes.Black, x, ref tempY, width - right); if (tempY > height - bottom) { watermarkprint(X, page, fontW); page = _document.AddPage(); page.Size = PageSize.A4; X = XGraphics.FromPdfPage(page); y = top; } //Prints Questions X.DrawStringML(question, fontQ, XBrushes.Black, x, ref y, width - right); for (int k = 0; k < _test[i].anwsers.Count; k++) { string answer = _test[i].anwsers[k].text; //ipologismos gia allagi selida tempY = y; E.DrawStringML(answer, fontQ, Brushes.Black, x, ref tempY, width - right); if (tempY > height-bottom) { watermarkprint(X, page, fontW); page = _document.AddPage(); page.Size = PageSize.A4; X = XGraphics.FromPdfPage(page); y = top; } y += 3; //Edw tipwnei apantisi X.DrawRectangle(new Pen(Color.Black), x + 15, y, 20, 20); if (_solved && _test[i].anwsers[k].correct) { var cube = new Bitmap(20, 20); Graphics C = Graphics.FromImage(cube); C.FillRectangle(Brushes.Black, 0, 0, 20, 20); X.DrawImage(cube, x+15, y,20,20); } y += 12; X.DrawStringML(answer, fontA, Brushes.Black, x + 45, ref y, width - right); } y += 30; } watermarkprint(X,page,fontW); _document.Save(_savePath); Process.Start(_savePath); }
private XFont GetXFont(eFont AFont) { XFont ReturnValue = FXDefaultFont; switch (AFont) { case eFont.eDefaultFont: ReturnValue = FXDefaultFont; break; case eFont.eDefaultBoldFont: ReturnValue = FXDefaultBoldFont; break; case eFont.eHeadingFont: ReturnValue = FXHeadingFont; break; case eFont.eSmallPrintFont: ReturnValue = FXSmallPrintFont; break; case eFont.eBarCodeFont: ReturnValue = FXBarCodeFont; break; } Font gFont = GetFont(AFont); string id = ReturnValue.FontFamily.Name + gFont.SizeInPoints.ToString() + gFont.Style.ToString(); if (!FXFontCache.ContainsKey(id)) { XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); FXFontCache.Add(id, new XFont(ReturnValue.FontFamily.Name, Point(gFont.SizeInPoints /*+XFONTSIZE*/), ReturnValue.Style, options)); } ReturnValue = FXFontCache[id]; return ReturnValue; }
/// <summary> /// /// </summary> /// <param name="gfx"></param> /// <param name="text"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <param name="db"></param> /// <param name="r"></param> public void Draw(object gfx, Kaliber3D.Render.XText text, double dx, double dy, ImmutableArray<Kaliber3D.Render.ShapeProperty> db, Kaliber3D.Render.Record r) { var _gfx = gfx as XGraphics; var tbind = text.BindToTextProperty(db, r); if (string.IsNullOrEmpty(tbind)) return; var options = new XPdfFontOptions(PdfFontEncoding.Unicode); var fontStyle = XFontStyle.Regular; if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Bold)) { fontStyle |= XFontStyle.Bold; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Italic)) { fontStyle |= XFontStyle.Italic; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Underline)) { fontStyle |= XFontStyle.Underline; } if (text.Style.TextStyle.FontStyle.Flags.HasFlag(Kaliber3D.Render.FontStyleFlags.Strikeout)) { fontStyle |= XFontStyle.Strikeout; } var font = new XFont( text.Style.TextStyle.FontName, _scaleToPage(text.Style.TextStyle.FontSize), fontStyle, options); var rect = Kaliber3D.Render.Rect2.Create( text.TopLeft, text.BottomRight, dx, dy); var srect = new XRect( _scaleToPage(rect.X), _scaleToPage(rect.Y), _scaleToPage(rect.Width), _scaleToPage(rect.Height)); var format = new XStringFormat(); switch (text.Style.TextStyle.TextHAlignment) { case Kaliber3D.Render.TextHAlignment.Left: format.Alignment = XStringAlignment.Near; break; case Kaliber3D.Render.TextHAlignment.Center: format.Alignment = XStringAlignment.Center; break; case Kaliber3D.Render.TextHAlignment.Right: format.Alignment = XStringAlignment.Far; break; } switch (text.Style.TextStyle.TextVAlignment) { case Kaliber3D.Render.TextVAlignment.Top: format.LineAlignment = XLineAlignment.Near; break; case Kaliber3D.Render.TextVAlignment.Center: format.LineAlignment = XLineAlignment.Center; break; case Kaliber3D.Render.TextVAlignment.Bottom: format.LineAlignment = XLineAlignment.Far; break; } _gfx.DrawString( tbind, font, ToXSolidBrush(text.Style.Stroke), srect, format); }
private void DrawLeftString(string text, float fromleftmm, float fromtopmm, float widthmm, float fontsize) { XPdfFontOptions o = new XPdfFontOptions(PdfFontEncoding.Unicode); XFont font1 = new XFont("Times New Roman", fontsize, XFontStyle.Regular, o); gfx.DrawString(text, font1, XBrushes.Black, new XRect(XUnit.FromMillimeter(fromleftmm).Point, XUnit.FromMillimeter(fromtopmm).Point, XUnit.FromMillimeter(widthmm).Point, 5), XStringFormats.TopLeft); }
/// <summary> /// Creates font and enforces bold/italic simulation. /// </summary> public static XFont CreateSpecialFont(string familyName, double emSize, XFontStyle style, XPdfFontOptions pdfOptions, XStyleSimulations styleSimulations) { return new XFont(familyName, emSize, style, pdfOptions, styleSimulations); }
/// <summary> /// initialise the fonts and pens. /// this can only happen when the Graphics and GraphicsUnit are known. /// </summary> private void InitFontsAndPens() { FXBlackPen = new XPen(XColor.FromKnownColor(XKnownColor.Black), Cm(0.05f)); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); // the fonts need to be a little bit bigger so that they have the same size as the GfxPrinter? FXSmallPrintFont = new XFont("Arial", 0.12, XFontStyle.Regular, options); // Point(6 + XFONTSIZE) FXDefaultFont = new XFont("Arial", 0.14, XFontStyle.Regular, options); // Point(8 + XFONTSIZE) FXDefaultBoldFont = new XFont("Arial", 0.14, XFontStyle.Bold, options); // Point(8 + XFONTSIZE) FXHeadingFont = new XFont("Arial", 0.16, XFontStyle.Bold, options); // Point(10 + XFONTSIZE) // using GPL Font Code 128 from Grand Zebu http://grandzebu.net/ FXBarCodeFont = new XFont("Code 128", 0.45, XFontStyle.Regular, options); // Point(10 + XFONTSIZE) FXBiggestLastUsedFont = FXDefaultFont; FXRight = new XStringFormat(); FXRight.Alignment = XStringAlignment.Far; FXLeft = new XStringFormat(); FXLeft.Alignment = XStringAlignment.Near; FXCenter = new XStringFormat(); FXCenter.Alignment = XStringAlignment.Center; }
private void button2_Click(object sender, EventArgs e) { System.Drawing.Rectangle r = pictureBox1.RectangleToScreen(pictureBox1.ClientRectangle); Bitmap b = new Bitmap(r.Width - 5, r.Height - 5); Graphics g = Graphics.FromImage(b); g.CopyFromScreen(r.Location, new Point(0, 0), r.Size); b.Save("111.png"); SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "pdf|*.pdf"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { PdfDocument doc = new PdfDocument(); // Set font encoding to unicode XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); XFont font = new XFont("Times New Roman", 12, XFontStyle.Regular, options); XImage img = XImage.FromFile("111.png"); PdfPage page = doc.AddPage(); XGraphics xgr = XGraphics.FromPdfPage(page); xgr.DrawImage(img,30,80,538,242); xgr.DrawString("Спроектированный шкаф: ", font, XBrushes.Black,new XRect(20, 50, page.Width - 200, 600), XStringFormats.TopCenter); doc.Save(@saveFileDialog1.FileName + ".pdf"); doc.Close(); } // File.Delete("111.png"); }
private static void DrawText(XGraphics gfx, string text, string font, string style, double size, string color, int width, int height, int x, int y) { XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Default); XFont fontStyle = null; switch (style) { case "Bold": fontStyle = new XFont(font, size, XFontStyle.Bold, options); break; case "Italic": fontStyle = new XFont(font, size, XFontStyle.Italic, options); break; case "Regular": fontStyle = new XFont(font, size, XFontStyle.Regular, options); break; case "Underline": fontStyle = new XFont(font, size, XFontStyle.Underline, options); break; case "Strikeout": fontStyle = new XFont(font, size, XFontStyle.Strikeout, options); break; case "BoldItalic": fontStyle = new XFont(font, size, XFontStyle.BoldItalic, options); break; default: break; } System.Drawing.Color fontColor = ConverterManager.HexToColorConverter(color); XBrush fontBrush = new XSolidBrush(new XColor { R = fontColor.R, G = fontColor.G, B = fontColor.B }); XRect fontRect = new XRect(x, y, width, height); XStringFormat fontFormat = new XStringFormat { Alignment = XStringAlignment.Center }; gfx.DrawString(text, fontStyle, fontBrush, fontRect, fontFormat); }
private static void PrintSection(XGraphics gfx, string header, string text, XPoint point, double width, double height, double headerFontSize, double textFontSize, double headerHeight) { XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); var fontHeader = new XFont("Times New Roman", headerFontSize, XFontStyle.Bold, options); var fontText = new XFont("Times New Roman", textFontSize, XFontStyle.Bold, options); var tf = new XTextFormatter(gfx); tf.DrawString(header, fontHeader, XBrushes.Black, new XRect(point.X, point.Y, width, height)); tf.DrawString(text, fontText, XBrushes.Black, new XRect(point.X + 5, point.Y + headerHeight, width, height)); }