I want to draw a System.Windows.Forms.DataVisualization.Charting.Chart on a PDFPage.
The method Chart.Printing.PrintPaint(Graphics graphics, Rectangle position) can be used to draw the chart on a Graphics.
How can I do to draw it on the XGraphics?
I tried to draw the chart on a Bitmap using the code below:
Code:
PdfDocument document = new PdfDocument();
PdfPage page = document.AddPage();
page.Orientation = PdfSharp.PageOrientation.Landscape;
XGraphics gfx = XGraphics.FromPdfPage(page);
gfx.DrawRectangle(XBrushes.Red, rectanglePage);
Rectangle rectangle = new Rectangle(0, 0, (int)page.Width.Point, (int)page.Height.Point);
Bitmap bmp = new Bitmap(rectangle.Width, rectangle.Height);
Graphics g = Graphics.FromImage(bmp);
this.chart.Printing.PrintPaint(g, rectangle);
XImage img = XImage.FromGdiPlusImage(bmp);
gfx.DrawImage(img, 0, 0);
However, this does not work. On the result file, the chart is significantly smaller than the PDF page, as you can see on the attached image (The Page has been filled in red to differentiate the actual page to the chart).
In the code, page.Width.Point==842, and so is the chart on the image. However, the page actual width is 1123px.
I suspect a problem of PDI, but the answer from your team on this question
http://stackoverflow.com/questions/1102 ... n-pdfsharp says that I cannot change the DPI.
This other question
viewtopic.php?f=2&t=3141&hilit=graphics shows how to how to use XGraphics to draw on a Graphics. But I need to do the opposite.