How to Convert Word to PDF using C++

In this brief topic, we will learn how to convert Word to PDF using C++. You can customize the output PDF by changing its appearance and other properties using simple API calls and generate PDF from DOCX in C++ that can be viewed in the browser or any other viewer.

Steps to Convert Word to PDF using C++

  1. Install Aspose.Words for C++ from the NuGet package manager
  2. Include Aspose.Words namespace and all necessary header files
  3. Using Document class, load the source Word file for exporting to PDF in C++
  4. Instantiate the PdfSaveOptions to set pages, page mode, and compliance mode of PDF
  5. Save the DOCX file as PDF using Save method

In the above steps, you can export Word to PDF in C++ using simple API calls. After loading the document from disk, you can customize the output PDF using PdfSaveOptions class and set page range, page mode and PDF compliance for exported PDF. Finally, we will be saving the PDF either on disk or in MemoryStream.

Code to Generate PDF from DOCX in C++

The above example convert Word to PDF in C++. The rendering to PDF starts by loading the Word file from disk. Then in subsequent steps, we have used PdfSaveOptions class to set different PDF options. You can also customize the PDF by setting other optional settings like textual contents compression, zoom behavior, zoom factor, outline options, option to use anti-aliasing, and many more. Finally, we have saved the generated PDF on disk.

We have learnt here how to convert Word to PDF using C++. If you are interested in learning about converting Word file to MD file format, refer to the article on how to convert Word to Markdown using C++.

 English