using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents.colorSpaces;
using it.stefanochizzolini.clown.documents.contents.composition;
using it.stefanochizzolini.clown.documents.contents.entities;
using it.stefanochizzolini.clown.documents.contents.fonts;
using it.stefanochizzolini.clown.documents.contents.xObjects;
using it.stefanochizzolini.clown.documents.fileSpecs;
using annotationsit.stefanochizzolini.clown.documents.interaction.annotations;
using filesit.stefanochizzolini.clown.files;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
namespace it.stefanochizzolini.clown.samples{
/**
<summary>This sample demonstrates how to insert annotations into a PDF document.</summary>
*/
public class AnnotationSample
: ISample
{
#region dynamic
#region interface
#region public
#region ISample
public void Run(
SampleLoader loader
)
{
// 1. PDF file instantiation.
files::File file = new files::File();
Document document = file.Document;
// 2. Content creation.
Populate(loader,document);
// (boilerplate metadata insertion -- ignore it)
loader.BuildAccessories(document,this.GetType(),"Annotations","inserting annotations");
// 3. Serialize the PDF file (again, boilerplate code -- see the SampleLoader class source code)!
loader.Serialize(file,this.GetType().Name,false);
}
#endregion
#endregion
#region private
private void Populate(
SampleLoader loader,
Document document
)
{
Page page = new Page(document);
document.Pages.Add(page);
StandardType1Font font = new StandardType1Font(
document,
StandardType1Font.FamilyNameEnum.Courier,
true,
false
);
PrimitiveFilter builder = new PrimitiveFilter(page);
builder.SetFont(font,12);
builder.ShowText("Note annotation:", new Point(35,35));
annotations::Note note = new annotations::Note(
page,
new Point(50, 50),
"Note annotation"
);
note.IconType = annotations::Note.IconTypeEnum.Help;
note.ModificationDate = new DateTime();
note.IsOpen = true;
builder.ShowText("Callout note annotation:", new Point(35,85));
annotations::CalloutNote calloutNote = new annotations::CalloutNote(
page,
new Rectangle(50, 100, 200, 24),
"Callout note annotation"
);
calloutNote.Justification = annotations::CalloutNote.JustificationEnum.Right;
calloutNote.Line = new annotations::CalloutNote.LineObject(
page,
new Point(150,650),
new Point(100,600),
new Point(50,100)
);
builder.ShowText("File attachment annotation:", new Point(35,135));
annotations::FileAttachment attachment = new annotations::FileAttachment(
page,
new Rectangle(50, 150, 12, 12),
new FileSpec(
EmbeddedFile.Get(
document,
loader.InputPath + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar + "gnu.jpg"
),
"happyGNU.jpg"
)
);
attachment.Text = "File attachment annotation";
attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip;
builder.BeginLocalState();
builder.ShowText("Line annotation:", new Point(35,185));
builder.SetFont(font,10);
builder.ShowText("Arrow:", new Point(50,200));
annotations::Line line = new annotations::Line(
page,
new Point(50, 260),
new Point(200,210)
);
line.FillColor = new DeviceRGBColor(1,0,0);
line.StartStyle = annotations::Line.LineEndStyleEnum.Circle;
line.EndStyle = annotations::Line.LineEndStyleEnum.ClosedArrow;
line.Text = "Arrow line annotation";
line.CaptionVisible = true;
builder.ShowText("Dimension:", new Point(300,200));
line = new annotations::Line(
page,
new Point(300,220),
new Point(500,220)
);
line.LeaderLineLength = 20;
line.LeaderLineExtensionLength = 10;
line.Text = "Dimension line annotation";
line.CaptionVisible = true;
builder.End();
builder.ShowText("Scribble annotation:", new Point(35,285));
annotations::Scribble scribble = new annotations::Scribble(
page,
new RectangleF(50, 300, 100, 30),
new List<IList<PointF>>(
new List<PointF>[]
{
new List<PointF>(
new PointF[]
{
new PointF(50,300),
new PointF(70,310),
new PointF(100,320)
}
)
}
)
);
scribble.Text = "Scribble annotation";
builder.ShowText("Rectangle annotation:", new Point(35,335));
annotations::Rectangle rectangle = new annotations::Rectangle(
page,
new Rectangle(50, 350, 100, 30)
);
rectangle.FillColor = new DeviceRGBColor(1,0,0);
rectangle.Text = "Rectangle annotation";
builder.ShowText("Ellipse annotation:", new Point(35,385));
annotations::Ellipse ellipse = new annotations::Ellipse(
page,
new Rectangle(50, 400, 100, 30)
);
ellipse.FillColor = new DeviceRGBColor(0,0,1);
ellipse.Text = "Ellipse annotation";
builder.ShowText("Rubber stamp annotation:", new Point(35,435));
annotations::RubberStamp rubberStamp = new annotations::RubberStamp(
page,
new Rectangle(50, 450, 100, 30),
annotations::RubberStamp.IconTypeEnum.Approved
);
rubberStamp.Text = "Rubber stamp annotation";
builder.ShowText("Caret annotation:", new Point(35,485));
annotations::Caret caret = new annotations::Caret(
page,
new Rectangle(50, 500, 100, 30)
);
caret.Text = "Caret annotation";
caret.SymbolType = annotations::Caret.SymbolTypeEnum.NewParagraph;
builder.Flush();
}
#endregion
#endregion
#endregion
}
}
|