Using Area class of TALLPDF3.0 in .Net
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 sectionDocument document =
new Document();Section section = document.Sections.Add();
// the main content flow starts 20 points from the top edge of the pagesection.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 pagearea =
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 pagearea =
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 LASTarea =
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 LASTarea =
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 ONLYarea =
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 ONLYarea =
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
Write New Comment ▼
Write New Comment
Sorry! This knol's owner(s) have blocked you from editing, making suggestions, or commenting here.