PDFsharp & MigraDoc Foundation http://forum.pdfsharp.com/ |
|
Draw a vertical line over a StackedBarChart in MigraDoc http://forum.pdfsharp.com/viewtopic.php?f=2&t=4270 |
Page 1 of 1 |
Author: | ionutnespus [ Wed Jun 30, 2021 7:34 am ] |
Post subject: | Draw a vertical line over a StackedBarChart in MigraDoc |
Hello, I want to generate a PDF that has a StackedBarChart. I need to draw some vertical lines at certain positions over the chart (like some milestones). The only way I found to do this is to create the chart with MigraDoc, then open it with PDFSharp and draw with XGraphics on it. Is there a easier way to achieve this? The vertical lines should be drawn at specific position, so identifying the coordinates is a bit tricky. This is my code until now: Code: var migraDocument = new Document();
//Add the bar chart WriteDocument(migraDocument); //Render the MigraDoc document DocumentRenderer documentRenderer = new DocumentRenderer(migraDocument); documentRenderer.PrepareDocument(); //Use PdfSharp to draw with XGraphics PdfDocument pdfDocument = new PdfDocument(); int pageCount = documentRenderer.FormattedDocument.PageCount; for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) // Note that page numbers start with 1. { PdfPage pdfPage = pdfDocument.AddPage(); XGraphics xGraphics = XGraphics.FromPdfPage(pdfPage); //draw some random lines to see it works XPen pen = new XPen(XColors.DarkGreen, 6); XPoint[] points = new XPoint[] { new XPoint(20, 100), new XPoint(60, 120), new XPoint(90, 20), new XPoint(170, 90), new XPoint(230, 40) }; xGraphics.DrawLines(pen, points); documentRenderer.RenderPage(xGraphics, pageNumber); } pdfDocument.Save("output.pdf"); |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |