HTML JPG PDF XML
  Product Family
PDF

Convert TEXT to PDF via C++

Export TEXT documents to multiple formats including PDF on any platform with C++ language

How to Convert Text to PDF Using C++

In order to convert Text to PDF, we’ll use Aspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation and conversion API for C++ platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.PDF

Steps to Convert TEXT to PDF via C++

C++ developers can easily load & convert BTEXT files to PDF in just a few lines of code.

  1. Initialize a new Document
  2. Load input Text file
  3. Finally, save the output PDF file

System Requirements

Before running the C++ conversion sample code, make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with C++ Runtime Environment for Windows 32 bit, Windows 64 bit and Linux 64 bit.
  • Development environment like Microsoft Visual Studio.
  • Aspose.PDF for C++ DLL referenced in your project.
 

This sample code shows Text to PDF C++ Conversion

    string dataDir = RunExamples.GetDataDir_AsposePdf_DocumentConversion();
    // Read the source text file
    TextReader tr = new StreamReader(dataDir + "log.txt");

    // Instantiate a Document object by calling its empty constructor
    Document pdfDocument= new Document();

    // Add a new page in Pages collection of Document
    Page page = pdfDocument.Pages.Add();

    // Create an instance of TextFragmet and pass the text from reader object to its constructor as argument
    TextFragment text = new TextFragment(tr.ReadToEnd());

    // Add a new text paragraph in paragraphs collection and pass the TextFragment object
    page.Paragraphs.Add(text);

    // Save resultant PDF file
    pdfDocument.Save(dataDir + "TexttoPDF_out.pdf");
 
  • Free App to Convert Text to PDF