Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
445
Fit a chart for PDF Export
posted

Hi all,

 

I'm trying to fit a chart into a page for a PDF Export, but it will not be fitted.

I'm using following code, but I don't know what is wrong.

Any help will be appreciate.

Regards

 

 Report report = new Report();

                    //Create a section and set page dimension and orientation
                    ISection reportSection = report.AddSection();
                    reportSection.PageSize = frm.TargetPageSize;                                       
                    reportSection.PageOrientation = frm.TargetPaperOrientation;
                    reportSection.PageMargins = new Margins(Infragistics.Documents.Utils.Converter.MillimetersToPoints(10), Infragistics.Documents.Utils.Converter.MillimetersToPoints(10), Infragistics.Documents.Utils.Converter.MillimetersToPoints(10), Infragistics.Documents.Utils.Converter.MillimetersToPoints(10));

                    //swap With/Height depending on the PageOrientation
                    double pageWith = reportSection.PageOrientation == PageOrientation.Portrait ? (double)Infragistics.Documents.Utils.Converter.PointsToPixels(reportSection.PageSize.Width - reportSection.PageMargins.Left - reportSection.PageMargins.Right) : (double)Infragistics.Documents.Utils.Converter.PointsToPixels(reportSection.PageSize.Height - reportSection.PageMargins.Top - reportSection.PageMargins.Bottom);
                    double pageHeight = reportSection.PageOrientation == PageOrientation.Portrait ? (double)Infragistics.Documents.Utils.Converter.PointsToPixels(reportSection.PageSize.Height - reportSection.PageMargins.Top - reportSection.PageMargins.Bottom) : (double)Infragistics.Documents.Utils.Converter.PointsToPixels(reportSection.PageSize.Width - reportSection.PageMargins.Left - reportSection.PageMargins.Right);

                    double scalingWidth = pageWith / (double)chart.Width;
                    double scalingHeight = pageHeight / (double)chart.Height;
                       
                    //create graphic interface
                    Graphics graphics = reportSection.AddCanvas().CreateGraphics();
                    graphics.PageUnit = GraphicsUnit.Pixel;

                    chart.RenderPdfFriendlyGraphics(graphics, (int)Math.Floor((double)chart.Width * scalingWidth), (int)Math.Floor((double)chart.Height * scalingHeight));
                    report.Publish(frm.Path, FileFormat.PDF);

  • 28496
    Offline posted

    i don't think PageSize needs to be converted from points to pixels.

    when i corrected the assigment to the pageWith and PageHeight variables, it fixed the problem.

                pageWith = reportSection.PageOrientation == PageOrientation.Portrait ? reportSection.PageSize.Width - reportSection.PageMargins.Left - reportSection.PageMargins.Right : reportSection.PageSize.Height - reportSection.PageMargins.Top - reportSection.PageMargins.Bottom;
                pageHeight = reportSection.PageOrientation == PageOrientation.Portrait ? reportSection.PageSize.Height - reportSection.PageMargins.Top - reportSection.PageMargins.Bottom : reportSection.PageSize.Width - reportSection.PageMargins.Left - reportSection.PageMargins.Right;