Convert PDF to DOC and DOCX in C++
Contents
[
Hide
]
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.
- Open the input PDF as Document.
- Create DocSaveOptions.
- Set
FormattoDocSaveOptions::DocFormat::Docin DocSaveOptions. - 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.
- Open the input PDF as Document.
- Create DocSaveOptions.
- Set
FormattoDocSaveOptions::DocFormat::DocXin DocSaveOptions. - 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.
- Open the input PDF as Document.
- Create DocSaveOptions.
- Set
FormattoDocSaveOptions::DocFormat::DocXin DocSaveOptions. - Set
ModetoDocSaveOptions::RecognitionMode::EnhancedFlowin DocSaveOptions. - 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.
- Open the input PDF as Document.
- Create DocSaveOptions.
- Set
FormattoDocSaveOptions::DocFormat::DocXin DocSaveOptions. - Set
AddReturnToLineEndtotruein DocSaveOptions. - 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.
- Open the input PDF as Document.
- Create DocSaveOptions.
- Set
FormattoDocSaveOptions::DocFormat::DocXin DocSaveOptions. - Set
RecognizeBulletstotruein DocSaveOptions. - 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.
- Open the input PDF as Document.
- Create DocSaveOptions.
- Set
FormattoDocSaveOptions::DocFormat::DocXin DocSaveOptions. - Set
ImageResolutionXto300in DocSaveOptions. - Set
ImageResolutionYto300in DocSaveOptions. - 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);
}
}