Extract Table Data from PDF Documents into database in C#
Loading
Extract Table Data from PDF Documents into database in C#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Muhammad Imran AnsariPosted Feb 16, 2022, 3:46 AM
Leon DPosted Feb 16, 2022, 1:17 AM
Spire.PDF library can be used to detect and extract table data from PDF, then you can save the extracted data to database.
https://www.e-iceblue.com/Download/download-pdf-for-net-now.html
Sample code:
using System.IO;
using System.Text;
using Spire.Pdf;
using Spire.Pdf.Utilities;
namespace ExtractPdfTable
{
class Program
{
static void Main(string[] args)
{
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load the sample PDF file
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\table.pdf");
//Create a StringBuilder object
StringBuilder builder = new StringBuilder();
//Initialize an instance of PdfTableExtractor class
PdfTableExtractor extractor = new PdfTableExtractor(doc);
//Declare a PdfTable array
PdfTable[] tableList = null;
//Loop through the pages
for (int pageIndex = 0; pageIndex < doc.Pages.Count; pageIndex++)
{
//Extract tables from a specific page
tableList = extractor.ExtractTable(pageIndex);
//Determine if the table list is null
if (tableList != null && tableList.Length > 0)
{
//Loop through the table in the list
foreach (PdfTable table in tableList)
{
//Get row number and column number of a certain table
int row = table.GetRowCount();
int column = table.GetColumnCount();
//Loop though the row and colunm
for (int i = 0; i < row; i++)
{
for (int j = 0; j < column; j++)
{
//Get text from the specific cell
string text = table.GetText(i, j);
//Add text to the string builder
builder.Append(text + " ");
}
builder.Append("\r\n");
}
}
}
}
//Write to a .txt file
File.WriteAllText("Table.txt", builder.ToString());
}
}
}
For more information, you can visit this documentation:
https://www.e-iceblue.com/Tutorials/NET/Spire.PDF/Program-Guide/Table/C-/VB.NET-Extract-Tables-from-PDF.html
Rohan GuptaPosted Feb 15, 2022, 11:25 AM
Kapil Singh KumawatPosted Feb 15, 2022, 11:15 AM
you can check this link -
https://social.msdn.microsoft.com/Forums/windows/en-US/4f35879e-16bf-4648-ae41-7b10accfdc27/extract-a-pdf-from-sqldatabase-and-display-it-using-c