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

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)
For HTML2PDF and XML2PDF solution check our PDFDoc Scout ActiveX library instead