Giter Club home page Giter Club logo

pdfbox-via-py4j's Introduction

py4j経由でpythonからapache pdfboxでテキストを抽出する。

構成

$ tree
.
├── J4Py.java
├── README.md
├── build.sh
├── manifest.mf
├── org
│   └── kuryu
│       └── PDFExtractText.java
├── pdfbox-app-2.0.8.jar
└── py4j0.10.6.jar -> /Users/kuryu/.pyenv/versions/anaconda3-5.0.1/share/py4j/py4j0.10.6.jar

py4j setting

cf. https://qiita.com/arc279/items/5f547de8978a790e8523

$ pip show py4j
Name: py4j
Version: 0.10.6
Summary: Enables Python programs to dynamically access arbitrary Java objects
Home-page: https://www.py4j.org/
Author: Barthelemy Dagenais
Author-email: [email protected]
License: BSD License
Location: /Users/kuryu/.pyenv/versions/anaconda3-5.0.1/lib/python3.6/site-packages
Requires:
Required-by:

# pyenv使用の場合
$ python-config --exec-prefix
/Users/kuryu/.pyenv/versions/anaconda3-5.0.1

$ ln -s $(python-config --exec-prefix)/share/py4j/py4j0.10.6.jar .

pdfbox 取得

wget -nc http://central.maven.org/maven2/org/apache/pdfbox/pdfbox-app/2.0.8/pdfbox-app-2.0.8.jar

Java Gateway Server

bulid

#!/bin/bash

javac org/kuryu/*.java -cp pdfbox-app-2.0.8.jar
jar cvf kuryu.jar org/kuryu/*.class

javac J4Py.java -cp py4j0.10.6.jar
jar cvfm J4Py.jar manifest.mf J4Py.class

run

java -jar J4Py.jar

python usage

サンプルデータ取得

平成29年版 厚生労働白書

wget -nc http://www.mhlw.go.jp/wp/hakusyo/kousei/17/dl/all.pdf

sample usage

from py4j.java_gateway import JavaGateway
gateway = JavaGateway()

ex = gateway.jvm.org.kuryu.PDFExtractText

with open("all.pdf", "rb") as fp:
  text = ex.convert(fp.read())

print(text)

pdfbox-via-py4j's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.