Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Sat Aug 01, 2015 5:33 pm

I've been working with the drawing tools of Free Spire.PDF. Using this code from the tutorial:
Code: Select all
PointF[] points = new PointF[5];
for (int i = 0; i < points.Length; i++)
{
    float x = (float)Math.Cos(i * 2 * Math.PI / 5);
    float y = (float)Math.Sin(i * 2 * Math.PI / 5);
    points[i] = new PointF(x, y);
}
PdfPath path = new PdfPath();
path.AddLine(points[2], points[0]);
path.AddLine(points[0], points[3]);
path.AddLine(points[3], points[1]);
path.AddLine(points[1], points[4]);
path.AddLine(points[4], points[2]);

which generates this star nicely:
TutorialStar.PNG


However if I modify the code so that the lines are not drawn in sequence:
Code: Select all
PointF[] points = new PointF[5];
for (int i = 0; i < points.Length; i++)
{
    float x = (float)Math.Cos(i * 2 * Math.PI / 5);
    float y = (float)Math.Sin(i * 2 * Math.PI / 5);
    points[i] = new PointF(x, y);
}
PdfPath path = new PdfPath();
path.AddLine(points[2], points[0]);
path.AddLine(points[4], points[2]);
path.AddLine(points[0], points[3]);
path.AddLine(points[3], points[1]);
path.AddLine(points[1], points[4]);

I get the following result:
TutorialStarRearranged.PNG

It is as if PDFPath requires the lines to be added in order, and that it draws without picking up the pen. Is this a correct understanding? Is there a way to avoid this so that I can add the lines in any order/not have to sort them? Thanks in advance.

scotthclearspaninc
 
Posts: 4
Joined: Sat Aug 01, 2015 5:23 pm

Mon Aug 03, 2015 10:15 am

Hello,

Thanks for your inquiry.
Your understanding is correct. If you want to avoid this. Please refer to the below method to draw the lines.
Code: Select all
page.Canvas.DrawLine(pen, points[2], points[0]);


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF