UnicodeSample.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 » UnicodeSample.cs
using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents.composition;
using it.stefanochizzolini.clown.documents.contents.entities;
using fontsit.stefanochizzolini.clown.documents.contents.fonts;
using it.stefanochizzolini.clown.documents.contents.xObjects;
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 the PDF Clown's support to Unicode-aware fonts.</summary>
  */
  public class UnicodeSample
    : ISample
  {
    #region static
    #region fields
    private const float Margin = 36;
    #endregion
    #endregion

    #region dynamic
    #region interface
    #region public
    #region ISample
    public void Run(
      SampleLoader loader
      )
    {
      // 1. Instantiate a new PDF file!
      files::File file = new files::File();

      // 2. Get its corresponding document!
      Document document = file.Document;

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

      // (boilerplate metadata insertion -- ignore it)
      loader.BuildAccessories(document,this.GetType(),"Unicode","using Unicode fonts");

      // 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
    /**
      <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.1. Create a content builder for the page!
      PrimitiveFilter builder = new PrimitiveFilter(page);

      // 2.2. Create a block builder!
      BlockFilter blockFilter = new BlockFilter(builder);

      // 3. Inserting contents...
      // Define the font to use!
      fonts::Font font = new fonts::OpenTypeFont(
        document,
        loader.InputPath + Path.DirectorySeparatorChar + "fonts" + Path.DirectorySeparatorChar + "GenR102.TTF"
        );
      // Define the paragraph break size!
      Size breakSize = new Size(0,10);
      // Define the text to show!
      string[] titles = new string[]
        {
          " 1",
          "ASARIYA SINTE (1)",
          "Article 1",
          "Article premier",
          " 1",
          "Artculo 1",
          "Artikel 1",
          "Madde 1",
          "Artikel 1",
          "Articolo 1",
          "Artyku 1",
          "Bend 1",
          "Abala kn."
        };
      string[] bodies = new string[]
        {
          "'           .      ,         .",
          "Aduniya kuna n gu ibuna damayo hi n dei-dei nn daama nna n burucinitr f, n lasabu nna laakari ya nam nn m huro cr kuna nyanze tr b.",
          "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.",
          "Tous les tres humains naissent libres et gaux en dignit et en droits. Ils sont dous de raison et de conscience et doivent agir les uns envers les autres dans un esprit de fraternit.",
          "          .               .",
          "Todos los seres humanos nacen libres e iguales en dignidad y derechos y, dotados como estn de razn y conciencia, deben comportarse fraternalmente los unos con los otros.",
          "Alle Menschen sind frei und gleich an Wrde und Rechten geboren. Sie sind mit Vernunft und Gewissen begabt und sollen einander im Geist der Brderlichkeit begegnen.",
          "Btn insanlar hr, haysiyet ve haklar bakmndan eit doarlar. Akl ve vicdana sahiptirler ve birbirlerine kar kardelik zihniyeti ile hareket etmelidirler.",
          "Alla mnniskor r fdda fria och lika i vrde och rttigheter. De har utrustats med frnuft och samvete och br handla gentemot varandra i en anda av gemenskap.",
          "Tutti gli esseri umani nascono liberi ed eguali in dignit e diritti. Essi sono dotati di ragione e di coscienza e devono agire gli uni verso gli altri in spirito di fratellanza.",
          "Wszyscy ludzie rodz si wolni i rwni pod wzgldem swej godnoci i swych praw. S oni obdarzeni rozumem i sumieniem i powinni postpowa wobec innych w duchu braterstwa.",
          "Hem mirov azad  di weqar  mafan de wekhev tn dinyay. Ew xwed hi  ur in  div li hember hev bi zihniyeteke bratiy bilivin.",
          "Gbogbo nyn ni a b n mnira; iy ti t kkan s dgba. Wn n bn ti lky ti ti r-okn,  s ye k won  ma hw s ara won gg b omo y."
        };
      string[] sources = new string[]
      {
        "http://www.unhchr.ch/udhr/lang/grk.htm",
        "http://www.unhchr.ch/udhr/lang/den.htm",
        "http://www.unhchr.ch/udhr/lang/eng.htm",
        "http://www.unhchr.ch/udhr/lang/frn.htm",
        "http://www.unhchr.ch/udhr/lang/rus.htm",
        "http://www.unhchr.ch/udhr/lang/spn.htm",
        "http://www.unhchr.ch/udhr/lang/ger.htm",
        "http://www.unhchr.ch/udhr/lang/trk.htm",
        "http://www.unhchr.ch/udhr/lang/swd.htm",
        "http://www.unhchr.ch/udhr/lang/itn.htm",
        "http://www.unhchr.ch/udhr/lang/pql.htm",
        "http://www.unhchr.ch/udhr/lang/kdb1.htm",
        "http://www.unhchr.ch/udhr/lang/yor.htm"
      };
      // Begin the content block!
      blockFilter.Begin(
        new RectangleF(
          Margin,
          Margin,
          page.Size.Value.Width - Margin * 2,
          page.Size.Value.Height - Margin * 2
          ),
        AlignmentXEnum.Justify,
        AlignmentYEnum.Top
        );
      for(
        int index = 0,
          length = titles.Length;
        index < length;
        index++
        )
      {
        builder.SetFont(font,12);
        blockFilter.ShowText(titles[index]);
        blockFilter.ShowBreak();

        builder.SetFont(font,11);
        blockFilter.ShowText(bodies[index]);
        blockFilter.ShowBreak(AlignmentXEnum.Right);

        builder.SetFont(font,8);
        blockFilter.ShowText("[Source: " + sources[index] + "]");
        blockFilter.ShowBreak(breakSize,AlignmentXEnum.Justify);
      }
      // End the content block!
      blockFilter.End();

      // 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.