Home
We need your feedback!

Bytescout.PDF for .NET


Subscribe to Our Bi-Monthly Newsletter (tips, new releases, specials):
 Subscribe in a reader
 PRODUCTS  |  DOWNLOAD  |  PURCHASE  |  SUPPORT  |  TESTIMONIALS   |  NEWS  | 

Bytescout.PDF library for .NET - drawing lines in PDF document

Download Free Trial Buy Now More Information
For HTML2PDF and XML2PDF solution check our PDFDoc Scout ActiveX library instead

Drawing a line in PDF document

This example demonstrates how to draw a line using Drawing class in Bytescout.PDF library

Lines in PDF document made using Bytescout.PDF library

Download example source code: bytescoutpdf_lines.zip (10 KB)

using System;
using System.Collections.Generic;
using System.Text;
using Bytescout.PDF;
using System.Diagnostics;

namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
// Create main PDF Doc Engine
PDFDocEngine engine = new PDFDocEngine("", "");

// Add new document
Document document = engine.AddDocument();

// Append new page to the document
Page page = document.AddPage(PageSizeType.A3, PageOrientationType.LandScape);

// Create new drawing
Drawing drawing = page.AddDrawing();

// Line width
const double lineWidth = 10.0f;

// Set Line Width
drawing.SetLineWidth(lineWidth);

// Set lines join style
drawing.SetLineJoin(LineJoinType.Round);
// Set lines cap style
drawing.SetLineCap(LineCapType.Round);

// Draw from point with coordinate (100, 100)...
drawing.MoveTo(100.0f, 100.0f);
// ... to point with coordinate (100, 200)
drawing.LineTo(100.0f, 200.0f);
// Draw from point with coordinate (100, 100)...
drawing.MoveTo(100.0f, 100.0f);
// ... to point with coordinate (200, 100)
drawing.LineTo(200.0f, 100.0f);

// Stroke lines
drawing.Stroke();

// Create new path
drawing.NewPath();
// Draw from point with coordinate (100, 400)...
drawing.MoveTo(100.0f, 400.0f);
// ... to point with coordinate (100, 500) and then ...
drawing.LineTo(100.0f, 500.0f);
// ... to point with coordinate (200, 500) and then ...
drawing.LineTo(200.0f, 500.0f);
// ... to point with coordinate (200, 400)
drawing.LineTo(200.0f, 400.0f);
// Close path
drawing.ClosePath();

// Create blue fill colot
Color fillColor = Drawing.RGBToColor(0, 0, 255);

// Set fill color
drawing.SetFillColor(fillColor);

// Sets current path as a clipping boundaries for the first filling the
// inside with the current fill color (uses the "non-zero winding number" rule ),
// and then stroking the path with the current stroke color
drawing.EoFillAndStroke();

// Closing drawing on the page
drawing.Close();

// Save document
document.Save("Lines.pdf");


// open generated PDF document in default PDF viewer installed in Windows
Process.Start("Lines.pdf");
}
}
}

Download example source code: bytescoutpdf_lines.zip (10 KB)

Download Free Trial Buy Now More Information
For HTML2PDF and XML2PDF solution check our PDFDoc Scout ActiveX library instead

"Hello, World!" quick start step-by-step tutorials:

Advanced Examples:

HOME  |  CONTACT US

Copyright © ByteScout, 2003-2010. Privacy Statement
Microsoft®, Windows®, Windows 2000®, Windows Server®, Windows Vista®, Internet Explorer®, .NET Framework®, ActiveX®, Visual Basic®, Visual C#®, ASP®, ASP.NET®, Excel®, PowerPoint®, are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. Adobe®, Flash® and Acrobat® are registered trademarks of Adobe Systems, Incorporated. Mozilla®, Firefox® and the Mozilla and Firefox Logos are registered trademarks of the Mozilla Foundation. Other product names or brandnames used herein are for identification purposes only and might be trademarks or registered trademarks of their respective companies. We disclaim any and all rights to those marks.