C++: Convert PDF to Excel

PDF files are great for delivering documents in a standard format that looks exactly the same no matter what device or software you use to view them, but they are difficult to edit. If you have a spreadsheet in PDF format, usually the easiest way to work with the data is to convert the PDF to Excel and edit it there. In this article, you will learn how to convert PDF to Excel in C++ using Spire.PDF for C++.

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 PDF to Excel in C++

Spire.PDF for C++ offers the PdfDocument->SaveToFile() method to convert PDF documents to other file formats including XLSX. Before converting, you can set the conversion options by using PdfDocument->GetConvertOptions->SetPdfToXlsxOptions() method. This method takes the XlsxLineLayoutOptions object as a parameter, and the constructor of the XlsxLineLayoutOptions class has the following five parameters, enabling you to control how PDF will be converted to Excel.

  • bool convertToMultipleSheet: Indicates whether each page of the PDF will be converted to a worksheet in Excel.
  • bool rotatedText: Indicates whether to show rotated text.
  • bool splitCell: Indicates whether a PDF table cell containing text spanning several lines will be split into multiple rows in Excel.
  • bool wrapText: Indicates whether to wrap text in an Excel cell.
  • bool overlapText: Indicates whether to display overlapping text.
  • C++
#include "Spire.Pdf.o.h";

using namespace Spire::Pdf;

int main() {

    //Create a PdfDcoument object
    PdfDocument* doc = new PdfDocument();

    //Load a PDF document
    doc->LoadFromFile(L"C:\\Users\\Administrator\\Desktop\\Business sales invoice.pdf");

    //Create a XlsxLineLayoutOptions object
    XlsxLineLayoutOptions* options = new XlsxLineLayoutOptions(true, true, false, true, false);

    //Set PDF to XLSX convert options
    doc->GetConvertOptions()->SetPdfToXlsxOptions(options);

    //Save the PDF document to Excel
    doc->SaveToFile(L"output/PdfToExcel.xlsx", FileFormat::XLSX);
	doc->Close();
	delete doc;
}

C++: Convert PDF to Excel

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.