Products
TallPDF.NET 4.0
Created
7/4/2014
Tags
Generate PDF

This code sample shows how to use document layout options

// add a section that has A4-sized pages Section section = document.Sections.Add(); section.PageSize = PageSize.A4;

// set left and right margin to 150 points which equals to 2.08 inch or 5.29 cm section.Margin.Left = 150; section.Margin.Right = 150;

TextParagraph textParagraph = new TextParagraph(); textParagraph.SpacingBefore = 10; textParagraph.Justified = true; textParagraph.Fragments.Add(new Fragment("Left and right margin are set to 150 points.")); section.Paragraphs.Add( textParagraph );

// left aligned paragraph textParagraph = new TextParagraph(); textParagraph.SpacingBefore = 10; textParagraph.Border = new Border(new SolidBrush(System.Drawing.Color.LightBlue)); textParagraph.HorizontalAlignment = HorizontalAlignment.Left; textParagraph.Fragments.Add( new Fragment( "Left" ) ); section.Paragraphs.Add( textParagraph );

// center aligned paragraph textParagraph = new TextParagraph(); textParagraph.SpacingBefore = 10; textParagraph.Border = new Border( new SolidBrush( System.Drawing.Color.LightBlue ) ); textParagraph.HorizontalAlignment = HorizontalAlignment.Center; textParagraph.Fragments.Add( new Fragment( "Center" ) ); section.Paragraphs.Add( textParagraph );

// right aligned paragraph textParagraph = new TextParagraph(); textParagraph.SpacingBefore = 10; textParagraph.Border = new Border( new SolidBrush( System.Drawing.Color.LightGreen ) ); textParagraph.HorizontalAlignment = HorizontalAlignment.Right; textParagraph.Fragments.Add( new Fragment( "Right" ) ); section.Paragraphs.Add( textParagraph );

document.Write( file ); }]]>