Create PDF Document using C++

Aspose.PDF for C++ API lets C++ application developers to embed PDF documents processing functionality in their applications. It can be used to create and read PDF files without the need of any other software installed on the underlying machine. Aspose.PDF for C++ can be used in a variety of C++ application types such as QT, MFC and console apps.

How to create PDF File using C++

To create a PDF file using C++, the following steps can be used.

  1. Instantiate a Document object
  2. Add a Page to document object
  3. Create a TextFragment object
  4. Add TextFragment to Paragraph collection of the page
  5. Save the resultant PDF document
void CreatePDF() {
    // String for path name.
    String _dataDir("C:\\Samples\\");

    // String for file name.
    String filename("sample-new.pdf");

    // Initialize document object
    auto document = MakeObject<Document>();
    // Add page
    auto page = document->get_Pages()->Add();

    // Add text to new page
    auto textFragment = MakeObject<TextFragment>(u"Hello World!");

    // Save updated PDF
    String outputFileName = _dataDir + filename;