예제 #1
0
        public FileContentResult GetResultAsPdf()
        {
            DataFileContents = ProjectileMotionFilesSaving.GetMemoryStreamFromPdfDocument((document, page) =>
            {
                using (Image chart = Image.FromStream(new MemoryStream(GetBytes())))
                {
                    int chartHeightRendered = 0;
                    while (chartHeightRendered < chart.Size.Height)
                    {
                        using (XGraphics gfx = XGraphics.FromPdfPage(chartHeightRendered == 0 ? page : document.AddPage(), XPageDirection.Downwards))
                        {
                            gfx.PdfPage.TrimMargins = new TrimMargins()
                            {
                                All = new XUnit(1, XGraphicsUnit.Centimeter)
                            };


                            int chartHeightFullPage = Convert.ToInt32(chart.Size.Width * (gfx.PageSize.Height / gfx.PageSize.Width));
                            int chartHeightToRender = chart.Size.Height - chartHeightRendered < chartHeightFullPage ? chart.Size.Height - chartHeightRendered : chartHeightFullPage;

                            gfx.PdfPage.Orientation = PageOrientation.Portrait;
                            gfx.DrawImage(
                                ImgToXimg(
                                    CropImg(
                                        chart,
                                        new Rectangle(
                                            new Point(0, chartHeightRendered),
                                            new Size(chart.Size.Width, chartHeightToRender)
                                            )
                                        )
                                    ),
                                0,
                                0,
                                gfx.PageSize.Width,
                                gfx.PageSize.Width * ((double)chartHeightToRender / chart.Size.Width)
                                );

                            chartHeightRendered += chartHeightToRender;
                        }
                    }
                }
            }).ToArray();

            ContentType = "aplication/pdf";

            return(GetResultAsContentType());
        }
예제 #2
0
 /// <summary>
 /// Constructor for a projectile motion.
 /// </summary>
 /// <param name="settings">Settings object for projectile motion. It cannot be null.</param>
 public ProjectileMotion(ProjectileMotionSettings settings)
 {
     Settings   = settings ?? throw new ArgumentNullException(nameof(settings), "Settings object cannot be null.");
     Trajectory = new ProjectileMotionTrajectory(Settings);
     Saving     = new ProjectileMotionFilesSaving(this);
 }