public void TestAppendImage() { using (Image image = new Bitmap(2, 2)) { builder.AppendImage(image); Assert.AreEqual(1, doc.LastSection.Elements.Count); Paragraph paragraph = (Paragraph)doc.LastSection.Elements[0]; Assert.AreEqual(1, paragraph.Elements.Count); MigraDocImage inserted = (MigraDocImage)paragraph.Elements[0]; Assert.AreEqual(image.Width, inserted.Source.Width); Assert.AreEqual(image.Height, inserted.Source.Height); } }
public static Document CreateStandardDocument(bool vertical = true) { Document document = new Document(); var section = document.AddSection(); PageSetup pageSetup = document.DefaultPageSetup.Clone(); pageSetup.LeftMargin = Unit.FromCentimeter(1); pageSetup.RightMargin = Unit.FromCentimeter(1); pageSetup.TopMargin = Unit.FromCentimeter(1); pageSetup.BottomMargin = Unit.FromCentimeter(1); pageSetup.Orientation = vertical ? Orientation.Portrait : Orientation.Landscape; section.PageSetup = pageSetup; document.Styles.Normal.ParagraphFormat.SpaceAfter = Unit.FromPoint(10); section.AddParagraph(); PdfBuilder builder = new PdfBuilder(document, PdfOptions.Default); builder.AppendImage(Image.LoadFromResource("AIBanner.png")); document.LastSection.AddParagraph(); return(document); }
/// <summary> /// Render the given DirectedGraphTag tag to the PDF document. /// </summary> /// <param name="tag">Directed graph tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(DirectedGraphTag tag, PdfBuilder renderer) { renderer.GetPageSize(out double width, out double height); renderer.StartNewParagraph(); renderer.AppendImage(WriteToImage(tag.Graph, (int)width, (int)width)); renderer.StartNewParagraph(); }
/// <summary> /// Render the given image tag to the PDF document. /// </summary> /// <param name="image">Image tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(Image image, PdfBuilder renderer) { // Add the image to a new paragraph. renderer.StartNewParagraph(); renderer.AppendImage(image.GetRaster(searchPath)); renderer.StartNewParagraph(); }
/// <summary> /// Render the given Map tag to the PDF document. /// </summary> /// <param name="map">Map tag to be rendered.</param> /// <param name="document">PDF renderer to use for rendering the tag.</param> protected override void Render(MapTag map, PdfBuilder document) { document.GetPageSize(out double width, out double height); int resolution = (int)Math.Min(width, height); document.StartNewParagraph(); document.AppendImage(map.ToImage(resolution)); document.StartNewParagraph(); }
/// <summary> /// Render the given LinkInline object to the PDF document. /// </summary> /// <param name="renderer">The PDF renderer.</param> /// <param name="link">The link object to be renderered.</param> protected override void Write(PdfBuilder renderer, LinkInline link) { string uri = link.GetDynamicUrl != null?link.GetDynamicUrl() ?? link.Url : link.Url; if (link.IsImage) { Image image = GetImage(uri); // Technically, the image should be written to the same paragraph as any existing content. // However, if the image is too large, I'm going to add it to its own paragraph. // I'm defining "too large" as "taller than page height * 0.9". renderer.GetPageSize(out _, out double height); if (image.Height > 0.9 * height) { renderer.StartNewParagraph(); } renderer.AppendImage(image); // The assumption here is that any children of the image are the image's caption. renderer.StartNewParagraph(); // Increment heading count, iff the link has a caption. if (link.Any()) { renderer.IncrementFigureNumber(); renderer.AppendText($"Figure {renderer.FigureNumber}: ", TextStyle.Strong); renderer.WriteChildren(link); renderer.StartNewParagraph(); } } else { // Clunky bookmark detection. This could be improved. if (uri.StartsWith("#")) { renderer.StartBookmark(uri); } else { renderer.SetLinkState(uri); } renderer.WriteChildren(link); renderer.ClearLinkState(); } }
/// <summary> /// Render the given graph tag to the PDF document. /// </summary> /// <param name="graph">Graph tag to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(IGraph graph, PdfBuilder renderer) { renderer.GetPageSize(out double width, out _); renderer.StartNewParagraph(); var plot = exporter.ToPlotModel(graph); // Temp hack - set marker size to 5. We need to review // appropriate sizing for graphs in autodocs. if (plot is OxyPlot.PlotModel model) { foreach (var series in model.Series.OfType <OxyPlot.Series.LineSeries>()) { series.MarkerSize = 5; } } renderer.AppendImage(exporter.Export(plot, width, width / aspectRatio)); renderer.StartNewParagraph(); }
/// <summary> /// Render the given graph page to the PDF document. /// </summary> /// <param name="GraphPage">Graph page to be rendered.</param> /// <param name="renderer">PDF renderer to use for rendering the tag.</param> protected override void Render(GraphPage page, PdfBuilder renderer) { renderer.GetPageSize(out double width, out double height); // Let image width = half page width. width /= 2; // 6 graphs per page - 2 columns of 3 rows. // Therefore each graph gets 1/3 total page height. height /= 3; renderer.StartNewParagraph(); foreach (IGraph graph in page.Graphs) { OxyPlot.IPlotModel model = exporter.ToPlotModel(graph); if (model is OxyPlot.PlotModel plot) { FixSizing(ref plot); plot.Legends.Clear(); } renderer.AppendImage(exporter.Export(model, width, height /*width * 2 / 3*/)); } renderer.StartNewParagraph(); }