TextFrameSample.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 » TextFrameSample.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.fonts;
using it.stefanochizzolini.clown.files;

using System.Drawing;

namespace it.stefanochizzolini.clown.samples{
  /**
    <summary>This sample demonstrates how to obtain the actual area (frame or bounding box)
    occupied by shown text.</summary>
  */
  public class TextFrameSample
    : ISample
  {
    #region dynamic
    #region interface
    #region public
    #region ISample
    public void Run(
      SampleLoader loader
      )
    {
      // 1. Instantiate a new PDF file!
      /* NOTE: a File object is the low-level (syntactic) representation of a PDF file. */
      File file = new File();

      // 2. Get its corresponding document!
      /* NOTE: a Document object is the high-level (semantic) representation of a PDF file. */
      Document document = file.Document;

      // 3. Insert the contents into the document!
      Populate(document,loader);

      // (boilerplate metadata insertion -- ignore it)
      loader.BuildAccessories(document,this.GetType(),"Text frame","getting the actual bounding box of text shown");

      // 4. Serialize the PDF file (again, boilerplate code -- see the SampleLoader class source code)!
      loader.Serialize(file,this.GetType().Name,false);
    }
    #endregion
    #endregion

    #region private
    /**
      <summary>Populates a PDF file with contents.</summary>
    */
    private void Populate(
      Document document,
      SampleLoader loader
      )
    {
      // 1. Add the page to the document!
      Page page = new Page(document); // Instantiates the page inside the document context.
      document.Pages.Add(page); // Puts the page in the pages collection.

      // 2. Create a content builder for the page!
      PrimitiveFilter builder = new PrimitiveFilter(page);

      BlockFilter blockFilter = new BlockFilter(builder);
      blockFilter.Begin(new RectangleF(300,400,200,100),AlignmentXEnum.Left,AlignmentYEnum.Middle);
      builder.SetFont(
        new StandardType1Font(
          document,
          StandardType1Font.FamilyNameEnum.Times,
          false,
          true
          ),
        12
        );
      builder.SetFillColor(new DeviceRGBColor(115f/255,164f/255,232f/255));
      blockFilter.ShowText("showText() methods return the actual bounding box of the shown text, allowing to precisely determine its location on the page.");
      blockFilter.End();

      builder.SetStrokeColor(new DeviceRGBColor(115f/255,164f/255,232f/255));

      // 3. Inserting contents...
      // Set the font to use!
      builder.SetFont(
        new StandardType1Font(
          document,
          StandardType1Font.FamilyNameEnum.Courier,
          true,
          false
          ),
        72
        );
      builder.DrawPolygon(
        builder.ShowText(
          "Text frame",
          new PointF(150,360),
          AlignmentXEnum.Left,
          AlignmentYEnum.Middle,
          45
          )
        );
      builder.Stroke();

      builder.SetFont(
        new OpenTypeFont(
          document,
          loader.InputPath + System.IO.Path.DirectorySeparatorChar + "fonts" + System.IO.Path.DirectorySeparatorChar + "Ruritania-Outline.ttf"
          ),
        102
        );
      builder.DrawPolygon(
        builder.ShowText(
          "Text frame",
          new PointF(300,600),
          AlignmentXEnum.Center,
          AlignmentYEnum.Middle,
          -25
          )
        );
      builder.Stroke();

      // 4. Flush the contents into the page!
      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.