Given a scholarly PDF, extract figures, tables, captions, and section titles.
759
stars
70
commits
Scala
primary language
Mar 10, 2024
updated
PDFFigures 2.0 is a Scala based project built to extract figures, captions, tables and section titles from scholarly documents, with a strong focus on documents from the domain of computer science. See our paper for more details.
PDFFigures 2.0 takes as input a scholarly document in PDF form. Its output will be a list of 'Figure' objects where, for each figure, we have identified:
PDFFigures 2 also supports the ability to save images of the extracted figures as rasterized images. Currently, we support any format that a BufferedImage can be saved to (png, jpeg, etc.). More experimentally, if pdftocairo is installed it can be used to save the figures to a selection of vector graphics formats (svg, ps, eps, etc.).
PDFFigures 2 only seeks to extract figures or tables that have been captioned, in which case we define a figure to be all elements on the page that the caption refers to. If a figure has subfigures, the returned figure will include all the subfigures. If a table or figure includes text titles or comments, those elements will be included in the figure.
Clone the repo and then run with sbt.
For licensing reasons, PDFFigures2 does not include libraries for some image formats. Without these libraries, PDFFigures2 cannot process PDFs that contain images in these formats. If you have no licensing restrictions in your project, we recommend you add these additional dependencies to your project as well:
"com.github.jai-imageio" % "jai-imageio-core" % "1.2.1",
"com.github.jai-imageio" % "jai-imageio-jpeg2000" % "1.3.0", // For handling jpeg2000 images
"com.levigo.jbig2" % "levigo-jbig2-imageio" % "1.6.5", // For handling jbig2 images
PDFFigures 2 provides two CLI tools. One, 'FigureExtractorBatchCli', can be used to extract figures from a large number of PDFs and save the results to disk. The second, 'FigureExtractorVisualizationCli', works on a single PDF and provides extensive debug visualizations. Note it is recommended to use the "-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider" to get the best performance out of the PDF parser, see here[https://pdfbox.apache.org/2.0/getting-started.html]
To run on a PDF and get a preview of the results use:
sbt "runMain org.allenai.pdffigures2.FigureExtractorVisualizationCli /path/to/pdf"
To get a visualization of how the PDF was parsed:
sbt "runMain org.allenai.pdffigures2.FigureExtractorVisualizationCli /path/to/pdf" -r
To get a visualization of all the intermediate steps:
sbt "runMain org.allenai.pdffigures2.FigureExtractorVisualizationCli /path/to/pdf" -s
To run on lots of PDFs while saving the images, figure objects, and run statistics:
sbt "runMain org.allenai.pdffigures2.FigureExtractorBatchCli /path/to/pdf_directory/ -s stat_file.json -m /figure/image/output/prefix -d /figure/data/output/prefix"
To compile a stand-alone JAR with these tools:
sbt assembly
FigureExtractor has experimental support for additionally identifying section titles. Section
titles, along with the PDF's text, can be returned from the BatchCli using the "-g" flag.
The output will the full text of the PDF, organized into sections.
An effort is made to identify the abstract, if there is one, and to exclude
text like page headers, authors names, and page numbers.
Text inside figures and captions will also be excluded from the main
text and encoded separately.
Note that while the extracted section titles have been found to be reliable, the
quality of the returned text
itself has not been tested and is mostly what is returned by PDFBox's ExtractText
FigureExtractor exports its high level programmatic interfaces in FigureExtractor.scala
FigureExtractor rigorously checks Thread.interrupted and so can be timed out easily. FigureExtractorBatchCli supports multi-threading.
See the paper for more details. In brief, the input PDF is pushed through the following steps:
This repo includes python-based scripts to evaluate figure extractors and two datasets with ground truth labels. See the evaluation directory.
FigureExtractor has been tested on papers selected from Semantic Scholar. It is not well tested on domains outside of computer science. When errors do occur, some common causes are:
There are a few edge cases were we consistently fail, due to hard coded assumptions or special cases we do not handle at the moment:
Christopher Clark, chrisc@allenai.org
Scala
70.7%
Python
28.9%
Given a scholarly PDF, extract figures, tables, captions, and section titles.
759
stars
70
commits
Scala
primary language
Mar 10, 2024
updated
PDFFigures 2.0 is a Scala based project built to extract figures, captions, tables and section titles from scholarly documents, with a strong focus on documents from the domain of computer science. See our paper for more details.
PDFFigures 2.0 takes as input a scholarly document in PDF form. Its output will be a list of 'Figure' objects where, for each figure, we have identified:
PDFFigures 2 also supports the ability to save images of the extracted figures as rasterized images. Currently, we support any format that a BufferedImage can be saved to (png, jpeg, etc.). More experimentally, if pdftocairo is installed it can be used to save the figures to a selection of vector graphics formats (svg, ps, eps, etc.).
PDFFigures 2 only seeks to extract figures or tables that have been captioned, in which case we define a figure to be all elements on the page that the caption refers to. If a figure has subfigures, the returned figure will include all the subfigures. If a table or figure includes text titles or comments, those elements will be included in the figure.
Clone the repo and then run with sbt.
For licensing reasons, PDFFigures2 does not include libraries for some image formats. Without these libraries, PDFFigures2 cannot process PDFs that contain images in these formats. If you have no licensing restrictions in your project, we recommend you add these additional dependencies to your project as well:
"com.github.jai-imageio" % "jai-imageio-core" % "1.2.1",
"com.github.jai-imageio" % "jai-imageio-jpeg2000" % "1.3.0", // For handling jpeg2000 images
"com.levigo.jbig2" % "levigo-jbig2-imageio" % "1.6.5", // For handling jbig2 images
PDFFigures 2 provides two CLI tools. One, 'FigureExtractorBatchCli', can be used to extract figures from a large number of PDFs and save the results to disk. The second, 'FigureExtractorVisualizationCli', works on a single PDF and provides extensive debug visualizations. Note it is recommended to use the "-Dsun.java2d.cmm=sun.java2d.cmm.kcms.KcmsServiceProvider" to get the best performance out of the PDF parser, see here[https://pdfbox.apache.org/2.0/getting-started.html]
To run on a PDF and get a preview of the results use:
sbt "runMain org.allenai.pdffigures2.FigureExtractorVisualizationCli /path/to/pdf"
To get a visualization of how the PDF was parsed:
sbt "runMain org.allenai.pdffigures2.FigureExtractorVisualizationCli /path/to/pdf" -r
To get a visualization of all the intermediate steps:
sbt "runMain org.allenai.pdffigures2.FigureExtractorVisualizationCli /path/to/pdf" -s
To run on lots of PDFs while saving the images, figure objects, and run statistics:
sbt "runMain org.allenai.pdffigures2.FigureExtractorBatchCli /path/to/pdf_directory/ -s stat_file.json -m /figure/image/output/prefix -d /figure/data/output/prefix"
To compile a stand-alone JAR with these tools:
sbt assembly
FigureExtractor has experimental support for additionally identifying section titles. Section
titles, along with the PDF's text, can be returned from the BatchCli using the "-g" flag.
The output will the full text of the PDF, organized into sections.
An effort is made to identify the abstract, if there is one, and to exclude
text like page headers, authors names, and page numbers.
Text inside figures and captions will also be excluded from the main
text and encoded separately.
Note that while the extracted section titles have been found to be reliable, the
quality of the returned text
itself has not been tested and is mostly what is returned by PDFBox's ExtractText
FigureExtractor exports its high level programmatic interfaces in FigureExtractor.scala
FigureExtractor rigorously checks Thread.interrupted and so can be timed out easily. FigureExtractorBatchCli supports multi-threading.
See the paper for more details. In brief, the input PDF is pushed through the following steps:
This repo includes python-based scripts to evaluate figure extractors and two datasets with ground truth labels. See the evaluation directory.
FigureExtractor has been tested on papers selected from Semantic Scholar. It is not well tested on domains outside of computer science. When errors do occur, some common causes are:
There are a few edge cases were we consistently fail, due to hard coded assumptions or special cases we do not handle at the moment:
Christopher Clark, chrisc@allenai.org
Scala
70.7%
Python
28.9%