Create PDF document programmatically

Create PDF files programmatically for reports, invoices, and other generated documents.

Create a PDF with text

  1. Create an empty Document.
  2. Add a page to the document with PageCollection::Add().
  3. Create a TextFragment containing Hello World!.
  4. Add the text fragment to the page’s Paragraphs collection.
  5. Save the result with Document::Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
#include <Aspose.PDF.Cpp/Text/TextFragment.h>
#include <Aspose.PDF.Cpp/Generator/Paragraphs.h>

using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Text;

void CreatePDF(String path_outfile) {
    auto document = MakeObject<Document>();
    auto page = document->get_Pages()->Add();
    auto textFragment = MakeObject<TextFragment>(u"Hello World!");
    page->get_Paragraphs()->Add(textFragment);
    document->Save(path_outfile);
}