Using Area class of TALLPDF3.0 in .Net

This program clearly demonstrates how to use Area class of TALLPDF3.0 in .Net framework


Using Area class of TALLPDF3.0 in .Net

 
Note: Dont forget to add 
TallComponents.PDF.Layout dll in references
 

using

System.IO;

using

TallComponents.PDF.Layout;

using

TallComponents.PDF.Layout.Brushes;

using

TallComponents.PDF.Layout.Fonts;

using

TallComponents.PDF.Layout.Paragraphs;

namespace

TallComponents.Samples.TallPDF

{

public class Areas

{

const string text = "With TallPDF.NET you can create PDF documents " +

"by building an instance of the TallPDF.NET Document " +

"Object Model. The TallComponents team has produced " +

"a DOM that is extremely intuitive and yet powerful. " +

"This allows you to create both simple and complex " +

"documents fast.";

static void Main()

{

// write the PDF document to disk in push mode.

using( FileStream file = new FileStream( @"..\..\areas.pdf", FileMode.Create, FileAccess.Write ) )

{

// create a new document and a section

Document document =

new Document();

Section section = document.Sections.Add();

// the main content flow starts 20 points from the top edge of the page

section.Margin.Top = 20;

Area area;

TextParagraph textParagraph;

Fragment fragment;

// create dummy content to fill the pages

for ( int i=0; i<50; i++ )

{

textParagraph =

new TextParagraph();

textParagraph.SpacingAfter = 20;

section.Paragraphs.Add( textParagraph );

fragment =

new Fragment( text );

textParagraph.Fragments.Add( fragment );

}

// create an area that appears on the foreground of EACH page

area =

new Area( section.PageSize.Width - 220, section.PageSize.Height - 20, 200, 100 );

section.ForegroundAreas.Add( area );

fragment =

new Fragment( "This area appears on the foreground of each page.", Font.Helvetica, 16 );

fragment.TextColor = System.Drawing.Color.Blue;

textParagraph =

new TextParagraph();

textParagraph.Fragments.Add( fragment );

textParagraph.Border =

new Border( System.Drawing.Color.Orange, 1, new SolidBrush( System.Drawing.Color.Yellow ) );

area.Paragraphs.Add( textParagraph );

// create an area that appears in the background of EACH page

area =

new Area( 50, 200, 200, 100 );

section.BackgroundAreas.Add( area );

fragment =

new Fragment( "This area appears in the background of each page.", Font.Helvetica, 16 );

fragment.TextColor = System.Drawing.Color.Blue;

textParagraph =

new TextParagraph();

textParagraph.Fragments.Add( fragment );

textParagraph.Border =

new Border( System.Drawing.Color.Orange, 1, new SolidBrush( System.Drawing.Color.Yellow ) );

area.Paragraphs.Add( textParagraph );

// create an area that appears on the foreground of each EVEN page except the FIRST or LAST

area =

new Area( ( section.PageSize.Width / 2 ) - 100, section.PageSize.Height / 2, 200, 100 );

area.Odd = area.First = area.Last =

false;

section.ForegroundAreas.Add( area );

fragment =

new Fragment( "This area appears on the foreground of each EVEN page, except on the FIRST or LAST.", Font.Helvetica, 16 );

fragment.TextColor = System.Drawing.Color.Blue;

textParagraph =

new TextParagraph();

textParagraph.Fragments.Add( fragment );

textParagraph.Border =

new Border( System.Drawing.Color.Orange, 1, new SolidBrush( System.Drawing.Color.Yellow ) );

area.Paragraphs.Add( textParagraph );

// create an area that appears on the foreground of each ODD page except the FIRST or LAST

area =

new Area( ( section.PageSize.Width / 2 ) - 100, section.PageSize.Height / 2, 200, 100 );

area.Even = area.First = area.Last =

false;

section.ForegroundAreas.Add( area );

fragment =

new Fragment( "This area appears on the foreground of each ODD page, except on the FIRST or LAST.", Font.Helvetica, 16 );

fragment.TextColor = System.Drawing.Color.Blue;

textParagraph =

new TextParagraph();

textParagraph.Fragments.Add( fragment );

textParagraph.Border =

new Border( System.Drawing.Color.Orange, 1, new SolidBrush( System.Drawing.Color.Yellow ) );

area.Paragraphs.Add( textParagraph );

// create an area that appears on the FIRST page ONLY

area =

new Area( ( section.PageSize.Width / 2 ) - 100, section.PageSize.Height / 2, 200, 100 );

area.Middle = area.Last =

false;

section.ForegroundAreas.Add( area );

fragment =

new Fragment( "This area appears on the FIRST page only.", Font.Helvetica, 16 );

fragment.TextColor = System.Drawing.Color.Blue;

textParagraph =

new TextParagraph();

textParagraph.Fragments.Add( fragment );

textParagraph.Border =

new Border( System.Drawing.Color.Orange, 1, new SolidBrush( System.Drawing.Color.Yellow ) );

area.Paragraphs.Add( textParagraph );

// create an area that appears on the LAST page ONLY

area =

new Area( ( section.PageSize.Width / 2 ) - 100, section.PageSize.Height / 2, 200, 100 );

area.First = area.Middle =

false;

section.ForegroundAreas.Add( area );

fragment =

new Fragment( "This area appears on the LAST page only.", Font.Helvetica, 16 );

fragment.TextColor = System.Drawing.Color.Blue;

textParagraph =

new TextParagraph();

textParagraph.Fragments.Add( fragment );

textParagraph.Border =

new Border( System.Drawing.Color.Orange, 1, new SolidBrush( System.Drawing.Color.Yellow ) );

area.Paragraphs.Add( textParagraph );

document.Write( file );

}

}

}

}

Comments

Article rating:
Your rating:

Categories

Based on community consensus.

Activity for this knol

This week:

31pageviews

Totals:

456pageviews