- How to add page numbers to your PDF
- Add text field to PDF
- Append multiple PDF documents
- Bulleted list from XML and XSL
- Merge PDF
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Convert TXT to PDF
- Convert XHTML to PDF
- Create PDF in C# - Tall Components - Check out our PDF code samples
- Text formatting
- Generate PDF form from XML
- Generate PDF with local images from XML with Xamarin.iOS
- XhtmlParagraph and TrueType fonts
- Add footer with left and right aligned text on same line
- Read and write meta data from PDF
- Stitch PDF documents
- Use multiple licenses
- What is the resulting fontsize in PDF rich text used in SimpleXhtmlShape
Convert TXT to PDF
using System;
using System.IO;
using TallComponents.PDF.Layout;
using TallComponents.PDF.Layout.Paragraphs;
using TallComponents.PDF.Layout.Fonts;
namespace txt2pdf
{
class Program
{
static void Main(string[] args)
{
Document document = new Document();
Section section = new Section();
section.PageSize = PageSize.Letter;
document.Sections.Add(section);
string[] lines = File.ReadAllLines("test.txt");
foreach (string line in lines)
{
TextParagraph text = new TextParagraph();
text.SpacingAfter = 12;
section.Paragraphs.Add(text);
Fragment fragment = new Fragment();
fragment.FontSize = 12;
fragment.Font = Font.Courier;
fragment.Text = line;
text.Fragments.Add(fragment);
}
using (FileStream file = new FileStream(
"test.pdf", FileMode.Create, FileAccess.Write))
{
document.Write(file);
}
}
}
}