小编Rim*_*im 的帖子

使用iText从pdf文件中提取文本列

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

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

这是代码:

public class pdf
{
    private static String INPUTFILE = "http://www.revuemedecinetropicale.com/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 …
Run Code Online (Sandbox Code Playgroud)

java pdf text-extraction itext

6
推荐指数
1
解决办法
3万
查看次数

从pdf文件中提取文本

我需要从pdf文件中提取文字(逐字逐句).

import java.io.*;

import com.itextpdf.text.*;

import com.itextpdf.text.pdf.*;

import com.itextpdf.text.pdf.parser.*;

public class pdf {

    private static String INPUTFILE = "http://ontology.buffalo.edu/ontology%28PIC%29.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);

                System.out.println(i);


                Image instance …
Run Code Online (Sandbox Code Playgroud)

java pdf parsing itext

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

itext ×2

java ×2

pdf ×2

parsing ×1

text-extraction ×1