-
Notifications
You must be signed in to change notification settings - Fork 3
/
ShapeHelper.cs
71 lines (63 loc) · 2.47 KB
/
ShapeHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using iDiTect.Pdf.ColorSpaces;
using iDiTect.Pdf.Editing;
using iDiTect.Pdf.IO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
namespace iDiTect.Pdf.Demo
{
public static class ShapeHelper
{
public static void AddShape()
{
//This example is using page level builder
PdfDocument document = new PdfDocument();
PdfPage page = document.Pages.AddPage();
PageContentBuilder builder = new PageContentBuilder(page);
//Add line shape
builder.GraphicState.StrokeColor = new RgbColor(255, 0, 0);
builder.DrawLine(new Point(10, 10), new Point(200, 20));
//Add rectangle shape by Block object
Block block = new Block();
block.GraphicState.StrokeColor = new RgbColor(255, 0, 0);
block.GraphicState.FillColor = new RgbColor(0, 255, 0);
block.GraphicState.IsFilled = true;
block.InsertRectangle(new Rect(0, 0, 50, 50));
builder.Position.Translate(10, 20);
builder.DrawBlock(block);
using (FileStream fs = File.Create("AddShape.pdf"))
{
PdfFile pdfFile = new PdfFile();
pdfFile.Export(document, fs);
}
}
public static void AddShape2()
{
//This example is using document level builder
PdfDocument document = new PdfDocument();
using (PdfDocumentBuilder builder = new PdfDocumentBuilder(document))
{
//Add line shape
Block lineBlock = new Block();
lineBlock.GraphicState.StrokeColor = new RgbColor(255, 0, 0);
lineBlock.InsertLine(new Point(10, 10), new Point(200, 20));
builder.InsertBlock(lineBlock);
//Add rectangle shape
Block rectBlock = new Block();
rectBlock.GraphicState.StrokeColor = new RgbColor(255, 0, 0);
rectBlock.GraphicState.FillColor = new RgbColor(0, 255, 0);
rectBlock.GraphicState.IsFilled = true;
rectBlock.InsertRectangle(new Rect(0, 0, 50, 50));
builder.InsertBlock(rectBlock);
}
using (FileStream fs = File.Create("AddShape2.pdf"))
{
PdfFile pdfFile = new PdfFile();
pdfFile.Export(document, fs);
}
}
}
}