Aspose.PDF С++ Example

[ ]

A “Hello World” example is traditionally used to introduce features of a programming language or software with a simple use case.

Aspose.PDF for C++ is a feature rich PDF API that allows the developers to embed PDF document creation, manipulation & conversion capabilities in their C++ applications. It supports working with many popular file formats including PDF, XFA, TXT, HTML, PCL, XML, XPS, EPUB, TEX and image file formats. In this article, we are creating a PDF document containing text “Hello World!”. After installing Aspose.PDF for C++ in your environment, you can execute below code sample to see how Aspose.PDF API works.

Below code snippet follows these steps:

  1. Create a String Class for path name and file name.
  2. Instantiate a Document object. In this step we will create an empty PDF document with some metadata but without pages.
  3. Add a Page to the document object. So, now our document will have one page.
  4. Saveresultant PDF document

Following code snippet is a Hello World program to exhibit working of Aspose.PDF for C++ API.

void ExampleSimple()
    // Buffer to hold combined path.
    String outputFileName;

    // String for path name.
    String _dataDir("C:\\Samples\\");

    // String for file name.
    String filename("HelloWorld_out.pdf");

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

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

    auto paragraphs = page->get_Paragraphs();

    // Save updated PDF
    outputFileName = _dataDir + filename;