BarcodeSample.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 » BarcodeSample.cs
using it.stefanochizzolini.clown.documents;
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.files;

using System;
using System.Collections.Generic;
using System.Drawing;

namespace it.stefanochizzolini.clown.samples{
  /**
    <summary>This sample demonstrates how to show bar codes in a PDF file.</summary>
  */
  public class BarcodeSample
    : 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. PDF file instantiation.
      File file = new File();

      // 2. Content creation.
      Document document = file.Document;
      Populate(document,loader);

      // (boilerplate metadata insertion -- ignore it)
      loader.BuildAccessories(document,this.GetType(),"Barcode","showing barcodes");

      // 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
      )
    {
      // Get the abstract barcode entity!
      EAN13Barcode barcode = new EAN13Barcode("8012345678901");
      // Create the reusable barcode within the document!
      XObject barcodeXObject = barcode.ToXObject(document);

      Pages pages = document.Pages;
      // Page 1.
      {
        Page page = new Page(document);
        pages.Add(page);
        Size pageSize = page.Size.Value;

        PrimitiveFilter builder = new PrimitiveFilter(page);
        {
          BlockFilter blockFilter = new BlockFilter(builder);
          blockFilter.Hyphenation = true;
          blockFilter.Begin(
            new RectangleF(
              Margin,
              Margin,
              pageSize.Width - Margin * 2,
              pageSize.Height - Margin * 2
              ),
            AlignmentXEnum.Left,
            AlignmentYEnum.Top
            );
          StandardType1Font bodyFont = new StandardType1Font(
            document,
            StandardType1Font.FamilyNameEnum.Courier,
            true,
            false
            );
          builder.SetFont(bodyFont,32);
          blockFilter.ShowText("Barcode sample"); blockFilter.ShowBreak();
          builder.SetFont(bodyFont,16);
          blockFilter.ShowText("Showing the EAN-13 Bar Code on different compositions:"); blockFilter.ShowBreak();
          blockFilter.ShowText("- page 1: on the lower right corner of the page, 100pt wide;"); blockFilter.ShowBreak();
          blockFilter.ShowText("- page 2: on the middle of the page, 1/3-page wide, 25 degree counterclockwise rotated;"); blockFilter.ShowBreak();
          blockFilter.ShowText("- page 3: filled page, 90 degree clockwise rotated."); blockFilter.ShowBreak();
          blockFilter.End();
        }

        // Show the barcode!
        builder.ShowXObject(
          barcodeXObject,
          new PointF(
            pageSize.Width - Margin,
            pageSize.Height - Margin
            ),
          new Size(100,0),
          AlignmentXEnum.Right,
          AlignmentYEnum.Bottom,
          0
          );
        builder.Flush();
      }

      // Page 2.
      {
        Page page = new Page(document);
        pages.Add(page);
        Size pageSize = page.Size.Value;

        PrimitiveFilter builder = new PrimitiveFilter(page);
        // Show the barcode!
        builder.ShowXObject(
          barcodeXObject,
          new PointF(
            pageSize.Width / 2,
            pageSize.Height / 2
            ),
          new Size((int)pageSize.Width/3,0),
          AlignmentXEnum.Center,
          AlignmentYEnum.Middle,
          25
          );
        builder.Flush();
      }

      // Page 3.
      {
        Page page = new Page(document);
        pages.Add(page);
        Size pageSize = page.Size.Value;

        PrimitiveFilter builder = new PrimitiveFilter(page);
        // Show the barcode!
        builder.ShowXObject(
          barcodeXObject,
          new PointF(
            pageSize.Width / 2,
            pageSize.Height / 2
            ),
          new Size((int)pageSize.Height,(int)pageSize.Width),
          AlignmentXEnum.Center,
          AlignmentYEnum.Middle,
          -90
          );
        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.