How to extract from a PDF a table that contains empty cells, and then, how to rebuild it as a Matlab table (or cell array)?

11 Ansichten (letzte 30 Tage)
[EDITED] How to extract from a PDF a table that contains empty cells, and then, how to rebuild it as a Matlab table (or cell array)?
Just as example, I created a PDF document (here attached, "pdftable.pdf") with Latex (here below the code) that only contains a fictious table with a few empty cells:
\documentclass[12pt]{article}
\usepackage{graphicx}
\begin{document}
\begin{center}
\begin{tabular}{ |c|c|c| }
\hline
cell1 & cell2 & \\ \hline
cell4 & & cell6 \\ \hline
& cell8 & cell9 \\
\hline
\end{tabular}
\end{center}
\end{document}
Then, I tried to extract that table's content from the PDF document, by using a tool that looks like to be state-of-the-art of Matlab for extracting texts from PDFs, i.e.:
>> str = extractFileText('pdftable.pdf')
str =
"cell1 cell2
cell4 cell6
cell8 cell9
1"
As we can see, extractFileText spits out every row of that table, but how can I know which cells of the table (contained inside the PDF document) were empty, just from the extractFileText output ?
OK, in this simple example I have a tiny 3x3 table with enumerated cells (i.e. "cell1", "cell2", "cell3", "cell4", "cell5", etc..) and, by eye, I can easily find which cells were empty in my PDF.
However, usually, I would have very long tables (inside my PDF document), and I could not check manually, i.e. by eye, which rows (extracted by extractFileText) contained empty cells.
Therefore, is there a way to re-build the table contained in my PDF, as a Matlab table or cell array, and by including the empty cells as follows?
% Desired Output (either as a table or a cell array)
str =
3×3 cell array
{'cell1'} {'cell2'} {'_' }
{'cell4'} {'_' } {'cell6'}
{'_' } {'cell8'} {'cell9'}

Akzeptierte Antwort

Suraj
Suraj am 28 Mär. 2023
Hi Sim
From the example you’ve presented it is clear that you’re trying to read a table from a PDF but the empty cells are causing extractFileText to produce unfavourable results.
The extractFileText method primarily focuses on extraction of text data from documents, as it belongs to the Text Analytics Toolbox. Extraction of tabular data from a PDF is a highly requested feature that MathWorks plans to add in a future release.
For now, I suggest you use a workaround that takes a .docx or .xlsx file as input rather than a PDF. You may use any online service or other widely available tools to convert your PDF to these formats. You can then feed your input file to the readtable method which is already great at extracting tables from both Word and Excel files.
Hope this helps.
  1 Kommentar
Sim
Sim am 28 Mär. 2023
Thanks a lot! Ok, so, for this specific task, we still need to rely on tools external to Matlab, thanks.
Do you already know which future release (also a date of the release) will contain this highly requested feature?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by