News Category

C#/VB.NET: Convert PDF to Excel

2022-06-09 03:58:00 Written by  support iceblue
Rate this item
(0 votes)

PDF is a versatile file format, but it is difficult to edit. If you want to modify and calculate PDF data, converting PDF to Excel would be an ideal solution. In this article, you will learn how to convert PDF to Excel in C# and VB.NET using Spire.PDF for .NET.

Install Spire.PDF for .NET

To begin with, you need to add the DLL files included in the Spire.PDF for.NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.

PM> Install-Package Spire.PDF

Convert PDF to Excel in C# and VB.NET

The following are the steps to convert a PDF document to Excel:

  • Initialize an instance of PdfDocument class.
  • Load the PDF document using PdfDocument.LoadFromFile(filePath) method.
  • Save the document to Excel using PdfDocument.SaveToFile(filePath, FileFormat.XLSX) method.
  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.Conversion;

namespace ConvertPdfToExcel
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of PdfDocument class
            PdfDocument pdf = new PdfDocument();
            //Load the PDF document
            pdf.LoadFromFile("Sample.pdf");

            //Save the PDF document to XLSX
            pdf.SaveToFile("PdfToExcel.xlsx", FileFormat.XLSX);
        }
    }
}

C#/VB.NET: Convert PDF to Excel

Convert a Multi-Page PDF to One Excel Worksheet in C# and VB.NET

The following are the steps to covert a multi-page PDF to one Excel worksheet:

  • Initialize an instance of PdfDocument class.
  • Load the PDF document using PdfDocument.LoadFromFile(filePath) method.
  • Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
  • Set PDF to XLSX convert options using PdfDocument.ConvertOptions.SetPdfToXlsxOptions(XlsxLineLayoutOptions) method.
  • Save the document to Excel using PdfDocument.SaveToFile(filePath, FileFormat.XLSX) method.
  • C#
  • VB.NET
using Spire.Pdf;
using Spire.Pdf.Conversion;

namespace ConvertPdfToExcel
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize an instance of PdfDocument class
            PdfDocument pdf = new PdfDocument();
            //Load the PDF document
            pdf.LoadFromFile("Sample1.pdf");

            //Initialize an instance of XlsxLineLayoutOptions class, in the class constructor, setting the first parameter - convertToMultipleSheet as false.
            //The four parameters represent: convertToMultipleSheet, showRotatedText, splitCell, wrapText
            XlsxLineLayoutOptions options = new XlsxLineLayoutOptions(false, true, true, true);
            //Set PDF to XLSX convert options
            pdf.ConvertOptions.SetPdfToXlsxOptions(options);

            //Save the PDF document to XLSX
            pdf.SaveToFile("PdfToOneExcelSheet.xlsx", FileFormat.XLSX);
        }
    }
}

C#/VB.NET: 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.

Additional Info

  • tutorial_title:
Last modified on Tuesday, 20 June 2023 01:45