1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java 取pdf 文本域_java – 使用iText从pdf文件中提取文本列

java 取pdf 文本域_java – 使用iText从pdf文件中提取文本列

时间:2019-09-18 02:49:53

相关推荐

java 取pdf 文本域_java – 使用iText从pdf文件中提取文本列

我需要使用iText从pdf文件中提取文本.

问题是:一些pdf文件包含2列,当我提取文本时,我得到一个文本文件,其中列被合并为结果(即同一行中两列的文本)

这是代码:

public class pdf

{

private static String INPUTFILE = "/TAP_519-522_-_AO_07151GT_Rasoamananjara__ao.pdf" ;

private static String OUTPUTFILE = "c:/new3.pdf";

public static void main(String[] args) throws DocumentException, IOException {

Document document = new Document();

PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(OUTPUTFILE));

document.open();

PdfReader reader = new PdfReader(INPUTFILE);

int n = reader.getNumberOfPages();

PdfImportedPage page;

// Go through all pages

for (int i = 1; i <= n; i++) {

page = writer.getImportedPage(reader, i);

Image instance = Image.getInstance(page);

document.add(instance);

}

document.close();

PdfReader readerN = new PdfReader(OUTPUTFILE);

for (int i = 1; i <= n; i++) {

String myLine = PdfTextExtractor.getTextFromPage(readerN,i);

System.out.println(myLine);

try {

FileWriter fw = new FileWriter("c:/yo.txt",true);

fw.write(myLine);

fw.close();

}catch (IOException ioe) {ioe.printStackTrace(); }

}

}

你能帮我完成这个任务吗?

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。