linux pdf转纯文本,PDFLayoutTextStripper:将PDF格式的文档转换成为TXT的纯文本文件

PDFLayoutTextStripper

Converts a PDF file into a text file while keeping the layout of the original PDF. Useful to extract the content from a table or a form in a PDF file. PDFLayoutTextStripper is a subclass of PDFTextStripper class (from the Apache PDFBox library).

Use cases

Data extraction from a table in a PDF file 69fa3f76c8efd536bf74017e1e37594c.png

Data extraction from a form in a PDF file 9da07a65217894770c6f2fd5abd879b7.png

How to install

Maven

io.github.jonathanlink

PDFLayoutTextStripper

2.2.3

Manual

Install apache pdfbox manually (to get the v2.0.6 click here ) and its two dependencies commons-logging.jar and fontbox

warning: only pdfbox versions from version 2.0.0 upwards are compatible with this version of PDFLayoutTextStripper.java

How to use on Linux/Mac

cd PDFLayoutTextStripper

javac -cp .:/pathto/pdfbox-2.0.6.jar:/pathto/commons-logging-1.2.jar:/pathto/PDFLayoutTextStripper/fontbox-2.0.6.jar *.java

java -cp .:/pathto/pdfbox-2.0.6.jar:/pathto/commons-logging-1.2.jar:/pathto/PDFLayoutTextStripper/fontbox-2.0.6.jar test

How to use on Windows

The same as for Linux (see above) but replace : with ;

Sample code

import java.io.File;

import java.io.FileNotFoundException;

import java.io.IOException;

import org.apache.pdfbox.io.RandomAccessFile;

import org.apache.pdfbox.pdfparser.PDFParser;

import org.apache.pdfbox.pdmodel.PDDocument;

import org.apache.pdfbox.text.PDFTextStripper;

public class test {

public static void main(String[] args) {

String string = null;

try {

PDFParser pdfParser = new PDFParser(new RandomAccessFile(new File("./samples/bus.pdf"), "r"));

pdfParser.parse();

PDDocument pdDocument = new PDDocument(pdfParser.getDocument());

PDFTextStripper pdfTextStripper = new PDFLayoutTextStripper();

string = pdfTextStripper.getText(pdDocument);

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

};

System.out.println(string);

}

}

Contributors

Thanks to

Dmytro Zelinskyy for reporting an issue with its correction (v2.2.3)

Ho Ting Cheng for reporting an issue (v2.1)

James Sullivan for having updated the code to make it work with the latest version of PDFBox (v2.0)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值