Convert Word DOCX to PDF

Welcome again to the Home of File Format APIs! In the recent past, I have written a couple of blog posts to cover various scenarios of converting Word (DOC/DOCX) to PDF programmatically in .NET (using C#) and Java applications. Since this is a popular and widely used feature, I thought to cover it for C++ as well. Therefore, in this post, I will show you how to convert Word DOC/DOCX to PDF in C++ applications. This article addresses the following Word to PDF conversions:

  • Simple Word DOC/DOCX to PDF in C++.
  • DOCX to PDF with particular standard i.e. PDF 1.5, PDF/A-1a, etc.
  • Converting selected pages of a DOCX to PDF.
  • Apply image/text compression in DOCX to PDF conversion.

C++ Word to PDF Converter Library

Aspose.Words for C++ is an advanced library to create and manipulate Word document formats within C++ applications without requiring MS Word. You can either install it via NuGet or download the complete package containing the library files as well as ready to run source code examples.

Convert Word DOC/DOCX to PDF in C++

Converting a Word document to PDF is as simple as pie using Aspose.Words for C++. The following are the steps to convert a DOC/DOCX file to PDF.

  • Create an object of Document class and initialize it with the Word document’s path.
  • Call Document->Save() method to save the document as PDF.

The following code sample shows how to convert DOCX to PDF in C++.

Input Word Document

DOCX to PDF C++

Converted PDF Document

DOC to PDF in C++

Convert DOCX to PDF/A or Other PDF Standards in C++

The PDF format supports various PDF standards including PDF/A, PDF/E and etc. There might be the case when you need to convert Word file to a particular standard such as PDF/A-1a. In such a case, Aspose.Words for C++ allows you to set the desired PDF standard for the converted PDF. The following are the steps to set PDF standard in Word to PDF conversion:

The following code sample shows how to convert Word DOCX to PDF with PDF/A-1a standard.

Convert Selected Pages of a Word to PDF in C++

You may also convert only the selected pages instead of converting the whole Word to PDF. The following are the steps to convert only the desired pages of Word to PDF:

  • Load the Word document using Document class.
  • Set the starting page’s index using PdfSaveOptions->set_PageIndex() method.
  • Set the number of pages you want to convert using PdfSaveOptions->set_PageCount() method.
  • Save the document as PDF using Document->Save() method.

The following code sample shows how to convert selected pages of DOCX to PDF in C++.

Apply Image/Text Compression in DOCX to PDF Conversion

You may also compress the resultant PDF document in order to reduce its size. Aspose.Words for C++ lets you apply the text and image compression using PdfSaveOptions->set_TextCompression() and PdfSaveOptions->set_ImageCompression() methods respectively. The following code sample shows how to apply compression when converting DOCX to PDF in C++.

Learn more about Aspose.Words for C++

You may explore more about Aspose.Words for C++ using the documentation. In case you may find anything confusing, feel free to let us know via our forum.

See Also