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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kapil Singh KumawatRank #735 · 3.2K reputationPosted Feb 15, 2022, 6:15 AM EST
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
Rohan GuptaRank #2,588 · 539 reputationPosted Feb 15, 2022, 6:25 AM EST
Leon DRank #851 · 2.6K reputationPosted Feb 15, 2022, 8:17 PM EST
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
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Feb 15, 2022, 10:46 PM EST