InlineObjectSample.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 » InlineObjectSample.cs
using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents.composition;
using entitiesit.stefanochizzolini.clown.documents.contents.entities;
using it.stefanochizzolini.clown.documents.contents.fonts;
using filesit.stefanochizzolini.clown.files;

using System;
using System.Drawing;
using System.IO;

namespace it.stefanochizzolini.clown.samples{
  /**
    <summary>This sample demonstrates how to embed an image object within a content
    stream.</summary>
    <remarks>
      <para>Inline objects should be used sparingly, as they easily clutter content
      streams.</para>
      <para>The alternative (and preferred) way to insert an image object is via external
      object (XObject); its main advantage is to allow content reuse.</para>
    </remarks>
  */
  public class InlineObjectSample
    : 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.
      files::File file = new files::File();

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

      // (boilerplate metadata insertion -- ignore it)
      loader.BuildAccessories(document,this.GetType(),"Inline image","embedding an image within a content stream");

      // 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
    /**
      Populates a PDF file with contents.
    */
    private void Populate(
      Document document,
      SampleLoader loader
      )
    {
      Page page = new Page(document);
      document.Pages.Add(page);
      SizeF pageSize = page.Size.Value;

      PrimitiveFilter builder = new PrimitiveFilter(page);
      {
        BlockFilter blockFilter = new BlockFilter(builder);
        blockFilter.Hyphenation = true;
        blockFilter.Begin(
          new RectangleF(
            Margin,
            Margin,
            (float)pageSize.Width - Margin * 2,
            (float)pageSize.Height - Margin * 2
            ),
          AlignmentXEnum.Justify,
          AlignmentYEnum.Top
          );
        StandardType1Font bodyFont = new StandardType1Font(
          document,
          StandardType1Font.FamilyNameEnum.Courier,
          true,
          false
          );
        builder.SetFont(bodyFont,32);
        blockFilter.ShowText("Inline image sample"); blockFilter.ShowBreak();
        builder.SetFont(bodyFont,16);
        blockFilter.ShowText("Showing the GNU logo as an inline image within the page content stream.");
        blockFilter.End();
      }
      // Showing the 'GNU' image...
      {
        // Instantiate a jpeg image object!
        entities::Image image = entities::Image.Get(loader.InputPath + Path.DirectorySeparatorChar + "images" + Path.DirectorySeparatorChar + "gnu.jpg"); // Abstract image (entity).
        builder.ApplyMatrix(200,0,0,200,(pageSize.Width-200)/2,(pageSize.Height-200)/2);
        // Show the image!
        image.ToInlineObject(builder);
      }
      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.