PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Aug 03, 2021 9:40 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Jun 30, 2021 7:34 am 
Offline

Joined: Tue Jun 29, 2021 2:37 pm
Posts: 1
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");


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 18 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group