C++: Convert PDF to Word

PDF documents are great for presenting documents on different devices while keeping documents' appearance unchanged. It can also facilitate the sharing and transmission of documents. But editing PDF documents is usually quite troublesome. Therefore, many users will choose to convert PDF documents into easy-to-edit Word documents to facilitate the modification of document content.

  • The fixed layout conversion mode has a faster conversion speed and is conducive to the maximum preservation of the original appearance of PDF files. However, since each line of PDF text will be presented in a separate frame in the generated Word documents, the editability of the generated documents will be limited.
  • The flowable structure conversion mode is a full recognition mode. The converted content is not rendered in frames and the resulting document structure is flowable, meaning that the resulting Word document is easy to re-edit but may look different from the original PDF file.

This article is going to demonstrate how to use Spire.PDF for C++ to convert PDFs to Word documents in fixed layout mode or flowable structure mode.

Install Spire.PDF for C++

There are two ways to integrate Spire.PDF for C++ into your application. One way is to install it through NuGet, and the other way is to download the package from our website and copy the libraries into your program. Installation via NuGet is simpler and more recommended. You can find more details by visiting the following link.

Integrate Spire.PDF for C++ in a C++ Application

Convert PDFs to Doc/Docx Files in Fixed Layout

By default, when PdfDocument->SaveToFile() method is used to convert a PDF file to a Word document without setting the conversion options, the content arrangement of the output Word document will be in fixed layout. The detailed steps for converting a PDF file to a Word document in fixed layout mode are as follows.

  • Create an object of PdfDocument.
  • Load a PDF file using PdfDocument->LoadFromFile() method.
  • Save the PDF file as a Doc and a Docx file using PdfDocument->SaveToFile() method.
  • C++
#include "Spire.Pdf.o.h"

using namespace Spire::Pdf;

int main()
{
    //Create an Object of PdfDocument
    PdfDocument* pdf = new PdfDocument();

    //Load a PDF file
    pdf->LoadFromFile(L"C:/The Space Between Us.pdf");

    //Save the document as a Doc file
    pdf->SaveToFile(L"Output/PDFToWord.doc", FileFormat::DOC);

    //Save the document as a Docx file
    pdf->SaveToFile(L"Output/PDFToWord.docx", FileFormat::DOCX);
    pdf->Close();
    delete pdf;
}

C++: Convert PDF to Word

Convert PDFs to Doc/Docx Files in Flowable Structure

Spire.PDF for C++ provides the PdfDocument->GetConvertOptions()->SetPdfToDocOptions(true, true) method to change the conversion mode to flowable structure mode. The detailed steps for converting a PDF file To a Word document in flowable structure mode are as follows.

  • Create an object of PdfDocument.
  • Load a PDF file using PdfDocument->LoadFromFile() method.
  • Change the conversion mode to flowable structure mode using PdfDocument->GetConvertOptions()->SetPdfToDocOptions(true, true) method.
  • Save the PDF file as a Doc and a Docx file using PdfDocument->SaveToFile() method.
  • C++
#include "Spire.Pdf.o.h"

using namespace Spire::Pdf;

int main()
{
    //Create an Object of PdfDocument
    PdfDocument* pdf = new PdfDocument();

    //Load a PDF file
    pdf->LoadFromFile(L"C:/The Space Between Us.pdf");

    //Change the conversion mode to flowable structure mode
    pdf->GetConvertOptions()->SetPdfToDocOptions(true, true);

    //Save the document as a Doc file
    pdf->SaveToFile(L"Output/PDFToWord.doc", FileFormat::DOC);

    //Save the document as a Docx file
    pdf->SaveToFile(L"Output/PDFToWord.docx", FileFormat::DOCX);
    pdf->Close();
    delete pdf;
}

C++: Convert PDF to Word

Apply for a Temporary License

If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.