PDFRasterizer.NET 4.0 is now available. Supports .NET Core. Renders pixel-perfectly.
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Create PDF in C#
- Text formatting
- How to add page numbers to your PDF
- Append multiple PDF documents
- Add text field to PDF
- Convert XHTML to PDF
- Add footer with left and right aligned text on same line
- XhtmlParagraph and TrueType fonts
- What is the resulting fontsize in PDF for rich text used in a SimpleXhtmlShape
- Read and write meta data from PDF
- Merge PDF
- Stitch PDF documents
- Convert TXT to PDF
- Bulleted list from XML and XSL
- Use multiple licenses
- Generate PDF form from XML
Text formatting
This code sample shows how to format your text
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 properties
section.Paragraphs.Add( CreateTextParagraph( "TextParagraph with default properties:" ) );
section.Paragraphs.Add( CreateTextParagraph( text, System.Drawing.Color.Blue ) );
// Set alignment to right
section.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 center
section.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 justified
section.Paragraphs.Add( CreateTextParagraph( "textParagraph.Justified = true" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.Justified = true;
section.Paragraphs.Add( textParagraph );
// Set linespacing
section.Paragraphs.Add( CreateTextParagraph( "textParagraph.LineSpacing = 5" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.LineSpacing = 5;
section.Paragraphs.Add( textParagraph );
// Use First Line indentation
section.Paragraphs.Add( CreateTextParagraph( "textParagraph.FirstLineIndentation = 20" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.FirstLineIndentation = 20;
section.Paragraphs.Add( textParagraph );
// Use hang indentation
section.Paragraphs.Add( CreateTextParagraph( "textParagraph.HangIndentation = 20" ) );
textParagraph = CreateTextParagraph( text, System.Drawing.Color.Blue );
textParagraph.HangIndentation = 20;
section.Paragraphs.Add( textParagraph );
// Use different font
section.Paragraphs.Add(CreateTextParagraph("textParagraph.HangIndentation = 20"));
textParagraph = CreateTextParagraph(text, System.Drawing.Color.Blue,Font.TimesRoman, 28.0);
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;
}
private static TextParagraph CreateTextParagraph(string text, System.Drawing.Color textcolor,
Font f, double fsize)
{
TextParagraph paragraph = new TextParagraph();
Fragment textFragment = new Fragment(text);
textFragment.Font = f;
textFragment.FontSize = fsize;
textFragment.TextColor = textcolor;
paragraph.Fragments.Add(textFragment);
paragraph.SpacingAfter = 10;
return paragraph;
}

Download TallPDF.NET 4.0
We will send you a download link
Why do we ask your email address?
We send tips that speed up your evaluation
We let you know about bug fixes
You can always unsubscribe with one click
We never share your address with a 3rd party
Thank you for your download
We have sent an email with a download link.