0
感谢您的回复。文本即将到来,但不考虑任何(空格,字体大小,侧面标题,正文)。我想从pdf中读取数据,确切地说它存在于其中。任何帮助赞赏。下面使用java中的itext将pdf文件转换为word文档
这里我的代码被赋予是到目前为止我的代码:
package bis.proj.samp;
import java.io.File;
import java.io.FileOutputStream;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.rtf.RtfWriter2;
public class ReadPdfFile {
public static void main(String[] args) {
try {
Document document = new Document();
File file = new File("/home/mujafar/Desktop/file.doc");
if(!file.exists())
file.createNewFile();
RtfWriter2.getInstance(document, new FileOutputStream("/home/mujafar/Desktop/file.doc"));
System.out.println("file created");
document.open();
PdfReader reader = new PdfReader("/home/mujafar/Desktop/NPTEL Transcription Guidelines.pdf");
int n = reader.getNumberOfPages();
System.out.println("total no of pages:::"+n);
String s="";
for(int i=1;i<=n;i++)
{
s=PdfTextExtractor.getTextFromPage(reader, i);
System.out.println("string:::"+s);
System.out.println("====================");
document.add(new Paragraph(s));
document.newPage();
}
document.close();
System.out.println("completed");
} catch (Exception de) {}
}
}
感谢您的回复。但我不明白如何使用上述代码。请您附上完整的代码,从pdf文件中读取内容(文本和图像),并将内容写入word文档(doc/docx)。 – mujafar
以上只是为了得到文字,因为这是我认为你需要的。我会编辑它以使其更加完整。图像和布局留作练习。 RenderListener也有一个renderImage()方法。 – geert3
感谢您的回复。文本即将到来,但不考虑任何(空格,字体大小,侧面标题,正文)。我想从pdf中读取数据,确切地说它存在于其中。任何帮助赞赏。我的代码如下 – mujafar