Back to Blog

    Developer Blog

    How to convert a text file to PDF?

    Foxit PDF Generator for .NET SDK

    To make text to PDF files conversion, follow the steps outlined below:

    1. Extract the text from the text file.
    2. Add the extracted text to a PDF using the TextArea class.Here is an example that adds “Hello World!” to a PDF.
           // Create a PDF Document
    
            Document document = new Document();
    
            // Create a PDF Page
    
            Page page = new Page();
    
            // Create a Text Area
    
            TextArea textArea = new TextArea("Hello World!", 10, 10, 200, 100);
    
            // Add the text area to the page
    
            page.Elements.Add(textArea);
    
            // Add the page to the document
    
            document.Pages.Add(page);
    
            // Save the document
    
            document.Draw(@"C:\MyDocument.pdf");
    

    Note: The class can be used to handle font size, color, alignment and other properties.