using
System.IO;using
TallComponents.PDF.Layout;using
TallComponents.PDF.Layout.Paragraphs;namespace
TallComponents.Samples.TallPDF{
public class TextFormatting{
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(){
using( FileStream file = new FileStream( @"..\..\TextFormatting.pdf", FileMode.Create, FileAccess.Write ) ){
Document document =
new Document();Section section = document.Sections.Add();
section.PageSize = PageSize.A4;
TextParagraph textParagraph;
// Just display the dummy text without setting any additional propertiessection.Paragraphs.Add( CreateTextParagraph( "TextParagraph with default properties:" ) );
section.Paragraphs.Add( CreateTextParagraph( text, System.Drawing.Color.Blue ) );
// Set alignment to rightsection.Paragraphs.Add( CreateTextParagraph( "textParagraph.HorizontalAlignment = HorizontalAlignment.Right" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.HorizontalAlignment = HorizontalAlignment.Right;
section.Paragraphs.Add( textParagraph );
// Set alignment to centersection.Paragraphs.Add( CreateTextParagraph( "textParagraph.HorizontalAlignment = HorizontalAlignment.Center" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.HorizontalAlignment = HorizontalAlignment.Center;
section.Paragraphs.Add( textParagraph );
// Display the textparagraph justifiedsection.Paragraphs.Add( CreateTextParagraph( "textParagraph.Justified = true" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.Justified =
true;section.Paragraphs.Add( textParagraph );
// Set linespacingsection.Paragraphs.Add( CreateTextParagraph( "textParagraph.LineSpacing = 5" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.LineSpacing = 5;
section.Paragraphs.Add( textParagraph );
// Use First Line indentationsection.Paragraphs.Add( CreateTextParagraph( "textParagraph.FirstLineIndentation = 20" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.FirstLineIndentation = 20;
section.Paragraphs.Add( textParagraph );
// Use hang indentationsection.Paragraphs.Add( CreateTextParagraph( "textParagraph.HangIndentation = 20" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.HangIndentation = 20;
section.Paragraphs.Add( textParagraph );
document.Write( file );
}
}
private static TextParagraph CreateTextParagraph( string text ){
return CreateTextParagraph( text, System.Drawing.Color.Black );}
private static TextParagraph CreateTextParagraph( string text, System.Drawing.Color textcolor ){
TextParagraph paragraph =
new TextParagraph();Fragment textFragment =
new Fragment( text );textFragment.TextColor = textcolor;
paragraph.Fragments.Add( textFragment );
paragraph.SpacingAfter = 10;
return paragraph;}
}
}






Comments
Write New Comment ▼
Write New Comment
Sorry! This knol's owner(s) have blocked you from editing, making suggestions, or commenting here.