Home Features Download Tutorial Version History License PDF Mosaic Blog Source Code
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.
C# :
using PDFMosaic; using System.Drawing; namespace LinesAndCurves { class LinesAndCurves { static void Main(string[] args) { PDFDocument document = new PDFDocument(); document.Pages.Add(new PDFPage(PDFPaperFormat.A4)); PDFCanvas canvas = document.Pages[0].Canvas; PDFFont font = new PDFFont(PDFStandardFont.Helvetica, 8, false, false); PDFSolidPen penCurve = new PDFSolidPen(); PDFSolidPen penLine = new PDFSolidPen(); PDFSolidBrush brush = new PDFSolidBrush(); penLine.DashPattern = new PDFDashPattern(new float[] { 2, 2 }, 1); canvas.DrawCurve(penCurve, 100, 100, 200, 200, 100, 300, 200, 400); canvas.DrawLine(penLine, 100, 100, 200, 200); canvas.DrawLine(penLine, 100, 300, 200, 400); canvas.DrawCurve(penCurve, 300, 100, 200, 300, 400, 200, 400, 100); canvas.DrawLine(penLine, 300, 100, 200, 300); canvas.DrawLine(penLine, 400, 200, 400, 100); canvas.DrawString("100,100", font, brush, 100, 90); canvas.DrawString("200,200", font, brush, 200, 200); canvas.DrawString("100,300", font, brush, 100, 290); canvas.DrawString("200,400", font, brush, 200, 400); document.Save("LinesAndCurves.pdf", true); } } }
Visual Basic :
Imports PDFMosaic Imports System.Drawing Module LinesAndCurves Sub Main() Dim document As PDFDocument = New PDFDocument() document.Pages.Add(New PDFPage(PDFPaperFormat.A4)) Dim canvas As PDFCanvas = document.Pages(0).Canvas Dim penCurve As PDFSolidPen = New PDFSolidPen() Dim penLine As PDFSolidPen = New PDFSolidPen() penLine.DashPattern = New PDFDashPattern(New Single() {2, 2}, 1) canvas.DrawCurve(penCurve, 100, 100, 200, 200, 100, 300, 200, 400) canvas.DrawLine(penLine, 100, 100, 200, 200) canvas.DrawLine(penLine, 100, 300, 200, 400) canvas.DrawCurve(penCurve, 300, 100, 200, 300, 400, 200, 400, 100) canvas.DrawLine(penLine, 300, 100, 200, 300) canvas.DrawLine(penLine, 400, 200, 400, 100) Dim font As PDFFont = New PDFFont(PDFStandardFont.Helvetica, 8, False, False) Dim brush As PDFSolidBrush = New PDFSolidBrush() canvas.DrawString("100,100", font, brush, 100, 90) canvas.DrawString("200,200", font, brush, 200, 200) canvas.DrawString("100,300", font, brush, 100, 290) canvas.DrawString("200,400", font, brush, 200, 400) document.Save("LinesAndCurves.pdf", True) End Sub End Module
Home Features Download Tutorial Version History License PDF Mosaic Blog Source Code