AnnotationSample.cs :  » PDF » PDF-Clown » it » stefanochizzolini » clown » samples » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » PDF » PDF Clown 
PDF Clown » it » stefanochizzolini » clown » samples » AnnotationSample.cs
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
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.