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
- Generate PDF with local images from XML with Xamarin.iOS
Create PDF in C#
Want to know how to create a PDF file in C#? With Tall Components TallPDF.NET library you can generate PDF on the fly, from scratch, use code, XML/XSL or a combination.
This simple code sample shows you how to create a PDF using C# and print “Hello World” to it.
C# code sample – how to create PDF file in C#Creat
// create a new document with a single section
Document document = new Document();
Section section = document.Sections.Add();
document.Sections.Add( section );
// add a new textparagraph to the section
TextParagraph textParagraph = new TextParagraph();
section.Paragraphs.Add( textParagraph );
// create a fragment, set some text and add it to the paragraph
Fragment fragment = new Fragment();
fragment.Text = "Hello world!";
textParagraph.Fragments.Add( fragment );
Here is the created PDF file:
You might have noticed that you have to add the text into Fragment then add the Fragment into TextParagraph instead of simply add the text into TextParagraph. By doing so, a TextParagraph is allowed to have texts with different fonts and styles. This design increases the flexibility of TextParagraph.
Here is the sample of saving document:
using( FileStream file = new FileStream( @"..\..\HelloWorld.pdf", FileMode.Create, FileAccess.Write ) )
{
document.Write( file );
}
More C# PDF code samples for Creating PDF?
Check out other Generate PDF code samples:
Download TallPDF.NET 5.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.