PDFsharp & MigraDoc Foundation https://forum.pdfsharp.net/ |
|
Drawing a path surrounding a given path https://forum.pdfsharp.net/viewtopic.php?f=2&t=3287 |
Page 1 of 1 |
Author: | stefan.at.wpf [ Thu Feb 04, 2016 5:01 pm ] |
Post subject: | Drawing a path surrounding a given path |
Given a path like this: Attachment: pdfsharp_input.jpg [ 7.94 KiB | Viewed 5028 times ] I want to create a path surrounding this path with a given distance, e.g. 1 cm. The following sketch demonstrates that - the red path surrounds the black path with a distance of 1 cm. Attachment: pdfhsrap_desired_output.jpg [ 20.93 KiB | Viewed 5028 times ] How can this be done in a generic way using PDFSharp? Here is the code for the black path: Code: // helper for easily getting an XPoint in centimeters private XPoint cmPoint(double x, double y) { return new XPoint( XUnit.FromCentimeter(x), XUnit.FromCentimeter(y) ); } // the path to be drawn private XGraphicsPath getMyPath() { XGraphicsPath path = new XGraphicsPath(); XPoint[] points = new XPoint[3]; points[0] = cmPoint(0, 0); points[1] = cmPoint(5, 2); points[2] = cmPoint(10,0); path.AddCurve(points); path.AddLine(cmPoint(10, 0), cmPoint(10, 10)); path.AddLine(cmPoint(10, 10), cmPoint(0, 10)); path.CloseFigure(); return path; } // generate the PDF file private void button3_Click(object sender, RoutedEventArgs e) { // Create a temporary file string filename = String.Format("{0}_tempfile.pdf", Guid.NewGuid().ToString("D").ToUpper()); XPen penBlack = new XPen(XColors.Black, 1); XPen penRed = new XPen(XColors.Red, 1); PdfDocument pdfDocument = new PdfDocument(); PdfPage page = pdfDocument.AddPage(); page.Size = PdfSharp.PageSize.A1; XGraphics gfx = XGraphics.FromPdfPage(page); //give us some space to the left and top gfx.TranslateTransform(XUnit.FromCentimeter(3), XUnit.FromCentimeter(3)); // draw the desired path gfx.DrawPath(penBlack, getMyPath()); // Save the pdfDocument... pdfDocument.Save(filename); // ...and start a viewer Process.Start(filename); } Thanks for any help on this topic! Hint: I also posted this on Stackoverflow, but yet could not get a sufficient solution. |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |