// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // Provides functionality to export plots to pdf. // // -------------------------------------------------------------------------------------------------------------------- namespace OxyPlot.Pdf { using System.IO; /// /// Provides functionality to export plots to pdf. /// public class PdfExporter : IExporter { /// /// Gets or sets the width (in points, 1/72 inch) of the output document. /// public double Width { get; set; } /// /// Gets or sets the height (in points, 1/72 inch) of the output document. /// public double Height { get; set; } /// /// Gets or sets the background color. /// public OxyColor Background { get; set; } /// /// Exports the specified model to a file. /// /// The model. /// The path. /// The width (points). /// The height (points). public static void Export(IPlotModel model, string path, double width, double height) { using (var s = File.OpenWrite(path)) { Export(model, s, width, height); } } /// /// Exports the specified model to a stream. /// /// The model. /// The output stream. /// The width (points). /// The height (points). public static void Export(IPlotModel model, Stream stream, double width, double height) { var exporter = new PdfExporter { Width = width, Height = height, Background = model.Background }; exporter.Export(model, stream); } /// /// Exports the specified to the specified . /// /// The model. /// The stream. public void Export(IPlotModel model, Stream stream) { using (var rc = new PdfRenderContext(this.Width, this.Height, this.Background)) { model.Update(true); model.Render(rc, this.Width, this.Height); rc.Save(stream); } } } }