This sample shows how to draw straight lines and cubic Bezier curves.
All drawing in a PDF document is done using methods and properties of PdfCanvas class. You can access it using Canvas property of PdfPage, PdfWatermark or PdfPattern classes.
There is a plenty of methods that draw lines, curves and shapes. All such methods have names that start with "Draw" (e.g. DrawLineTo method). All kinds of lines are drawn using current pen (PdfCanvas.Pen property).
using System.Diagnostics; using System.Drawing; namespace BitMiracle.Docotic.Pdf.Samples { public static class LinesAndCurves { public static void Main() { // NOTE: // When used in trial mode, the library imposes some restrictions. // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx // for more information. PdfDocument pdf = new PdfDocument(); PdfCanvas canvas = pdf.Pages[0].Canvas; //draw star PdfPoint startPosition = new PdfPoint(30, 80); canvas.CurrentPosition = startPosition; canvas.DrawLineTo(110, 80); canvas.DrawLineTo(45, 110); canvas.DrawLineTo(70, 60); canvas.DrawLineTo(95, 110); canvas.DrawLineTo(startPosition); //draw bezier curve canvas.CurrentPosition = new PdfPoint(150, 90); canvas.DrawCurveTo(new PdfPoint(180, 60), new PdfPoint(230, 120), new PdfPoint(250, 90)); //draw arc canvas.DrawArc(new PdfPoint(350, 90), 70, 40, 30, 280); string pathToFile = "LinesAndCurves.pdf"; pdf.Save(pathToFile); pdf.Dispose(); Process.Start(pathToFile); } } }
Imports System.Diagnostics Imports System.Drawing Imports BitMiracle.Docotic.Pdf Namespace BitMiracle.Docotic.Pdf.Samples Public NotInheritable Class LinesAndCurves Public Shared Sub Main() ' NOTE: ' When used in trial mode, the library imposes some restrictions. ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx ' for more information. Dim pdf As New PdfDocument() Dim canvas As PdfCanvas = pdf.Pages(0).Canvas 'draw star Dim startPosition As New PdfPoint(30, 80) canvas.CurrentPosition = startPosition canvas.DrawLineTo(110, 80) canvas.DrawLineTo(45, 110) canvas.DrawLineTo(70, 60) canvas.DrawLineTo(95, 110) canvas.DrawLineTo(startPosition) 'draw bezier curve canvas.CurrentPosition = New PdfPoint(150, 90) canvas.DrawCurveTo(New PdfPoint(180, 60), New PdfPoint(230, 120), New PdfPoint(250, 90)) 'draw arc canvas.DrawArc(New PdfPoint(350, 90), 70, 40, 30, 280) Dim pathToFile As String = "LinesAndCurves.pdf" pdf.Save(pathToFile) pdf.Dispose() Process.Start(pathToFile) End Sub End Class End Namespace
