LinkSample.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 » LinkSample.cs
using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.contents;
using it.stefanochizzolini.clown.documents.contents.colorSpaces;
using it.stefanochizzolini.clown.documents.contents.composition;
using entitiesit.stefanochizzolini.clown.documents.contents.entities;
using it.stefanochizzolini.clown.documents.contents.fonts;
using it.stefanochizzolini.clown.documents.fileSpecs;
using it.stefanochizzolini.clown.documents.interaction.actions;
using annotationsit.stefanochizzolini.clown.documents.interaction.annotations;
using it.stefanochizzolini.clown.documents.interaction.navigation.document;
using filesit.stefanochizzolini.clown.files;

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

namespace it.stefanochizzolini.clown.samples{
  /**
    <summary>This sample demonstrates how to apply links to a document.</summary>
  */
  public class LinkSample
    : ISample
  {
    #region dynamic
    #region interface
    #region public
    #region ISample
    public void Run(
      SampleLoader loader
      )
    {
      // 1. Creating the document...
      files::File file = new files::File();
      Document document = file.Document;
      Pages pages = document.Pages;

      // 2. Applying links...
      Page page = new Page(document);
      pages.Add(page);

      StandardType1Font font = new StandardType1Font(
        document,
        StandardType1Font.FamilyNameEnum.Courier,
        true,
        false
        );

      PrimitiveFilter builder = new PrimitiveFilter(page);
      BlockFilter blockFilter = new BlockFilter(builder);

      /*
        2.1. Goto-URI link.
      */
      {
        blockFilter.Begin(new RectangleF(30,100,200,50),AlignmentXEnum.Left,AlignmentYEnum.Middle);
        builder.SetFont(font,12);
        blockFilter.ShowText("Goto-URI link");
        builder.SetFont(font,8);
        blockFilter.ShowText("\nIt allows you to navigate to a network resource.");
        builder.SetFont(font,5);
        blockFilter.ShowText("\n\nClick on the box to go to the project's SourceForge.net repository.");
        blockFilter.End();

        try
        {
          /*
            NOTE: This statement instructs the PDF viewer to navigate to the given URI when the link is clicked.
          */
          annotations::Link link = new annotations::Link(
            page,
            new Rectangle(240,100,100,50),
            new GoToURI(
              document,
              new Uri("http://www.sourceforge.net/projects/clown")
              )
            );
          link.Border = new annotations::Border(
            document,
            3,
            annotations::Border.StyleEnum.Beveled,
            null
            );
        }
        catch(Exception exception)
        {throw new Exception("",exception);}
      }

      /*
        2.2. Embedded-goto link.
      */
      {
        // Get the path of the PDF file to attach!
        string filePath = loader.GetPdfFileChoice("Please select a PDF file to attach");

        /*
          NOTE: These statements instruct PDF Clown to attach a PDF file to the current document.
          This is necessary in order to test the embedded-goto functionality,
          as you can see in the following link creation (see below).
        */
        int fileAttachmentPageIndex = page.Index;
        string fileAttachmentName = "attachedSamplePDF";
        string fileName = System.IO.Path.GetFileName(filePath);
        annotations::FileAttachment attachment = new annotations::FileAttachment(
          page,
          new Rectangle(0, -20, 10, 10),
          new FileSpec(
            EmbeddedFile.Get(
              document,
              filePath
              ),
            fileName
            )
          );
        attachment.Name = fileAttachmentName;
        attachment.Text = "File attachment annotation";
        attachment.IconType = annotations::FileAttachment.IconTypeEnum.PaperClip;

        blockFilter.Begin(new RectangleF(30,170,200,50),AlignmentXEnum.Left,AlignmentYEnum.Middle);
        builder.SetFont(font,12);
        blockFilter.ShowText("Embedded-goto link");
        builder.SetFont(font,8);
        blockFilter.ShowText("\nIt allows you to navigate to a destination within an embedded PDF file.");
        builder.SetFont(font,5);
        blockFilter.ShowText("\n\nClick on the button to go to the 2nd page of the attached PDF file (" + fileName + ").");
        blockFilter.End();

        /*
          NOTE: This statement instructs the PDF viewer to navigate to the page 2 of a PDF file
          attached inside the current document as described by the FileAttachment annotation on page 1 of the current document.
        */
        annotations::Link link = new annotations::Link(
          page,
          new Rectangle(240,170,100,50),
          new GoToEmbedded(
            document,
            new GoToEmbedded.TargetObject(
              document,
              fileAttachmentPageIndex, // Page of the current document containing the file attachment annotation of the target document.
              fileAttachmentName, // Name of the file attachment annotation corresponding to the target document.
              null // No sub-target.
              ), // Target represents the document to go to.
            new RemoteDestination(
              document,
              1, // Show the page 2 of the target document.
              Destination.ModeEnum.Fit, // Show the target document page entirely on the screen.
              null // No view parameters.
              ) // The destination must be within the target document.
            )
          );
        link.Border = new annotations::Border(
          document,
          1,
          annotations::Border.StyleEnum.Dashed,
          new LineDash(new int[]{8,5,2,5})
          );
      }

      /*
        2.3. Textual link.
      */
      {
        blockFilter.Begin(new RectangleF(30,240,200,50),AlignmentXEnum.Left,AlignmentYEnum.Middle);
        builder.SetFont(font,12);
        blockFilter.ShowText("Textual link");
        builder.SetFont(font,8);
        blockFilter.ShowText("\nIt allows you to expose any kind of link (including the above-mentioned types) as text.");
        builder.SetFont(font,5);
        blockFilter.ShowText("\n\nClick on the text links to go either to the project's SourceForge.net repository or to the project's home page.");
        blockFilter.End();

        try
        {
          builder.BeginLocalState();
          builder.SetFont(font,10);
          builder.SetFillColor(new DeviceRGBColor(0,0,1));
          builder.ShowText(
            "PDF Clown Project's repository at SourceForge.net",
            new PointF(240,265),
            AlignmentXEnum.Left,
            AlignmentYEnum.Middle,
            0,
            new GoToURI(
              document,
              new Uri("http://www.sourceforge.net/projects/clown")
              )
            );
          builder.ShowText(
            "PDF Clown Project's home page",
            new PointF(240,285),
            AlignmentXEnum.Left,
            AlignmentYEnum.Bottom,
            -90,
            new GoToURI(
              document,
              new Uri("http://clown.stefanochizzolini.it")
              )
            );
          builder.End();
        }
        catch(Exception e)
        {}
      }

      builder.Flush();

      // (boilerplate metadata insertion -- ignore it)
      loader.BuildAccessories(document,this.GetType(),"Link annotations","applying link annotations");

      // 3. Serialize the PDF file (again, boilerplate code -- see the SampleLoader class source code)!
      loader.Serialize(file,this.GetType().Name,false);
    }
    #endregion
    #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.