Skip to content

Instantly share code, notes, and snippets.

@aspose-net
Created June 26, 2025 07:53
Show Gist options
  • Save aspose-net/890eb211e6ff86af38a68b0b43fba7c3 to your computer and use it in GitHub Desktop.
Save aspose-net/890eb211e6ff86af38a68b0b43fba7c3 to your computer and use it in GitHub Desktop.
C# code snippets for blog post: How to Export Data from PDF to Excel in .NET (Aspose.PDF API)

Aspose.PDF C# Code Snippets for Exporting PDF to Excel

This GitHub Gist contains a collection of C# code snippets demonstrating how to convert PDF files into Excel using the Aspose.PDF plugin family. These examples are related to the blog post titled "How to Export Data from PDF to Excel in .NET".

The provided code snippets showcase various scenarios for exporting data from a PDF file, such as:

  1. Exporting a single page or multiple pages to an Excel file.
  2. Converting a PDF with tables into an Excel file while preserving the table structure.
  3. Extracting text and images from a PDF and saving them in separate worksheets within an Excel file.

These examples provide a practical starting point for developers looking to integrate PDF-to-Excel conversion functionality into their .NET applications using Aspose.PDF. For more detailed information, please refer to the original Knowledge Base article linked above.

using Aspose.Pdf.Plugins;
using System.IO;
public class BatchPdfToExcelConverter
{
public static void ConvertAllPdfsInDirectory(string inputDir, string outputDir)
{
Directory.CreateDirectory(outputDir);
string[] pdfFiles = Directory.GetFiles(inputDir, "*.pdf");
foreach (var pdfFile in pdfFiles)
{
string outFile = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(pdfFile) + ".xlsx");
var converter = new PdfXls();
var options = new PdfToXlsOptions { Format = PdfToXlsOptions.ExcelFormat.XLSX };
options.AddInput(new FileDataSource(pdfFile));
options.AddOutput(new FileDataSource(outFile));
converter.Process(options);
Console.WriteLine($"Converted: {pdfFile} -> {outFile}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment