Convert PDF to DOC and DOCX in C++

Export PDFs to DOC or DOCX and configure text recognition, line endings, bullet recognition, and image resolution.

Configure the Aspose.PDF for C++ SDK before running these functions. Pass an existing input file and a writable destination path; create any required output directories first. Each function is an independent example, and its options do not carry over to other examples.

Convert PDF to DOC

Select DocSaveOptions::DocFormat::Doc for Word DOC output.

  1. Open the input PDF as Document.
  2. Create DocSaveOptions.
  3. Set Format to DocSaveOptions::DocFormat::Doc in DocSaveOptions.
  4. Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/DocSaveOptions.h>

namespace ConvertingExamples
{
	using namespace System;
	using namespace Aspose::Pdf;

	void ConvertPdfToDoc(String inputFile, String outputFile)
	{
		auto document = MakeObject<Document>(inputFile);
		auto options = MakeObject<DocSaveOptions>();
		options->set_Format(DocSaveOptions::DocFormat::Doc);
		document->Save(outputFile, options);
	}
}

Convert PDF to DOCX

Select DocSaveOptions::DocFormat::DocX for DOCX output.

  1. Open the input PDF as Document.
  2. Create DocSaveOptions.
  3. Set Format to DocSaveOptions::DocFormat::DocX in DocSaveOptions.
  4. Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/DocSaveOptions.h>

namespace ConvertingExamples
{
	using namespace System;
	using namespace Aspose::Pdf;

	void ConvertPdfToDocx(String inputFile, String outputFile)
	{
		auto document = MakeObject<Document>(inputFile);
		auto options = MakeObject<DocSaveOptions>();
		options->set_Format(DocSaveOptions::DocFormat::DocX);
		document->Save(outputFile, options);
	}
}

Use enhanced flow recognition

Set RecognitionMode::EnhancedFlow to configure how the converter reconstructs flowing text.

  1. Open the input PDF as Document.
  2. Create DocSaveOptions.
  3. Set Format to DocSaveOptions::DocFormat::DocX in DocSaveOptions.
  4. Set Mode to DocSaveOptions::RecognitionMode::EnhancedFlow in DocSaveOptions.
  5. Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/DocSaveOptions.h>

namespace ConvertingExamples
{
	using namespace System;
	using namespace Aspose::Pdf;

	void ConvertPdfToDocxEnhancedFlow(String inputFile, String outputFile)
	{
		auto document = MakeObject<Document>(inputFile);
		auto options = MakeObject<DocSaveOptions>();
		options->set_Format(DocSaveOptions::DocFormat::DocX);
		options->set_Mode(DocSaveOptions::RecognitionMode::EnhancedFlow);
		document->Save(outputFile, options);
	}
}

Add returns at line ends

Set AddReturnToLineEnd to true when exporting DOCX.

  1. Open the input PDF as Document.
  2. Create DocSaveOptions.
  3. Set Format to DocSaveOptions::DocFormat::DocX in DocSaveOptions.
  4. Set AddReturnToLineEnd to true in DocSaveOptions.
  5. Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/DocSaveOptions.h>

namespace ConvertingExamples
{
	using namespace System;
	using namespace Aspose::Pdf;

	void ConvertPdfToDocxWithLineBreaks(String inputFile, String outputFile)
	{
		auto document = MakeObject<Document>(inputFile);
		auto options = MakeObject<DocSaveOptions>();
		options->set_Format(DocSaveOptions::DocFormat::DocX);
		options->set_AddReturnToLineEnd(true);
		document->Save(outputFile, options);
	}
}

Recognize bullets

Enable RecognizeBullets for DOCX output.

  1. Open the input PDF as Document.
  2. Create DocSaveOptions.
  3. Set Format to DocSaveOptions::DocFormat::DocX in DocSaveOptions.
  4. Set RecognizeBullets to true in DocSaveOptions.
  5. Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/DocSaveOptions.h>

namespace ConvertingExamples
{
	using namespace System;
	using namespace Aspose::Pdf;

	void ConvertPdfToDocxWithBullets(String inputFile, String outputFile)
	{
		auto document = MakeObject<Document>(inputFile);
		auto options = MakeObject<DocSaveOptions>();
		options->set_Format(DocSaveOptions::DocFormat::DocX);
		options->set_RecognizeBullets(true);
		document->Save(outputFile, options);
	}
}

Set DOCX image resolution

Set ImageResolutionX and ImageResolutionY to 300 for exported images.

  1. Open the input PDF as Document.
  2. Create DocSaveOptions.
  3. Set Format to DocSaveOptions::DocFormat::DocX in DocSaveOptions.
  4. Set ImageResolutionX to 300 in DocSaveOptions.
  5. Set ImageResolutionY to 300 in DocSaveOptions.
  6. Save the result with Document::Save(), passing the output path and options.
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/DocSaveOptions.h>

namespace ConvertingExamples
{
	using namespace System;
	using namespace Aspose::Pdf;

	void ConvertPdfToDocxImageResolution(String inputFile, String outputFile)
	{
		auto document = MakeObject<Document>(inputFile);
		auto options = MakeObject<DocSaveOptions>();
		options->set_Format(DocSaveOptions::DocFormat::DocX);
		options->set_ImageResolutionX(300);
		options->set_ImageResolutionY(300);
		document->Save(outputFile, options);
	}
}