Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Mar 14, 2017 2:32 pm

Is there a table object exposed anywhere within PdfDocument?

I see the PdfTable class documentation, but this all looks like it is geared toward creating a table within a Pdf document.

What would be most useful would be an enumerable table class similar to the one available within word docs.

Is such a thing available through Spire.PDF, and if so, how is it accessed using C#?

elmsst
 
Posts: 1
Joined: Tue Mar 14, 2017 2:23 pm

Wed Mar 15, 2017 3:44 am

Dear elmsst,

Thanks for your inquiry.
Sorry that I am afraid that it is impossible to extract table from the PDF, since the pdf format is just a canvas where text and graphics are placed without any structure information. Theoretically, PDF does not contain explicit table data. It only contains lines and character glyphs which we tend to interpret as tables.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Mon Oct 18, 2021 10:03 am

Dear elmsst,

I am glad to inform you that we have supported extracting table data from PDFs.
Welcome to download and test Spire.PDF Pack(Hot Fix) Version:7.10.4.
Code: Select all
PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(inputPath);
            StringBuilder builder = new StringBuilder();           
            PdfTableExtractor extractor = new PdfTableExtractor(pdf);
            PdfTable[] tableLists = null;
            for (int pageIndex = 0; pageIndex < pdf.Pages.Count; pageIndex++)
            {
                tableLists = extractor.ExtractTable(pageIndex);
                if (tableLists != null && tableLists.Length > 0)
                {
                    foreach (PdfTable table in tableLists)
                    {
                        int row = table.GetRowCount();
                        int column = table.GetColumnCount();
                        for (int i = 0; i < row; i++)
                        {
                            for (int j = 0; j < column; j++)
                            {
                                string text = table.GetText(i, j);
                                builder.Append(text + " ");
                            }
                            builder.Append("\r\n");
                        }
                    }
                }
            }
            File.WriteAllText(outputFile, builder.ToString());


Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3044
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF