Convert PDF file to Excel file in C# and .NET


Why this code is useful:

  • Processing password-protected PDF files: Without knowing the password, it's impossible to extract the contents using standard tools, and the library makes this easy.
  • Automation: The code allows for integration into automated scripts, bots, or server applications.
  • Accuracy: Preserving styles and formatting after conversion ensures professional results.

What this code is useful for:

  • Legal practice: Extracting data from password-protected documents.
  • Accounting and finance: Automating the processing of financial reports protected in PDFs.
  • Contract processing: Converting protected contracts to an editable format.
  • Educational institutions: Preparing password-protected educational materials.

Converting password-protected PDFs to DOCX is a task that often arises in real-world business processes. With SautinSoft PDF Focus .NET, you can solve this problem quickly and reliably, implement automated scenarios, and improve document processing efficiency.

In this example, we demonstrated that even with a password, the library allows you to create an editable document, expanding the capabilities of automated data processing. We hope this example provides an excellent starting point for your own solutions!

Complete code

using System;
using System.IO;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Before starting, we recommend to get a free key:
            // https://sautinsoft.com/start-for-free/
            
            // Apply the key here:
            // SautinSoft.PdfFocus.SetLicense("...");
			
            string pathToPdf = Path.GetFullPath(@"..\..\..\Table.pdf");
            string pathToExcel = "Result.xlsx";
            
			// Convert PDF file to Excel file
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
			// The output result will be in XLSX (Excel modern format) or in XLS (Excel 97-2003 Workbook)
            f.ExcelOptions.Format = SautinSoft.PdfFocus.Format.Xlsx;
            // f.ExcelOptions.Format = SautinSoft.PdfFocus.Format.Xls;
           
		   // 'true' = Convert all data to spreadsheet (tabular and even textual).
            // 'false' = Skip textual data and convert only tabular (tables) data.
            f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = true;

            // 'true'  = Preserve original page layout.
            // 'false' = Place tables before text.
            f.ExcelOptions.PreservePageLayout = true;

            // The information includes the names for the culture, the writing system, 
            // the calendar used, the sort order of strings, and formatting for dates and numbers.
            System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo("en-US");
            ci.NumberFormat.NumberDecimalSeparator = ",";
            ci.NumberFormat.NumberGroupSeparator = ".";
            f.ExcelOptions.CultureInfo = ci;

            f.OpenPdf(pathToPdf);

            if (f.PageCount > 0)
            {
                int result = f.ToExcel(pathToExcel);
                
                //Open a produced Excel workbook
                if (result==0)
                {
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(pathToExcel) { UseShellExecute = true });
                }
            }
        }
    }
}

Download

Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

    Sub Main()
		' Before starting, we recommend to get a free key:
		' https://sautinsoft.com/start-for-free/

		' Apply the key here
		' SautinSoft.PdfFocus.SetLicense("...");

        Dim pathToPdf As String = Path.GetFullPath("..\..\..\Table.pdf")
		Dim pathToExcel As String = "Result.xlsx"

		' Convert PDF file to Excel file
		Dim f As New SautinSoft.PdfFocus()
		
		' The output result will be in XLSX (Excel modern format) or in XLS (Excel 97-2003 Workbook)
        f.ExcelOptions.Format = SautinSoft.PdfFocus.Format.Xlsx
        ' f.ExcelOptions.Format = SautinSoft.PdfFocus.Format.Xls
		
			' 'true' = Convert all data to spreadsheet (tabular and even textual).
			' 'false' = Skip textual data and convert only tabular (tables) data.
			f.ExcelOptions.ConvertNonTabularDataToSpreadsheet = True

			' 'true'  = Preserve original page layout.
			' 'false' = Place tables before text.
			f.ExcelOptions.PreservePageLayout = True

			' The information includes the names for the culture, the writing system, 
			' the calendar used, the sort order of strings, and formatting for dates and numbers.
			Dim ci As New System.Globalization.CultureInfo("en-US")
			ci.NumberFormat.NumberDecimalSeparator = ","
			ci.NumberFormat.NumberGroupSeparator = "."
			f.ExcelOptions.CultureInfo = ci

			f.OpenPdf(pathToPdf)

			If f.PageCount > 0 Then
				Dim result As Integer = f.ToExcel(pathToExcel)

				'Open a produced Excel workbook
				If result=0 Then
					System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(pathToExcel) With {.UseShellExecute = True})
            End If
        End If
    End Sub
End Module

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:


Captcha

Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.