static void DrawFormatted(Document doc, MigraDoc.Rendering.DocumentRenderer docRenderer, XGraphics gfx, Color color, String fontName, Unit fontSize, ParagraphAlignment alignment, String text, double x, double y, double width = 5) { Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); para.Format.Alignment = alignment; para.Format.Font.Name = fontName; para.Format.Font.Size = fontSize; para.Format.Font.Bold = true; para.Format.Font.Color = color; //para.Format.Borders.Color = color; //para.Format.LineSpacing = 10; //para.Format.LineSpacingRule = LineSpacingRule.Exactly; para.AddText(text); docRenderer.RenderObject(gfx, XUnit.FromCentimeter(x), XUnit.FromCentimeter(y), XUnit.FromCentimeter(width), para); }
private void SamplePage1(PdfDocument document) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); gfx.MUH = PdfFontEncoding.Unicode; XFont font = new XFont("Verdana", 13, XFontStyle.Bold); gfx.DrawString("The following paragraph was rendered using MigraDoc:", font, XBrushes.Black, new XRect(100, 100, page.Width - 100, 100), XStringFormats.Center); Document doc = new Document(); Section sec = doc.AddSection(); Paragraph para = sec.AddParagraph(); para.Format.Alignment = ParagraphAlignment.Justify; para.Format.Font.Name = "Times New Roman"; para.Format.Font.Size = 12; para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; para.AddText("Duisism odigna acipsum delesenisl "); para.AddFormattedText("ullum in velenit"); para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " + "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " + "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis " + "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex " + "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠"); para.Format.Borders.Distance = "20pt"; para.Format.Borders.Color = Colors.Coral; MigraDoc.Rendering.DocumentRenderer documentRenderer = new MigraDoc.Rendering.DocumentRenderer(doc); documentRenderer.PrepareDocument(); documentRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para); }
bool StoreTempImage(string fileName) { try { float resolution = 300; int horzPixels = (int)(GetShapeWidth().Inch * resolution); int vertPixels = (int)(GetShapeHeight().Inch * resolution); Bitmap bmp = new Bitmap(horzPixels, vertPixels); // Always renders to a Bitmap for embedding in output. XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels)); //REM: Should not be necessary: gfx.ScaleTransform(resolution / 72); //gfx.PageUnit = XGraphicsUnit.Point; DocumentRenderer renderer = new DocumentRenderer(this.chart.Document); renderer.RenderObject(gfx, 0, 0, GetShapeWidth().Point, this.chart); bmp.SetResolution(resolution, resolution); bmp.Save(fileName, ImageFormat.Png); } catch (Exception) { return false; } return true; }
/// <summary> /// Renders a single paragraph. /// </summary> static void SamplePage1(PdfDocument document) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); // HACK² gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; XFont font = new XFont("Verdana", 13, XFontStyle.Bold); gfx.DrawString("The following paragraph was rendered using MigraDoc:", font, XBrushes.Black, new XRect(100, 100, page.Width - 200, 300), XStringFormats.Center); // You always need a MigraDoc document for rendering. Document doc = new Document(); Section sec = doc.AddSection(); // Add a single paragraph with some text and format information. Paragraph para = sec.AddParagraph(); para.Format.Alignment = ParagraphAlignment.Justify; para.Format.Font.Name = "Times New Roman"; para.Format.Font.Size = 12; para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; para.AddText("Duisism odigna acipsum delesenisl "); para.AddFormattedText("ullum in velenit", TextFormat.Bold); para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna "+ "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel "+ "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis "+ "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex "+ "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠"); para.Format.Borders.Distance = "5pt"; para.Format.Borders.Color = Colors.Gold; // Create a renderer and prepare (=layout) the document MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); // Render the paragraph. You can render tables or shapes the same way. docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", para); }
bool StoreTempImage(string fileName) { try { const float resolution = 96; int horzPixels = (int)(GetShapeWidth().Inch * resolution); int vertPixels = (int)(GetShapeHeight().Inch * resolution); Bitmap bmp = new Bitmap(horzPixels, vertPixels); #if true XGraphics gfx = XGraphics.CreateMeasureContext(new XSize(horzPixels, vertPixels), XGraphicsUnit.Point, XPageDirection.Downwards); #else #if GDI XGraphics gfx = XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels)); #endif #if WPF // TODOWPF XGraphics gfx = null; //XGraphics.FromGraphics(Graphics.FromImage(bmp), new XSize(horzPixels, vertPixels)); #endif #endif //REM: Should not be necessary: gfx.ScaleTransform(resolution / 72); //gfx.PageUnit = XGraphicsUnit.Point; DocumentRenderer renderer = new DocumentRenderer(_chart.Document); renderer.RenderObject(gfx, 0, 0, GetShapeWidth().Point, _chart); bmp.SetResolution(resolution, resolution); bmp.Save(fileName, ImageFormat.Png); } catch (Exception) { return false; } return true; }