pdftabextract

Python 언어로 만든 PDF 관련 프로젝트예요. 전 세계 개발자 2,256 명이 스타(좋아요)를 눌렀어요. 깃허브에 올라온 설치파일이 없는 개발자용 프로젝트예요. 마지막 수정은 4년 전이에요.

👩‍💻 개발자용⭐ 2,256 PDF

원문 소개: A set of tools for extracting tables from PDF files helping to do data mining on (OCR-processed) scanned documents.

바로 쓰기

내 상황에 맞는 방법을 하나 고르세요.

깃허브에는 설치파일이 없어요. 앱으로 배포하는 프로젝트라면 공식 사이트에서 받을 수 있는지 확인해 보세요.

브라우저에서 바로 열기 · 설치 없음

내 것으로 가져오기

git clone https://github.com/WZBSocialScienceCenter/pdftabextract.git

git clone: 개발자가 코드를 받는 명령어예요. 수정 내역까지 함께 받아져요.

한눈에 보기

인기⭐ 2,256 스타 · 🍴 363 포크
무료 여부Apache-2.0
무료이고 회사·상업용으로 써도 돼요. 출처(저작권 표시)만 남기면 돼요.
만든 언어Python
최신 버전정식 배포 버전 없음
활동만든 날 2016.7.8 · 최근 수정 4년 전 · 열린 이슈(질문) 5개
공식 사이트datascience.blog.wzb.eu/2017/02/16/data-mining-ocr-pdfs-using-pdftabextract-to-liberate-tabular-data-from-scanned-documents/

설명서 (README)

만든 사람이 쓴 원문 설명서예요. 영어가 어렵다면 한국어로 번역해서 보기 →

pdftabextract - A set of tools for data mining (OCR-processed) PDFs

July 2016 / Feb. 2017, Markus Konrad markus.konrad@wzb.eu post@mkonrad.net / Berlin Social Science Center

This project is currently not maintained.

IMPORTANT INITIAL NOTES

From time to time I receive emails from people trying to extract tabular data from PDFs. I'm fine with that and I'm glad to help. However, some people think that pdftabextract is some kind of magic wand that automatically extracts the data they want by simply running one of the provided examples on their documents. This, in the very most cases, won't work. I want to clear up a few things that you should consider before using this software and before writing an email to me:

  1. pdftabextract is not an OCR (optical character recognition) software. It requires scanned pages with OCR information, i.e. a "sandwich PDF" that contains both the scanned images and the recognized text. You need software like tesseract or ABBYY Finereader for OCR. In order to check if you have a "sandwich PDF", open your PDF and press "select all". This usually reveals the OCR-processed text information.
  2. pdftabextract is some kind of last resort when all other things fail for extracting tabular data from PDFs. Before trying this out, you should ask yourself the following questions:
  • Is there really no other way / no other format for which the data is available?
  • Can a special OCR software like ABBYY Finereader detect and extract the tables (you need to try this with a large sample of pages -- I found the table recognition in Finereader often unreliable)?
  • Is it possible to extract the recognized text as-is from the PDFs and parse it? Try using the pdftotext tool from poppler-utils, a package which is part of most Linux distributions and is also available for OSX via Homebrew or MacPorts: pdftotext -layout yourdocument.pdf. This will create a file yourdocument.txt containing the recognized text (from the OCR) with a layout that hopefully resembles your tables. Often, this can be parsed directly (e.g. with a Python script using regular expressions). If it can't be parsed (e.g. if the columns are not well separated in the text, the tables on each page are too different to each other in order to come up with a common structure for parsing, the pages are too skewed or rotated) then pdftabextract is the right software for you.
  1. pdftabextract is a set of tools. As such, it contains functions that are suitable for certain documents but not for others and many functions require you to set parameters that depend on the layout, scan quality, etc. of your documents. You can't just use the example scripts blindly with your data. You will need to adjust parameters in order that it works well with your documents. Below are some hints and explanations regarding those tools and their parameters.

Introduction

This repository contains a set of tools written in Python 3 with the aim to extract tabular data from (OCR-processed) PDF files. Before these files can be processed they need to be converted to XML files in pdf2xml format. This is very simple -- see section below for instructions.

Module overview

After that you can view the extracted text boxes with the pdf2xml-viewer tool if you like. The pdf2xml format can be loaded and parsed with functions in the common submodule. Lines can be detected in the scanned images using the imgproc module. If the pages are skewed or rotated, this can be detected and fixed with methods from imgproc and functions in textboxes. Lines or text box positions can be clustered in order to detect table columns and rows using the clustering module. When columns and rows were successfully detected, they can be converted to a page grid with the extract module and their contents can be extracted using fit_texts_into_grid in the same module. extract also allows you to export the data as pandas DataFrame.

If your scanned pages are double pages, you will need to pre-process them with splitpages.

Examples and tutorials

An extensive tutorial was posted here and is derived from the Jupyter Notebook contained in the examples. There are more use-cases and demonstrations in the examples directory.

Features

  • load and parse files in pdf2xml format (common module)
  • split scanned double pages (splitpages module)
  • detect lines in scanned pages via image processing (imgproc module)
  • detect page rotation or skew and fix it (imgproc and textboxes module)
  • detect clusters in detected lines or text box positions in order to find column and row positions (clustering module)
  • extract tabular data and convert it to pandas DataFrame (which allows export to CSV, Excel, etc.) (extract module)

Installation

This package is available on PyPI and can be installed via pip: pip install pdftabextract

Requirements

The requirements are listed in requirements.txt and are installed automatically if you use pip.

Only Python 3 -- No Python 2 support.

Converting PDF files to XML files with pdf2xml format

You need to convert your PDFs using the poppler-utils, a package which is part of most Linux distributions and is also available for OSX via Homebrew or MacPorts. From this package we need the command pdftohtml and can create an XML file in pdf2xml format in the following way using the Terminal:

pdftohtml -c -hidden -xml input.pdf output.xml

The arguments input.pdf and output.xml are your input PDF file and the created XML file in pdf2xml format respectively. It is important that you specify the -hidden parameter when you're dealing with OCR-processed ("sandwich") PDFs. You can furthermore add the parameters -f n and -l n to set only a range of pages to be converted.

Usage and examples

For usage and background information, please read my series of blog posts about data mining PDFs.

See the following images of the example input/output:

Original page

original page

Generated (and skewed) pdf2xml file viewed with pdf2xml-viewer

OCR PDF example in the viewer

Detected lines

Detected lines

Detected clusters of vertical lines (columns)

Detected clusters of vertical lines (columns)

Generated page grid viewed in pdf2xml-viewer

Generated page grid viewed in pdf2xml-viewer

Excerpt of the extracted data

Excerpt of the extracted data

License

Apache License 2.0. See LICENSE file.

자주 묻는 질문

pdftabextract 무료로 쓸 수 있나요?

네, Apache-2.0 라이선스로 공개된 오픈소스예요. 무료이고 회사·상업용으로 써도 돼요. 출처(저작권 표시)만 남기면 돼요. 깃허브 저장소에서 누구나 내려받을 수 있어요.

pdftabextract 설치는 어떻게 하나요?

따로 설치파일이 없어서 README 설명서의 안내를 따라 설치해야 해요. ZIP 다운로드로 전체 코드를 받거나, 브라우저에서 바로 열어 코드를 둘러볼 수 있어요.

코딩을 몰라도 pdftabextract 쓸 수 있나요?

조금 어려울 수 있어요. 완성된 설치파일이 없는 개발자용 프로젝트라서 터미널 명령어나 개발 환경이 필요해요. 처음이라면 Codespaces로 브라우저에서 먼저 실행해 보세요.

pdftabextract 인기는 어느 정도인가요?

깃허브 스타 2,256개, 포크 363개를 받은 프로젝트예요. 2016년에 만들어졌고 마지막 수정은 4년 전이에요. 스타가 1만 개를 넘으면 전 세계적으로 검증된 인기 프로젝트로 봐요.

복사했어요